> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kubiya.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Compile Template

> Compile a template by substituting variables with values from context.

This endpoint:
1. Parses the template to extract variables
2. Validates syntax
3. If context provided: validates against context and compiles
4. If validate_only=True: only validates without compiling

Returns detailed information about variables, errors, and warnings.



## OpenAPI

````yaml https://control-plane.kubiya.ai/api/openapi.json post /api/v1/templates/compile
openapi: 3.1.0
info:
  title: Agent Control Plane API
  description: Multi-tenant agent orchestration with Temporal workflows
  version: 1.0.0
servers: []
security:
  - BearerAuth: []
tags:
  - name: health
    description: 🏥 **Health & Status** - Check API health and availability
  - name: authentication
    description: 🔐 **Authentication** - Token validation and auth management
  - name: agents
    description: 🤖 **Agents** - Create and manage AI agents with custom capabilities
  - name: skills
    description: 🛠️ **Tool Sets** - Manage agent skills and tool configurations
  - name: integrations
    description: 🔌 **Integrations** - Connect to external services (Kubiya managed)
  - name: custom-integrations
    description: >-
      ⚙️ **Custom Integrations** - User-defined integration instances with env
      vars, secrets, and files
  - name: integration-templates
    description: >-
      📦 **Integration Templates** - Pre-configured templates for common
      services (PostgreSQL, Redis, MongoDB, etc.)
  - name: secrets
    description: 🔑 **Secrets** - Secure credential storage and retrieval
  - name: teams
    description: 👥 **Teams** - Team management and collaboration
  - name: workflows
    description: 📊 **Workflows** - Multi-step automation and orchestration
  - name: executions
    description: ▶️ **Executions** - Track and monitor workflow runs
  - name: jobs
    description: ⏰ **Jobs** - Scheduled and webhook-triggered tasks
  - name: policies
    description: 🛡️ **Policies** - Access control and security policies
  - name: analytics
    description: 📈 **Analytics** - Usage metrics and performance monitoring
  - name: projects
    description: 📁 **Projects** - Project organization and management
  - name: environments
    description: 🌍 **Environments** - Environment configuration (dev, staging, prod)
  - name: models
    description: 🧠 **Models** - LLM model configuration and management
  - name: runtimes
    description: ⚡ **Runtimes** - Agent execution runtime environments
  - name: workers
    description: 👷 **Workers** - Worker registration and heartbeat monitoring
  - name: storage
    description: 💾 **Storage** - File storage and cloud integration
  - name: context-graph
    description: 🕸️ **Context Graph** - Knowledge graph and context management
  - name: temporal-workflows
    description: >-
      ⚙️ **Temporal Workflows** - Background workflows for context graph
      ingestion, connector operations, and scheduled jobs
  - name: templates
    description: 📝 **Templates** - Reusable configuration templates
paths:
  /api/v1/templates/compile:
    post:
      tags:
        - templates
      summary: Compile Template
      description: |-
        Compile a template by substituting variables with values from context.

        This endpoint:
        1. Parses the template to extract variables
        2. Validates syntax
        3. If context provided: validates against context and compiles
        4. If validate_only=True: only validates without compiling

        Returns detailed information about variables, errors, and warnings.
      operationId: compile_template_api_v1_templates_compile_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TemplateCompileRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TemplateCompileResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    TemplateCompileRequest:
      properties:
        template:
          type: string
          minLength: 1
          title: Template
          description: Template string with {{variable}} syntax
        context:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Context
          description: Context for compilation (variables, secrets, env_vars)
        validate_only:
          type: boolean
          title: Validate Only
          description: Only validate syntax without compiling
          default: false
        environment_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Environment Id
          description: Environment ID for secret validation
      type: object
      required:
        - template
      title: TemplateCompileRequest
      description: Request schema for template compilation endpoint.
      example:
        context:
          env_vars:
            PORT: '8080'
          secrets:
            api_key: secret-value
          variables: {}
        environment_id: env-123
        template: http://api.example.com:{{.env.PORT}}/auth?key={{.secret.api_key}}
        validate_only: false
    TemplateCompileResponse:
      properties:
        valid:
          type: boolean
          title: Valid
          description: Whether the template is valid
        compiled:
          anyOf:
            - type: string
            - type: 'null'
          title: Compiled
          description: Compiled template (if valid and context provided)
        variables:
          items:
            $ref: '#/components/schemas/TemplateVariableSchema'
          type: array
          title: Variables
          description: Variables found in template
        errors:
          items:
            $ref: '#/components/schemas/ValidationErrorSchema'
          type: array
          title: Errors
          description: Validation/compilation errors
        warnings:
          items:
            type: string
          type: array
          title: Warnings
          description: Non-fatal warnings
      type: object
      required:
        - valid
      title: TemplateCompileResponse
      description: Response schema for template compilation endpoint.
      example:
        compiled: http://api.example.com:8080/auth?key=secret-value
        errors: []
        valid: true
        variables:
          - display_name: PORT
            end: 38
            name: env.PORT
            raw: '{{.env.PORT}}'
            start: 25
            type: env
          - display_name: api_key
            end: 68
            name: secret.api_key
            raw: '{{.secret.api_key}}'
            start: 48
            type: secret
        warnings: []
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    TemplateVariableSchema:
      properties:
        name:
          type: string
          title: Name
          description: Variable name (e.g., 'api_key' or 'secret.github_token')
        type:
          type: string
          title: Type
          description: 'Variable type: ''simple'', ''secret'', or ''env'''
        raw:
          type: string
          title: Raw
          description: Raw template string (e.g., '{{.secret.api_key}}')
        start:
          type: integer
          title: Start
          description: Start position in template
        end:
          type: integer
          title: End
          description: End position in template
        display_name:
          type: string
          title: Display Name
          description: Display name without type prefix
      type: object
      required:
        - name
        - type
        - raw
        - start
        - end
        - display_name
      title: TemplateVariableSchema
      description: Schema for a template variable.
    ValidationErrorSchema:
      properties:
        message:
          type: string
          title: Message
          description: Human-readable error message
        variable:
          anyOf:
            - $ref: '#/components/schemas/TemplateVariableSchema'
            - type: 'null'
          description: Variable that caused the error
        position:
          anyOf:
            - type: integer
            - type: 'null'
          title: Position
          description: Character position in template
        code:
          anyOf:
            - type: string
            - type: 'null'
          title: Code
          description: Machine-readable error code
      type: object
      required:
        - message
      title: ValidationErrorSchema
      description: Schema for a validation error.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Enter your Kubiya API token (format: Bearer <token>)'

````