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

# Query trace spans

> List or filter the spans of one trace in tree order.



## OpenAPI

````yaml https://api.uselemma.ai/openapi.json post /traces/{trace_id}/spans/query
openapi: 3.1.0
info:
  title: Lemma Platform API
  description: Lemma Platform HTTP API for AI observability and workspace operations.
  version: 0.1.0
servers:
  - url: https://api.uselemma.ai
    description: Lemma production API
security:
  - bearerAuth: []
paths:
  /traces/{trace_id}/spans/query:
    post:
      tags:
        - Traces / Spans
      summary: Query trace spans
      description: List or filter the spans of one trace in tree order.
      operationId: query_trace_spans
      parameters:
        - name: trace_id
          in: path
          required: true
          description: Trace ID.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                fields:
                  type: array
                  items:
                    type: string
                    enum:
                      - trace_id
                      - otel_span_id
                      - parent_otel_span_id
                      - name
                      - kind
                      - start_time_ns
                      - end_time_ns
                      - duration_ms
                      - status_code
                      - status_description
                      - input_tokens
                      - output_tokens
                      - model_name
                      - tps
                      - attributes
                      - events
                  minItems: 1
                context:
                  type: array
                  items:
                    type: string
                    const: preceding_generation
                limit:
                  type: integer
                  minimum: 1
                  maximum: 500
                cursor:
                  type: string
                  minLength: 1
                  maxLength: 16384
                tool_name:
                  type: string
                query:
                  type: string
                  minLength: 1
                  maxLength: 4096
                status_code:
                  type: string
                  enum:
                    - OK
                    - ERROR
                    - UNSET
              required:
                - fields
              additionalProperties: false
      responses:
        '200':
          description: Span query page
          content:
            application/json:
              schema:
                type: object
                properties:
                  spans:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        trace_id:
                          type: string
                        otel_span_id:
                          type: string
                        parent_otel_span_id:
                          type:
                            - string
                            - 'null'
                        name:
                          type: string
                        kind:
                          type:
                            - string
                            - 'null'
                        start_time_ns:
                          anyOf:
                            - type: string
                            - type: integer
                            - type: boolean
                            - type: 'null'
                        end_time_ns:
                          anyOf:
                            - type: string
                            - type: integer
                            - type: boolean
                            - type: 'null'
                        duration_ms:
                          type:
                            - number
                            - 'null'
                        status_code:
                          type:
                            - string
                            - 'null'
                        status_description:
                          type:
                            - string
                            - 'null'
                        input_tokens:
                          type:
                            - number
                            - 'null'
                        output_tokens:
                          type:
                            - number
                            - 'null'
                        model_name:
                          type:
                            - string
                            - 'null'
                        tps:
                          type:
                            - number
                            - 'null'
                        attributes:
                          type: object
                          additionalProperties: {}
                        events:
                          type: array
                          items:
                            type: object
                            additionalProperties: {}
                        context:
                          type: array
                          items:
                            type: object
                            properties:
                              relation:
                                type: string
                                const: preceding_generation
                              span:
                                type:
                                  - object
                                  - 'null'
                                properties:
                                  id:
                                    type: string
                                  trace_id:
                                    type: string
                                  otel_span_id:
                                    type: string
                                  parent_otel_span_id:
                                    type:
                                      - string
                                      - 'null'
                                  name:
                                    type: string
                                  kind:
                                    type:
                                      - string
                                      - 'null'
                                  start_time_ns:
                                    anyOf:
                                      - type: string
                                      - type: integer
                                      - type: boolean
                                      - type: 'null'
                                  end_time_ns:
                                    anyOf:
                                      - type: string
                                      - type: integer
                                      - type: boolean
                                      - type: 'null'
                                  duration_ms:
                                    type:
                                      - number
                                      - 'null'
                                  status_code:
                                    type:
                                      - string
                                      - 'null'
                                  status_description:
                                    type:
                                      - string
                                      - 'null'
                                  input_tokens:
                                    type:
                                      - number
                                      - 'null'
                                  output_tokens:
                                    type:
                                      - number
                                      - 'null'
                                  model_name:
                                    type:
                                      - string
                                      - 'null'
                                  tps:
                                    type:
                                      - number
                                      - 'null'
                                  attributes:
                                    type: object
                                    additionalProperties: {}
                                  events:
                                    type: array
                                    items:
                                      type: object
                                      additionalProperties: {}
                                required:
                                  - id
                                additionalProperties: false
                            required:
                              - relation
                              - span
                            additionalProperties: false
                      required:
                        - id
                      additionalProperties: false
                  next_request:
                    type:
                      - object
                      - 'null'
                    properties:
                      operation:
                        type: string
                        minLength: 1
                      arguments:
                        type: object
                        properties:
                          fields:
                            type: array
                            items:
                              type: string
                              enum:
                                - trace_id
                                - otel_span_id
                                - parent_otel_span_id
                                - name
                                - kind
                                - start_time_ns
                                - end_time_ns
                                - duration_ms
                                - status_code
                                - status_description
                                - input_tokens
                                - output_tokens
                                - model_name
                                - tps
                                - attributes
                                - events
                            minItems: 1
                          context:
                            type: array
                            items:
                              type: string
                              const: preceding_generation
                          limit:
                            type: integer
                            minimum: 1
                            maximum: 500
                          cursor:
                            type: string
                            minLength: 1
                            maxLength: 16384
                          tool_name:
                            type: string
                          query:
                            type: string
                            minLength: 1
                            maxLength: 4096
                          status_code:
                            type: string
                            enum:
                              - OK
                              - ERROR
                              - UNSET
                          trace_id:
                            type: string
                            minLength: 1
                        additionalProperties: false
                    required:
                      - operation
                      - arguments
                    additionalProperties: false
                required:
                  - spans
                  - next_request
                additionalProperties: false
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                  code:
                    type: string
                required:
                  - detail
                additionalProperties: false
        '401':
          description: Unauthenticated
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                  code:
                    type: string
                required:
                  - detail
                additionalProperties: false
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                  code:
                    type: string
                required:
                  - detail
                additionalProperties: false
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                  code:
                    type: string
                required:
                  - detail
                additionalProperties: false
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.