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

# Create prompt template version by name

> 
Create a new version of a prompt template, referenced by a string or name you define. [See SDK method.](https://docs.freeplay.ai/freeplay-sdk/prompts)

Set `create_template_if_not_exists=true` to auto-create the template if it doesn't exist.

**Version Creation Semantics:**

A new version is created only if there is no existing version with identical:
- Content (prompt messages)
- Model
- LLM parameters
- Version name (if provided)
- Version description
- Tool schema
- Output schema

If an identical version exists in any of the target environments, that version is reused and its environments are updated to match the requested environments. This ensures you never create duplicate versions with the same configuration.

**Environment Deployment:**

- When creating a new version, it will be deployed to the specified environments (or "latest" if none specified)
- When reuploading an existing prompt template with a new environment, the environments on that prompt template version will be updated

These checks are performed so that you can safely upload prompt templates without worrying that you will be creating duplicate versions. This is especially useful in development workflows where your prompts are stored in code.



## OpenAPI

````yaml https://app.freeplay.ai/openapi.json post /api/v2/projects/{project_id}/prompt-templates/name/{template_name}/versions
openapi: 3.1.0
info:
  title: Freeplay API
  version: 0.1.0
servers: []
security:
  - BearerAuth: []
paths:
  /api/v2/projects/{project_id}/prompt-templates/name/{template_name}/versions:
    post:
      tags:
        - Prompt Templates
      summary: Create prompt template version by name
      description: >-

        Create a new version of a prompt template, referenced by a string or
        name you define. [See SDK
        method.](https://docs.freeplay.ai/freeplay-sdk/prompts)


        Set `create_template_if_not_exists=true` to auto-create the template if
        it doesn't exist.


        **Version Creation Semantics:**


        A new version is created only if there is no existing version with
        identical:

        - Content (prompt messages)

        - Model

        - LLM parameters

        - Version name (if provided)

        - Version description

        - Tool schema

        - Output schema


        If an identical version exists in any of the target environments, that
        version is reused and its environments are updated to match the
        requested environments. This ensures you never create duplicate versions
        with the same configuration.


        **Environment Deployment:**


        - When creating a new version, it will be deployed to the specified
        environments (or "latest" if none specified)

        - When reuploading an existing prompt template with a new environment,
        the environments on that prompt template version will be updated


        These checks are performed so that you can safely upload prompt
        templates without worrying that you will be creating duplicate versions.
        This is especially useful in development workflows where your prompts
        are stored in code.
      operationId: post_create_template_version_by_name
      parameters:
        - name: project_id
          in: path
          required: true
          schema:
            type: string
        - name: template_name
          in: path
          required: true
          schema:
            type: string
        - name: create_template_if_not_exists
          in: query
          schema:
            default: null
            title: Create Template If Not Exists
            type:
              - boolean
              - 'null'
      requestBody:
        content:
          application/json:
            schema:
              properties:
                template_messages:
                  items:
                    anyOf:
                      - $ref: '#/components/schemas/PromptTemplateMessageInfo'
                      - $ref: '#/components/schemas/HistoryPlaceholderInfo'
                  title: Template Messages
                  type: array
                model:
                  title: Model
                  type: string
                provider:
                  title: Provider
                  type: string
                version_name:
                  default: null
                  title: Version Name
                  type:
                    - string
                    - 'null'
                version_description:
                  default: null
                  title: Version Description
                  type:
                    - string
                    - 'null'
                llm_parameters:
                  default: null
                  title: Llm Parameters
                  additionalProperties:
                    anyOf:
                      - type: string
                      - type: integer
                      - type: number
                      - additionalProperties: true
                        type: object
                  type:
                    - object
                    - 'null'
                tool_schema:
                  default: null
                  title: Tool Schema
                  items:
                    $ref: '#/components/schemas/NormalizedToolSchema'
                  type:
                    - array
                    - 'null'
                output_schema:
                  default: null
                  title: Output Schema
                  additionalProperties: true
                  type:
                    - object
                    - 'null'
                environments:
                  default: null
                  title: Environments
                  items:
                    type: string
                  type:
                    - array
                    - 'null'
              required:
                - template_messages
                - model
                - provider
              title: CreateTemplateVersionRequest
              type: object
      responses:
        '201':
          content:
            application/json:
              schema:
                properties:
                  prompt_template_id:
                    format: uuid
                    title: Prompt Template Id
                    type: string
                  prompt_template_version_id:
                    format: uuid
                    title: Prompt Template Version Id
                    type: string
                  prompt_template_name:
                    title: Prompt Template Name
                    type: string
                  version_name:
                    title: Version Name
                    type:
                      - string
                      - 'null'
                  version_description:
                    title: Version Description
                    type:
                      - string
                      - 'null'
                  metadata:
                    $ref: '#/components/schemas/PromptTemplateMetadata'
                  format_version:
                    title: Format Version
                    type: integer
                  project_id:
                    format: uuid
                    title: Project Id
                    type: string
                  content:
                    items:
                      anyOf:
                        - $ref: '#/components/schemas/ChatMessageWithMediaSlot'
                        - $ref: '#/components/schemas/ChatMessage'
                        - $ref: '#/components/schemas/HistoryPlaceholder'
                    title: Content
                    type: array
                  tool_schema:
                    title: Tool Schema
                    items:
                      $ref: '#/components/schemas/NormalizedToolSchema'
                    type:
                      - array
                      - 'null'
                  output_schema:
                    title: Output Schema
                    additionalProperties: true
                    type:
                      - object
                      - 'null'
                required:
                  - prompt_template_id
                  - prompt_template_version_id
                  - prompt_template_name
                  - version_name
                  - version_description
                  - metadata
                  - format_version
                  - project_id
                  - content
                  - tool_schema
                  - output_schema
                title: PlainPromptTemplate
                type: object
          description: >-
            PlainPromptTemplate(prompt_template_id: uuid.UUID,
            prompt_template_version_id: uuid.UUID, prompt_template_name: str,
            version_name: Optional[str], version_description: Optional[str],
            metadata:
            server.api_routes.prompt_templates_api_v2.PromptTemplateMetadata,
            format_version: int, project_id: uuid.UUID, content:
            list[typing.Union[server.project_sessions.prompt_template_model.ChatMessageWithMediaSlot,
            server.project_sessions.prompt_template_model.ChatMessage,
            server.project_sessions.prompt_template_model.HistoryPlaceholder]],
            tool_schema: Optional[list[shared.common.NormalizedToolSchema]],
            output_schema: Optional[dict[str, Any]])
components:
  schemas:
    PromptTemplateMessageInfo:
      properties:
        role:
          enum:
            - system
            - user
            - assistant
          title: Role
          type: string
        content:
          title: Content
          type: string
        media_slots:
          default: null
          title: Media Slots
          items:
            $ref: '#/components/schemas/MediaSlot'
          type:
            - array
            - 'null'
      required:
        - role
        - content
      title: PromptTemplateMessageInfo
      type: object
    HistoryPlaceholderInfo:
      additionalProperties: false
      properties:
        kind:
          const: history
          default: history
          title: Kind
          type: string
      title: HistoryPlaceholderInfo
      type: object
    NormalizedToolSchema:
      properties:
        name:
          title: Name
          type: string
        description:
          title: Description
          type: string
        parameters:
          additionalProperties: true
          title: Parameters
          type: object
      required:
        - name
        - description
        - parameters
      title: NormalizedToolSchema
      type: object
    PromptTemplateMetadata:
      properties:
        provider:
          title: Provider
          type:
            - string
            - 'null'
        flavor:
          title: Flavor
          type:
            - string
            - 'null'
        model:
          title: Model
          type:
            - string
            - 'null'
        params:
          title: Params
          additionalProperties: true
          type:
            - object
            - 'null'
        provider_info:
          title: Provider Info
          additionalProperties: true
          type:
            - object
            - 'null'
      required:
        - provider
        - flavor
        - model
        - params
        - provider_info
      title: PromptTemplateMetadata
      type: object
    ChatMessageWithMediaSlot:
      properties:
        role:
          title: Role
          type: string
        content:
          title: Content
          type: string
        media_slots:
          items:
            $ref: '#/components/schemas/MediaSlot'
          title: Media Slots
          type: array
      required:
        - role
        - content
      title: ChatMessageWithMediaSlot
      type: object
    ChatMessage:
      properties:
        role:
          title: Role
          type: string
        content:
          title: Content
          type: string
      required:
        - role
        - content
      title: ChatMessage
      type: object
    HistoryPlaceholder:
      properties:
        kind:
          const: history
          default: history
          title: Kind
          type: string
      title: HistoryPlaceholder
      type: object
    MediaSlot:
      additionalProperties: false
      properties:
        type:
          enum:
            - audio
            - video
            - image
            - file
          title: Type
          type: string
        placeholder_name:
          title: Placeholder Name
          type: string
      required:
        - type
        - placeholder_name
      title: MediaSlot
      type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````