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

# Publish a document as a template

> Copies one of your media documents into a new template and submits it
for moderation. The template is a frozen copy, so later edits to the
document do not change it. Requires a key bound to a user (a personal
API key, or `on_behalf_of_user_id`).




## OpenAPI

````yaml /openapi.yaml post /templates
openapi: 3.1.0
info:
  title: varg API
  version: 2.0.0
  description: |
    Unified REST API for AI media generation at `api.varg.ai/v2`.

    One API key, ~80 models across 8 providers, async jobs, stable output URLs
    on `s3.varg.ai`, files with lineage, and transparent credit billing
    (1 credit = 1 cent = $0.01).

    **The async job pattern:** every generation request returns `202 Accepted`
    with a job object (`status: queued`). Poll `GET /jobs/{id}` until the job
    reaches a terminal status (`completed`, `failed`, or `cancelled`), then read
    `output.outputs[0].url`. Alternatively, set `options.webhook_url` in the
    request to receive an HMAC-signed callback when the job finishes.
servers:
  - url: https://api.varg.ai/v2
security:
  - bearerAuth: []
tags:
  - name: Generation
    description: >-
      Create generation jobs (image, video, speech, music, transcription,
      ffmpeg, render, pipeline)
  - name: Tools
    description: Discover tools, their schemas, and call any tool generically
  - name: Jobs
    description: Poll and manage job lifecycle
  - name: Files
    description: Upload, import, probe, and manage files
  - name: Folders
    description: Group files into folders and file generated output automatically
  - name: Lineage
    description: Resolve which job produced a file
  - name: Presets
    description: Browse and apply reusable parameter values — voices, styles
  - name: Templates
    description: Browse, publish, use and render community templates
  - name: Pricing
    description: Estimate costs and browse the price catalog
  - name: Billing
    description: Balance, usage, and transaction history
  - name: Analytics
    description: >-
      Spend, runs and files over time — summaries, time series, breakdowns,
      activity
  - name: Account
    description: Identity and API key management
paths:
  /templates:
    post:
      tags:
        - Templates
      summary: Publish a document as a template
      description: |
        Copies one of your media documents into a new template and submits it
        for moderation. The template is a frozen copy, so later edits to the
        document do not change it. Requires a key bound to a user (a personal
        API key, or `on_behalf_of_user_id`).
      operationId: createTemplate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TemplateCreateRequest'
            example:
              document_id: 7c1d2a0e-5b4f-4f0e-9a52-0d3a1c6b8e11
              description: Product teaser with a slow dolly-in
              tags:
                - product
                - teaser
      responses:
        '201':
          description: Template created and awaiting moderation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TemplateCreated'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: invalid_request
                  message: Request failed validation
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: Template or document not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: not_found
                  message: Template not found
        '409':
          description: A template already exists for this document
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: conflict
                  message: >-
                    A template already exists for this document (status:
                    pending)
        '422':
          description: The key is not bound to a user account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: no_user_identity
                  message: This API key is not bound to a user account
components:
  schemas:
    TemplateCreateRequest:
      type: object
      required:
        - document_id
        - description
      properties:
        document_id:
          type: string
          format: uuid
          description: A media document you own. `documentId` is also accepted.
        description:
          type: string
          minLength: 1
          maxLength: 500
        tags:
          type: array
          maxItems: 5
          description: |
            Trimmed and lower-cased; empty tags are dropped and only the first
            five are kept. Each tag may be at most 30 characters.
          items:
            type: string
    TemplateCreated:
      type: object
      properties:
        id:
          type: string
          format: uuid
        status:
          type: string
          description: New templates start in moderation, typically `pending`
          example: pending
        sourceDocumentId:
          type: string
          format: uuid
        createdAt:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: model_not_found
            message:
              type: string
              example: 'Unknown model: flux-shnell'
            details: {}
  responses:
    Unauthorized:
      description: Missing or invalid API key / JWT
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            unauthorized:
              value:
                error:
                  code: unauthorized
                  message: Invalid or missing API key or JWT
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: |
        varg API key (`varg_...`). Get one at [app.varg.ai](https://app.varg.ai)
        or run `bunx vargai login`. App sessions may alternatively send a
        Supabase JWT.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.