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

# Update Prompt

> Update an existing prompt

Update a prompt's metadata or content. If the content changes, a new version is automatically created.

## Request

<ParamField header="Authorization" type="string" required>
  Bearer token with your API key: `Bearer tr_your_api_key`
</ParamField>

<ParamField path="slug" type="string" required>
  The prompt slug to update
</ParamField>

<ParamField body="name" type="string">
  New display name
</ParamField>

<ParamField body="slug" type="string">
  New URL-friendly identifier
</ParamField>

<ParamField body="description" type="string">
  New description (set to empty string to clear)
</ParamField>

<ParamField body="content" type="array">
  New array of prompt messages. If different from current content, creates a new version.
</ParamField>

## Response

Returns the updated prompt object with the new version number if content changed.

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT https://app.tracia.io/api/v1/prompts/welcome-email \
    -H "Authorization: Bearer tr_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Updated Welcome Email",
      "content": [
        {
          "id": "msg_1",
          "role": "user",
          "content": "Write a friendly welcome email for {{name}} at {{company}}."
        }
      ]
    }'
  ```

  ```typescript SDK theme={null}
  const prompt = await tracia.prompts.update('welcome-email', {
    name: 'Updated Welcome Email',
    content: [
      { id: 'msg_1', role: 'user', content: 'Write a friendly welcome email for {{name}} at {{company}}.' },
    ],
  });
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "clx1abc123",
    "slug": "welcome-email",
    "name": "Updated Welcome Email",
    "description": "A welcome email template",
    "provider": "OPENAI",
    "model": "gpt-4",
    "temperature": 0.7,
    "topP": null,
    "maxOutputTokens": null,
    "currentVersion": 4,
    "content": [
      {
        "id": "msg_1",
        "role": "user",
        "content": "Write a friendly welcome email for {{name}} at {{company}}."
      }
    ],
    "variables": ["name", "company"],
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-22T08:45:00.000Z"
  }
  ```

  ```json 404 theme={null}
  {
    "code": "NOT_FOUND",
    "message": "Prompt not found: welcome-email"
  }
  ```

  ```json 409 theme={null}
  {
    "code": "CONFLICT",
    "message": "A prompt with this slug already exists"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml PUT /prompts/{slug}
openapi: 3.1.0
info:
  title: Tracia API
  description: REST API for managing and running AI prompts with tracing
  version: 1.0.0
servers:
  - url: https://app.tracia.io/api/v1
    description: Production server
security:
  - bearerAuth: []
paths:
  /prompts/{slug}:
    put:
      tags:
        - Prompts
      summary: Update Prompt
      description: >-
        Update an existing prompt. If the content changes, a new version is
        automatically created.
      operationId: updatePrompt
      parameters:
        - name: slug
          in: path
          required: true
          schema:
            type: string
          description: The prompt slug to update
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: New display name
                slug:
                  type: string
                  description: New URL-friendly identifier
                description:
                  type: string
                  description: New description (set to empty string to clear)
                content:
                  type: array
                  items:
                    $ref: '#/components/schemas/Message'
                  description: New array of prompt messages
      responses:
        '200':
          description: Prompt updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Prompt'
        '404':
          description: Prompt not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Conflict - new slug already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Message:
      type: object
      required:
        - id
        - role
        - content
      properties:
        id:
          type: string
          description: Unique identifier for the message
        role:
          type: string
          enum:
            - system
            - user
            - assistant
          description: Message role
        content:
          type: string
          description: Message content (may include `{{variables}}`)
    Prompt:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the prompt
        slug:
          type: string
          description: URL-friendly identifier
        name:
          type: string
          description: Display name of the prompt
        description:
          type: string
          nullable: true
          description: Description of the prompt
        provider:
          type: string
          nullable: true
          enum:
            - OPENAI
            - ANTHROPIC
            - GOOGLE
            - AMAZON_BEDROCK
          description: Model provider
        model:
          type: string
          nullable: true
          description: Default model for this prompt
        temperature:
          type: number
          nullable: true
          description: Temperature setting for the model (0-2)
        topP:
          type: number
          nullable: true
          description: Top-p (nucleus) sampling setting (0-1)
        maxOutputTokens:
          type: integer
          nullable: true
          description: Maximum output tokens limit
        currentVersion:
          type: integer
          description: Current version number
        content:
          type: array
          items:
            $ref: '#/components/schemas/Message'
          description: Array of prompt messages
        variables:
          type: array
          items:
            type: string
          description: List of template variables extracted from content
        createdAt:
          type: string
          format: date-time
          description: ISO 8601 timestamp of creation
        updatedAt:
          type: string
          format: date-time
          description: ISO 8601 timestamp of last update
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Error code
            message:
              type: string
              description: Error message
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key starting with `tr_`

````