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

# Free-text semantic search over span embeddings (server-side embed)

> Embeds the `q` query server-side using the tenant's configured BYOK embedding key (OpenAI preferred, Anthropic fallback), then runs pgvector similarity search over span embeddings. Designed for MCP agents and other callers that cannot produce a 1536-dim vector directly.




## OpenAPI

````yaml /api-reference/openapi.yaml get /v1/search/spans
openapi: 3.1.0
info:
  title: TruLayer API
  version: 0.1.0
  description: |
    Trace ingestion, evaluation, query, and feedback API for TruLayer AI.

    ### Authentication

    Two auth schemes coexist: SDK API keys (`Authorization: Bearer tl_...`)
    and Clerk session JWTs (dashboard). Routes marked "requires Clerk auth"
    in their summary are unreachable via API key.

    ### Roles (TRU-234)

    Dashboard requests carry one of three organization roles: `owner`,
    `member`, `viewer`. Endpoints enforce role allowlists, not rank
    comparisons. See `docs/security.md` for the full role-permission
    matrix.

    - **owner** — full control including billing, member management,
      destructive deletes on failure-rules/model-routes/webhooks/eval-rules,
      control-loop execution, and DLQ resolution.
    - **member** — read + write (ingest, feedback, evals, API keys,
      projects, failure-rules, model-routes, webhooks).
    - **viewer** — read-only dashboard access plus compliance read access
      to `/v1/audit-log` and `/v1/dlq`.
servers:
  - url: https://api.trulayer.ai
    description: Production
  - url: http://localhost:8080
    description: Local development
security:
  - BearerAuth: []
tags:
  - name: health
  - name: ingest
  - name: traces
  - name: metrics
  - name: feedback
  - name: evals
  - name: eval-rules
  - name: control
  - name: apikeys
  - name: model-routes
  - name: datasets
  - name: search
  - name: anomaly
  - name: webhooks
  - name: failure-rules
  - name: eval-runs
  - name: ci
  - name: otlp
  - name: billing
  - name: deprecations
  - name: audit
  - name: failures
  - name: projects
  - name: compliance
  - name: dsr
  - name: policies
  - name: members
paths:
  /v1/search/spans:
    get:
      tags:
        - search
      summary: Free-text semantic search over span embeddings (server-side embed)
      description: >
        Embeds the `q` query server-side using the tenant's configured BYOK
        embedding key (OpenAI preferred, Anthropic fallback), then runs pgvector
        similarity search over span embeddings. Designed for MCP agents and
        other callers that cannot produce a 1536-dim vector directly.
      operationId: searchSpansText
      parameters:
        - name: q
          in: query
          required: true
          schema:
            type: string
            minLength: 1
          description: Free-form text to embed and search.
        - name: project_id
          in: query
          required: true
          schema:
            type: string
            format: uuid
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: RFC3339 lower bound on span created_at.
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: RFC3339 upper bound on span created_at.
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            default: 20
            minimum: 1
            maximum: 100
        - name: cursor
          in: query
          required: false
          schema:
            type: string
          description: Opaque cursor returned by a previous response.
      responses:
        '200':
          description: Search results
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SpanTextSearchResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '429':
          $ref: '#/components/responses/RateLimited'
        '502':
          description: Upstream embedding provider failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    SpanTextSearchResponse:
      type: object
      required:
        - results
      properties:
        results:
          type: array
          items:
            $ref: '#/components/schemas/SpanSearchResult'
        next_cursor:
          type: string
          description: Opaque cursor for the next page, omitted on the last page.
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
    SpanSearchResult:
      type: object
      required:
        - span_id
        - trace_id
        - similarity
        - span_name
        - span_type
        - created_at
      properties:
        span_id:
          type: string
          format: uuid
        trace_id:
          type: string
          format: uuid
        similarity:
          type: number
        span_name:
          type: string
        span_type:
          type: string
        created_at:
          type: string
          format: date-time
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid credentials
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: Insufficient role
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UnprocessableEntity:
      description: Request understood but cannot be processed in the current state
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: SDK API key (`tl_...`) or Clerk session JWT

````