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

# List threads



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/cerca/openapi.documented.yml get /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:
    get:
      tags:
        - Threads
      summary: List threads
      parameters:
        - schema:
            type: string
            minLength: 1
            example: agent_abc123
          required: true
          in: path
          name: agentId
        - schema:
            type: string
            description: Opaque pagination cursor returned by a previous request.
            example: cursor_abc123
          required: false
          description: Opaque pagination cursor returned by a previous request.
          name: cursor
          in: query
        - schema:
            type: string
            description: >-
              Maximum number of items to return. Defaults to 20 and preserves
              parseInt semantics.
            example: '20'
          required: false
          description: >-
            Maximum number of items to return. Defaults to 20 and preserves
            parseInt semantics.
          name: limit
          in: query
        - schema:
            type: string
            description: Optional schedule id filter.
            example: schedule_abc123
          required: false
          description: Optional schedule id filter.
          name: scheduleId
          in: query
        - schema:
            allOf:
              - $ref: '#/components/schemas/ThreadStatus'
              - description: Optional thread status filter.
          required: false
          description: Optional thread status filter.
          name: status
          in: query
      responses:
        '200':
          description: Threads page.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ThreadsPage'
        '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
            });


            // Automatically fetches more pages as needed.

            for await (const threadSummary of
            client.threads.list('agent_abc123')) {
              console.log(threadSummary.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
            )
            page = client.threads.list(
                agent_id="agent_abc123",
            )
            page = page.threads[0]
            print(page.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\tpage, err := client.Threads.List(\n\t\tcontext.TODO(),\n\t\t\"agent_abc123\",\n\t\tcercago.ThreadListParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", page)\n}\n"
        - lang: Ruby
          source: |-
            require "cerca"

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

            page = cerca.threads.list("agent_abc123")

            puts(page)
        - lang: CLI
          source: |-
            cerca threads list \
              --api-key 'My API Key' \
              --agent-id agent_abc123
components:
  schemas:
    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.
    ThreadsPage:
      type: object
      properties:
        cursor:
          type:
            - string
            - 'null'
        hasMore:
          type: boolean
        threads:
          type: array
          items:
            $ref: '#/components/schemas/ThreadSummary'
      required:
        - cursor
        - hasMore
        - threads
    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
    ThreadSummary:
      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'
        status:
          $ref: '#/components/schemas/ThreadStatus'
        stepCount:
          type: number
      required:
        - completedAt
        - createdAt
        - id
        - messageCount
        - model
        - parentThreadId
        - result
        - scheduleId
        - scheduleSeq
        - status
        - stepCount
  securitySchemes:
    bearerAuth:
      bearerFormat: Cerca API key
      scheme: bearer
      type: http

````