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

# Create thread



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/cerca/openapi.documented.yml post /agents/{agentId}/threads
openapi: 3.1.0
info:
  description: API-key accessible routes for Cerca agents.
  title: Cerca API
  version: 0.0.0
servers:
  - url: https://api.cerca.dev
security:
  - bearerAuth: []
paths:
  /agents/{agentId}/threads:
    post:
      tags:
        - Threads
      summary: Create thread
      parameters:
        - schema:
            type: string
            minLength: 1
            example: agent_abc123
          required: true
          in: path
          name: agentId
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateThreadRequest'
      responses:
        '201':
          description: Thread created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ThreadDetail'
        '400':
          description: Invalid runtime request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: >-
            Access denied or non-transient quota exceeded. Limit errors include
            a stable code field.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Runtime resource not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: Thread lifecycle conflict.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: >-
            Transient capacity limit exceeded. Limit errors include a stable
            code field.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Thread lifecycle operation failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Required runtime dependency unavailable.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        default:
          description: Runtime error response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Cerca from '@cerca-dev/sdk';

            const client = new Cerca({
              apiKey: process.env['CERCA_API_KEY'], // This is the default and can be omitted
            });

            const thread = await client.threads.create('agent_abc123');

            console.log(thread.id);
        - lang: Python
          source: |-
            import os
            from cerca import Cerca

            client = Cerca(
                api_key=os.environ.get("CERCA_API_KEY"),  # This is the default and can be omitted
            )
            thread = client.threads.create(
                agent_id="agent_abc123",
            )
            print(thread.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/matrices/cerca-go\"\n\t\"github.com/matrices/cerca-go/option\"\n)\n\nfunc main() {\n\tclient := cercago.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tthread, err := client.Threads.New(\n\t\tcontext.TODO(),\n\t\t\"agent_abc123\",\n\t\tcercago.ThreadNewParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", thread.ID)\n}\n"
        - lang: Ruby
          source: |-
            require "cerca"

            cerca = Cerca::Client.new(api_key: "My API Key")

            thread = cerca.threads.create("agent_abc123")

            puts(thread)
        - lang: CLI
          source: |-
            cerca threads create \
              --api-key 'My API Key' \
              --agent-id agent_abc123
