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



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/cerca/openapi.documented.yml post /agents/{agentId}/threads/{threadId}/turns
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/{threadId}/turns:
    post:
      tags:
        - Threads
      summary: Create turn
      parameters:
        - schema:
            type: string
            minLength: 1
            example: agent_abc123
          required: true
          in: path
          name: agentId
        - schema:
            type: string
            minLength: 1
            example: thread_abc123
          required: true
          in: path
          name: threadId
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StartTurnRequest'
      responses:
        '201':
          description: Thread turn started.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Turn'
        '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 turn = await client.threads.startTurn('agent_abc123',
            'thread_abc123', {
              message: 'message',
            });


            console.log(turn.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
            )
            turn = client.threads.start_turn(
                agent_id="agent_abc123",
                thread_id="thread_abc123",
                message="message",
            )
            print(turn.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\tturn, err := client.Threads.StartTurn(\n\t\tcontext.TODO(),\n\t\t\"agent_abc123\",\n\t\t\"thread_abc123\",\n\t\tcercago.ThreadStartTurnParams{\n\t\t\tMessage: cercago.F(\"message\"),\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", turn.ID)\n}\n"
        - lang: Ruby
          source: >-
            require "cerca"


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


            turn = cerca.threads.start_turn("agent_abc123", "thread_abc123",
            message: "message")


            puts(turn)
        - lang: CLI
          source: |-
            cerca threads start-turn \
              --api-key 'My API Key' \
              --agent-id agent_abc123 \
              --thread-id thread_abc123 \
              --message message
components:
  schemas:
    StartTurnRequest:
      type: object
      properties:
        message:
          type: string
        model:
          type: string
        tools:
          type: array
          items:
            $ref: '#/components/schemas/RuntimeToolSpec'
          description: >-
            Per-turn tool subset. Omit to inherit the thread's current tools;
            pass [] to run this turn with no configurable tools. Provided
            entries can only narrow the agent/thread effective tools.
      required:
        - message
      additionalProperties: false
    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
    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.*
    TokenUsage:
      type:
        - object
        - 'null'
      properties:
        inputTokens:
          type: number
        outputTokens:
          type: number
      required:
        - inputTokens
        - outputTokens
  securitySchemes:
    bearerAuth:
      bearerFormat: Cerca API key
      scheme: bearer
      type: http

````