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

# Search context



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/cerca/openapi.documented.yml get /agents/{agentId}/context/search
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}/context/search:
    get:
      tags:
        - Context
      summary: Search context
      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 key prefix filter.
            example: notes/
          required: false
          description: Optional key prefix filter.
          name: prefix
          in: query
        - schema:
            type: string
            description: Search query.
            example: project notes
          required: true
          description: Search query.
          name: q
          in: query
      responses:
        '200':
          description: Context search results.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextSearchPage'
        '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'
        '429':
          description: >-
            Transient capacity limit exceeded. Limit errors include a stable
            code field.
          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 searchResult of
            client.context.search('agent_abc123', { q: 'project notes' })) {
              console.log(searchResult.byteLength);
            }
        - 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.context.search(
                agent_id="agent_abc123",
                q="project notes",
            )
            page = page.results[0]
            print(page.byte_length)
        - 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.Context.Search(\n\t\tcontext.TODO(),\n\t\t\"agent_abc123\",\n\t\tcercago.ContextSearchParams{\n\t\t\tQ: cercago.F(\"project notes\"),\n\t\t},\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.context.search("agent_abc123", q: "project notes")

            puts(page)
        - lang: CLI
          source: |-
            cerca context search \
              --api-key 'My API Key' \
              --agent-id agent_abc123 \
              --q 'project notes'
components:
  schemas:
    ContextSearchPage:
      type: object
      properties:
        cursor:
          type:
            - string
            - 'null'
        hasMore:
          type: boolean
        results:
          type: array
          items:
            $ref: '#/components/schemas/ContextSearchResult'
      required:
        - cursor
        - hasMore
        - results
    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
    ContextSearchResult:
      type: object
      properties:
        byteLength:
          type: number
        key:
          type: string
        mimeType:
          type: string
        updatedAt:
          type: string
        version:
          type: number
        score:
          type: number
        snippet:
          type: string
      required:
        - byteLength
        - key
        - updatedAt
        - version
        - score
        - snippet
  securitySchemes:
    bearerAuth:
      bearerFormat: Cerca API key
      scheme: bearer
      type: http

````