> ## 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.

# Create Prompt

> Create a new prompt

## Request

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

<ParamField body="name" type="string" required>
  Display name for the prompt
</ParamField>

<ParamField body="slug" type="string">
  URL-friendly identifier. Auto-generated from name if not provided.
</ParamField>

<ParamField body="description" type="string">
  Description of the prompt
</ParamField>

<ParamField body="content" type="array" required>
  Array of prompt messages. Each message must have:

  * `id` (string): Unique identifier
  * `role` (string): `system`, `user`, or `assistant`
  * `content` (string): Message content
</ParamField>

## Response

Returns the created prompt object.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://app.tracia.io/api/v1/prompts \
    -H "Authorization: Bearer tr_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Welcome Email",
      "description": "A welcome email template",
      "content": [
        {
          "id": "msg_1",
          "role": "system",
          "content": "You are a helpful assistant."
        },
        {
          "id": "msg_2",
          "role": "user",
          "content": "Write a welcome email for {{name}}."
        }
      ]
    }'
  ```

  ```typescript SDK theme={null}
  const prompt = await tracia.prompts.create({
    name: 'Welcome Email',
    description: 'A welcome email template',
    content: [
      { id: 'msg_1', role: 'system', content: 'You are a helpful assistant.' },
      { id: 'msg_2', role: 'user', content: 'Write a welcome email for {{name}}.' },
    ],
  });
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "id": "clx1abc123",
    "slug": "welcome-email",
    "name": "Welcome Email",
    "description": "A welcome email template",
    "provider": null,
    "model": null,
    "temperature": null,
    "topP": null,
    "maxOutputTokens": null,
    "currentVersion": 1,
    "content": [
      {
        "id": "msg_1",
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "id": "msg_2",
        "role": "user",
        "content": "Write a welcome email for {{name}}."
      }
    ],
    "variables": ["name"],
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T10:30:00.000Z"
  }
  ```

  ```json 400 theme={null}
  {
    "code": "INVALID_REQUEST",
    "message": "Missing required field: name"
  }
  ```

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


## OpenAPI

````yaml POST /prompts
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:
    post:
      tags:
        - Prompts
      summary: Create Prompt
      description: Create a new prompt
      operationId: createPrompt
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - content
              properties:
                name:
                  type: string
                  description: Display name for the prompt
                slug:
                  type: string
                  description: >-
                    URL-friendly identifier. Auto-generated from name if not
                    provided.
                description:
                  type: string
                  description: Description of the prompt
                content:
                  type: array
                  items:
                    $ref: '#/components/schemas/Message'
                  description: Array of prompt messages
      responses:
        '201':
          description: Prompt created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Prompt'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Conflict - 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_`

````