components:
  schemas:
    CreateThreadRequest:
      type: object
      properties:
        instructions:
          type: string
        model:
          type: string
        systemPrompt:
          type: string
          description: >-
            Deprecated alias for `instructions`; accepted for backwards
            compatibility.
        tools:
          type: array
          items:
            $ref: '#/components/schemas/RuntimeToolSpec'
          description: >-
            Per-thread tool subset. Omit to inherit the agent's full effective
            tools; pass [] to run with no configurable tools. Provided entries
            can only narrow the agent's effective tools.
        message:
          type: string
      additionalProperties: false
    ThreadDetail:
      type: object
      properties:
        agentId:
          type: string
        completedAt:
          type:
            - string
            - 'null'
        createdAt:
          type: string
        depth:
          type: number
        error:
          type:
            - string
            - 'null'
        externalToolNamespaces:
          oneOf:
            - type: string
              enum:
                - all
              x-stainless-const: true
            - type: array
              items:
                type: string
        id:
          type: string
        instructions:
          type:
            - string
            - 'null'
        model:
          type: string
        parentThreadId:
          type:
            - string
            - 'null'
        result:
          type:
            - string
            - 'null'
        scheduleId:
          type:
            - string
            - 'null'
        scheduleSeq:
          type:
            - number
            - 'null'
        status:
          $ref: '#/components/schemas/ThreadStatus'
        updatedAt:
          type: string
        message:
          type: string
        activeTurnModel:
          type:
            - string
            - 'null'
        compiledContext:
          $ref: '#/components/schemas/ThreadCompiledContext'
        compactionSummary:
          type:
            - string
            - 'null'
        compactionThroughSeq:
          type:
            - number
            - 'null'
        composedSystemPrompt:
          type:
            - string
            - 'null'
        contextWindow:
          $ref: '#/components/schemas/ThreadContextWindow'
        hasMoreMessages:
          type: boolean
        lastTurnStatus:
          type:
            - string
            - 'null'
          enum:
            - completed
            - failed
            - null
        messageCursor:
          type:
            - number
            - 'null'
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ThreadMessage'
        subThreads:
          type: array
          items:
            $ref: '#/components/schemas/SubThreadSummary'
        tools:
          type: array
          items:
            $ref: '#/components/schemas/RuntimeToolName'
        turns:
          type: array
          items:
            $ref: '#/components/schemas/Turn'
      required:
        - agentId
        - completedAt
        - createdAt
        - depth
        - error
        - id
        - instructions
        - model
        - parentThreadId
        - result
        - scheduleId
        - scheduleSeq
        - status
        - updatedAt
        - message
        - compiledContext
        - compactionSummary
        - compactionThroughSeq
        - composedSystemPrompt
        - contextWindow
        - hasMoreMessages
        - lastTurnStatus
        - messageCursor
        - messages
        - subThreads
        - tools
        - turns
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        code:
          type: string
          description: Stable machine-readable error code when the API can provide one.
          example: MONTHLY_TOKEN_BUDGET_EXCEEDED
      required:
        - error
    RuntimeToolSpec:
      type: string
      minLength: 1
      description: >-
        Configurable runtime tool name, configurable namespace wildcard such as
        sandbox.*, or external namespace wildcard such as google.*. At thread
        and turn scope, entries can only narrow the agent's effective tools.
      examples:
        - sandbox.*
        - memory.read
        - google.*
    ThreadStatus:
      type: string
      enum:
        - idle
        - running
        - awaiting
        - closed
      description: >-
        `idle` threads can accept a new turn or be closed. `running` threads
        have an active turn. `awaiting` threads are paused on external input
        such as approvals. `closed` threads are terminal.
    ThreadCompiledContext:
      type:
        - object
        - 'null'
      properties:
        enabledTools:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/RuntimeToolName'
        systemPrompt:
          type:
            - string
            - 'null'
        turnId:
          type:
            - string
            - 'null'
      required:
        - enabledTools
        - systemPrompt
        - turnId
    ThreadContextWindow:
      type:
        - object
        - 'null'
      properties:
        compacted:
          type: boolean
        compactionThroughSeq:
          type:
            - number
            - 'null'
        contextWindowTokens:
          type: number
        estimationMethod:
          type: string
          enum:
            - heuristic_request_v1
          x-stainless-const: true
        llmEstimatedTokens:
          type: number
        model:
          type: string
        rawEstimatedTokens:
          type: number
      required:
        - compacted
        - compactionThroughSeq
        - contextWindowTokens
        - estimationMethod
        - llmEstimatedTokens
        - model
        - rawEstimatedTokens
    ThreadMessage:
      type: object
      properties:
        content:
          type: array
          items:
            $ref: '#/components/schemas/ContentBlock'
        createdAt:
          type: string
        role:
          type: string
          enum:
            - user
            - assistant
        seq:
          type: number
      required:
        - content
        - createdAt
        - role
        - seq
    SubThreadSummary:
      type: object
      properties:
        completedAt:
          type:
            - string
            - 'null'
        createdAt:
          type: string
        id:
          type: string
        messageCount:
          type: number
        model:
          type: string
        parentThreadId:
          type:
            - string
            - 'null'
        result:
          type:
            - string
            - 'null'
        scheduleId:
          type:
            - string
            - 'null'
        scheduleSeq:
          type:
            - number
            - 'null'
        state:
          $ref: '#/components/schemas/SubThreadState'
        stepCount:
          type: number
        toolUseId:
          type:
            - string
            - 'null'
      required:
        - completedAt
        - createdAt
        - id
        - messageCount
        - model
        - parentThreadId
        - result
        - scheduleId
        - scheduleSeq
        - state
        - stepCount
        - toolUseId
    RuntimeToolName:
      type: string
      enum:
        - get_time
        - sub_thread
        - wait
        - tool.call
        - tool.discover
        - artifact.read
        - agent.threads.list
        - agent.threads.get
        - agent.approvals.cancel
        - agent.approvals.grant_thread
        - agent.approvals.grant_agent
        - agent.create
        - agent.approvals.update
        - tool.connect
        - sandbox.exec
        - sandbox.read
        - sandbox.write_file
        - sandbox.read_file
        - sandbox.spawn
        - sandbox.stdin
        - sandbox.session_read
        - sandbox.kill
        - sandbox.list_sessions
        - sandbox.sync_artifact
        - memory.read
        - memory.list
        - memory.search
        - memory.write
        - memory.delete
        - db.query
        - web.search
        - web.fetch
        - agent.schedule.list
        - agent.schedule.create
        - agent.schedule.update
        - agent.schedule.delete
        - agent.schedule.trigger
    Turn:
      type: object
      properties:
        completedAt:
          type:
            - string
            - 'null'
        endMessageSeq:
          type:
            - number
            - 'null'
        error:
          type:
            - string
            - 'null'
        id:
          type: string
        result:
          type:
            - string
            - 'null'
        seq:
          type: number
        startMessageSeq:
          type: number
        startedAt:
          type: string
        status:
          type: string
          enum:
            - running
            - completed
            - failed
        threadId:
          type: string
        tokenUsage:
          $ref: '#/components/schemas/TokenUsage'
        message:
          type: string
      required:
        - completedAt
        - endMessageSeq
        - error
        - id
        - result
        - seq
        - startMessageSeq
        - startedAt
        - status
        - threadId
        - tokenUsage
        - message
    ContentBlock:
      oneOf:
        - $ref: '#/components/schemas/TextContentBlock'
          title: TextContentBlock
          x-stainless-variantName: TextContentBlock
        - $ref: '#/components/schemas/ToolUseContentBlock'
          title: ToolUseContentBlock
          x-stainless-variantName: ToolUseContentBlock
        - $ref: '#/components/schemas/ToolResultContentBlock'
          title: ToolResultContentBlock
          x-stainless-variantName: ToolResultContentBlock
        - $ref: '#/components/schemas/ServerToolUseContentBlock'
          title: ServerToolUseContentBlock
          x-stainless-variantName: ServerToolUseContentBlock
        - $ref: '#/components/schemas/WebSearchToolResultContentBlock'
          title: WebSearchToolResultContentBlock
          x-stainless-variantName: WebSearchToolResultContentBlock
      discriminator:
        propertyName: type
      description: >-
        Message content block. The `type` field distinguishes text, tool use,
        tool result, server tool use, and web search result blocks.
      example:
        text: Hello
        type: text
    SubThreadState:
      type: string
      enum:
        - pending
        - idle
        - running
        - awaiting
        - closed
      description: >-
        `pending` means the parent thread is still waiting on this sub-thread.
        Other values are the child thread lifecycle state.
    TokenUsage:
      type:
        - object
        - 'null'
      properties:
        inputTokens:
          type: number
        outputTokens:
          type: number
      required:
        - inputTokens
        - outputTokens
    TextContentBlock:
      type: object
      properties:
        providerMetadata:
          $ref: '#/components/schemas/ProviderMetadata'
        text:
          type: string
        type:
          type: string
          enum:
            - text
          x-stainless-const: true
      required:
        - text
        - type
    ToolUseContentBlock:
      type: object
      properties:
        id:
          type: string
        input:
          $ref: '#/components/schemas/JsonValue'
        name:
          $ref: '#/components/schemas/RuntimeToolName'
        providerMetadata:
          $ref: '#/components/schemas/ProviderMetadata'
        type:
          type: string
          enum:
            - tool_use
          x-stainless-const: true
      required:
        - id
        - input
        - name
        - type
    ToolResultContentBlock:
      type: object
      properties:
        content:
          type: string
        deniedByUser:
          type: boolean
        isError:
          type: boolean
        providerMetadata:
          $ref: '#/components/schemas/ProviderMetadata'
        toolUseId:
          type: string
        type:
          type: string
          enum:
            - tool_result
          x-stainless-const: true
      required:
        - content
        - isError
        - toolUseId
        - type
    ServerToolUseContentBlock:
      type: object
      properties:
        id:
          type: string
        input:
          $ref: '#/components/schemas/JsonValue'
        name:
          type: string
        providerMetadata:
          $ref: '#/components/schemas/ProviderMetadata'
        type:
          type: string
          enum:
            - server_tool_use
          x-stainless-const: true
      required:
        - id
        - input
        - name
        - type
    WebSearchToolResultContentBlock:
      type: object
      properties:
        content:
          x-stainless-any: true
          description: >-
            Web search result payload. The runtime returns either an array of
            web search results or an error object.
        toolUseId:
          type: string
        type:
          type: string
          enum:
            - web_search_tool_result
          x-stainless-const: true
      required:
        - content
        - toolUseId
        - type
    ProviderMetadata:
      type: object
      additionalProperties:
        $ref: '#/components/schemas/ProviderMetadataEntry'
    JsonValue:
      description: >-
        Any JSON value. Generated SDKs may expose this value boundary as unknown
        or Any.
      x-stainless-any: true
    ProviderMetadataEntry:
      type: object
      additionalProperties:
        type: string
      description: Provider-specific metadata for a message content block.
  securitySchemes:
    bearerAuth:
      bearerFormat: Cerca API key
      scheme: bearer
      type: http

````