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

> Run one analytics query over the project.



## OpenAPI

````yaml https://api.uselemma.ai/openapi.json post /projects/{project_id}/analytics/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:
  /projects/{project_id}/analytics/query:
    post:
      tags:
        - Analytics
      summary: Query analytics
      description: Run one analytics query over the project.
      operationId: query_project_analytics
      parameters:
        - name: project_id
          in: path
          required: true
          description: Project ID.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                from:
                  type: string
                  enum:
                    - artifact.iterated
                    - generation.completed
                    - insight.activated
                    - insight.created
                    - insight.deleted
                    - insight.merged
                    - insight.review_completed
                    - insight.revised
                    - issue.created
                    - issue.dismissed
                    - issue.flagged
                    - issue.insight_assessed
                    - issue.insight_moved
                    - issue.occurrence_recorded
                    - issue.reopened
                    - issue.resolved
                    - issue.review_started
                    - issue.slack_sent
                    - issue.unflagged
                    - span.errored
                    - tool.called
                    - trace.processed
                start:
                  type: string
                  format: date-time
                  description: >-
                    Second-aligned UTC instant. The window must end after start
                    and must be at most 90 days.
                end_exclusive:
                  type: string
                  format: date-time
                  description: >-
                    Second-aligned UTC instant. The window must end after start
                    and must be at most 90 days.
                filters:
                  type: array
                  items:
                    type: object
                    properties:
                      field:
                        type: string
                        enum:
                          - actor
                          - agent_name
                          - api_key_id
                          - cost_priced_tokens
                          - cost_total_tokens
                          - cost_unpriced_models
                          - cost_unpriced_models_truncated
                          - duration_ms
                          - error
                          - error_count
                          - estimated_cost_basis
                          - estimated_cost_usd
                          - failing_tool_calls
                          - input_tokens
                          - model
                          - model_tokens
                          - model_tokens_truncated
                          - output_tokens
                          - root_duration_ms
                          - root_status_code
                          - span_id
                          - span_name
                          - surface
                          - tool
                          - total_tokens
                          - tps
                          - trace_id
                          - user_id
                      op:
                        type: string
                        enum:
                          - eq
                          - neq
                          - gt
                          - gte
                          - lt
                          - lte
                          - in
                          - is_null
                          - is_not_null
                      value:
                        anyOf:
                          - type: string
                          - type: number
                          - type: array
                            items:
                              anyOf:
                                - type: string
                                - type: number
                    required:
                      - field
                      - op
                    additionalProperties: false
                  maxItems: 12
                group_by:
                  type: array
                  items:
                    anyOf:
                      - type: object
                        properties:
                          field:
                            type: string
                            enum:
                              - actor
                              - agent_name
                              - api_key_id
                              - cost_priced_tokens
                              - cost_total_tokens
                              - cost_unpriced_models
                              - cost_unpriced_models_truncated
                              - duration_ms
                              - error
                              - error_count
                              - estimated_cost_basis
                              - estimated_cost_usd
                              - failing_tool_calls
                              - input_tokens
                              - model
                              - model_tokens
                              - model_tokens_truncated
                              - output_tokens
                              - root_duration_ms
                              - root_status_code
                              - span_id
                              - span_name
                              - surface
                              - tool
                              - total_tokens
                              - tps
                              - trace_id
                              - user_id
                          as:
                            type: string
                        required:
                          - field
                        additionalProperties: false
                      - type: object
                        properties:
                          bucket:
                            type: string
                            enum:
                              - minute
                              - hour
                              - day
                              - week
                              - month
                          as:
                            type: string
                        required:
                          - bucket
                        additionalProperties: false
                  maxItems: 3
                measures:
                  type: array
                  items:
                    type: object
                    properties:
                      as:
                        type: string
                      agg:
                        type: string
                        enum:
                          - count
                          - uniqExact
                          - sum
                          - avg
                          - min
                          - max
                          - p50
                          - p95
                          - p99
                          - trace_cost
                          - generation_cost
                      field:
                        type: string
                        enum:
                          - actor
                          - agent_name
                          - api_key_id
                          - cost_priced_tokens
                          - cost_total_tokens
                          - cost_unpriced_models
                          - cost_unpriced_models_truncated
                          - duration_ms
                          - error
                          - error_count
                          - estimated_cost_basis
                          - estimated_cost_usd
                          - failing_tool_calls
                          - input_tokens
                          - model
                          - model_tokens
                          - model_tokens_truncated
                          - output_tokens
                          - root_duration_ms
                          - root_status_code
                          - span_id
                          - span_name
                          - surface
                          - tool
                          - total_tokens
                          - tps
                          - trace_id
                          - user_id
                      filter:
                        type: object
                        properties:
                          field:
                            type: string
                            enum:
                              - actor
                              - agent_name
                              - api_key_id
                              - cost_priced_tokens
                              - cost_total_tokens
                              - cost_unpriced_models
                              - cost_unpriced_models_truncated
                              - duration_ms
                              - error
                              - error_count
                              - estimated_cost_basis
                              - estimated_cost_usd
                              - failing_tool_calls
                              - input_tokens
                              - model
                              - model_tokens
                              - model_tokens_truncated
                              - output_tokens
                              - root_duration_ms
                              - root_status_code
                              - span_id
                              - span_name
                              - surface
                              - tool
                              - total_tokens
                              - tps
                              - trace_id
                              - user_id
                          op:
                            type: string
                            enum:
                              - eq
                              - neq
                              - gt
                              - gte
                              - lt
                              - lte
                              - in
                              - is_null
                              - is_not_null
                          value:
                            anyOf:
                              - type: string
                              - type: number
                              - type: array
                                items:
                                  anyOf:
                                    - type: string
                                    - type: number
                        required:
                          - field
                          - op
                        additionalProperties: false
                    required:
                      - as
                      - agg
                    additionalProperties: false
                  minItems: 1
                  maxItems: 8
                join:
                  type: object
                  properties:
                    from:
                      type: string
                      enum:
                        - artifact.iterated
                        - generation.completed
                        - insight.activated
                        - insight.created
                        - insight.deleted
                        - insight.merged
                        - insight.review_completed
                        - insight.revised
                        - issue.created
                        - issue.dismissed
                        - issue.flagged
                        - issue.insight_assessed
                        - issue.insight_moved
                        - issue.occurrence_recorded
                        - issue.reopened
                        - issue.resolved
                        - issue.review_started
                        - issue.slack_sent
                        - issue.unflagged
                        - span.errored
                        - tool.called
                        - trace.processed
                    'on':
                      type: string
                      enum:
                        - actor
                        - agent_name
                        - api_key_id
                        - duration_ms
                        - error
                        - input_tokens
                        - output_tokens
                        - span_id
                        - surface
                        - trace_id
                        - user_id
                    filters:
                      type: array
                      items:
                        type: object
                        properties:
                          field:
                            type: string
                            enum:
                              - actor
                              - agent_name
                              - api_key_id
                              - cost_priced_tokens
                              - cost_total_tokens
                              - cost_unpriced_models
                              - cost_unpriced_models_truncated
                              - duration_ms
                              - error
                              - error_count
                              - estimated_cost_basis
                              - estimated_cost_usd
                              - failing_tool_calls
                              - input_tokens
                              - model
                              - model_tokens
                              - model_tokens_truncated
                              - output_tokens
                              - root_duration_ms
                              - root_status_code
                              - span_id
                              - span_name
                              - surface
                              - tool
                              - total_tokens
                              - tps
                              - trace_id
                              - user_id
                          op:
                            type: string
                            enum:
                              - eq
                              - neq
                              - gt
                              - gte
                              - lt
                              - lte
                              - in
                              - is_null
                              - is_not_null
                          value:
                            anyOf:
                              - type: string
                              - type: number
                              - type: array
                                items:
                                  anyOf:
                                    - type: string
                                    - type: number
                        required:
                          - field
                          - op
                        additionalProperties: false
                      maxItems: 12
                    measures:
                      type: array
                      items:
                        type: object
                        properties:
                          as:
                            type: string
                          agg:
                            type: string
                            enum:
                              - count
                              - uniqExact
                              - sum
                              - avg
                              - min
                              - max
                              - p50
                              - p95
                              - p99
                              - trace_cost
                              - generation_cost
                          field:
                            type: string
                            enum:
                              - actor
                              - agent_name
                              - api_key_id
                              - cost_priced_tokens
                              - cost_total_tokens
                              - cost_unpriced_models
                              - cost_unpriced_models_truncated
                              - duration_ms
                              - error
                              - error_count
                              - estimated_cost_basis
                              - estimated_cost_usd
                              - failing_tool_calls
                              - input_tokens
                              - model
                              - model_tokens
                              - model_tokens_truncated
                              - output_tokens
                              - root_duration_ms
                              - root_status_code
                              - span_id
                              - span_name
                              - surface
                              - tool
                              - total_tokens
                              - tps
                              - trace_id
                              - user_id
                          filter:
                            type: object
                            properties:
                              field:
                                type: string
                                enum:
                                  - actor
                                  - agent_name
                                  - api_key_id
                                  - cost_priced_tokens
                                  - cost_total_tokens
                                  - cost_unpriced_models
                                  - cost_unpriced_models_truncated
                                  - duration_ms
                                  - error
                                  - error_count
                                  - estimated_cost_basis
                                  - estimated_cost_usd
                                  - failing_tool_calls
                                  - input_tokens
                                  - model
                                  - model_tokens
                                  - model_tokens_truncated
                                  - output_tokens
                                  - root_duration_ms
                                  - root_status_code
                                  - span_id
                                  - span_name
                                  - surface
                                  - tool
                                  - total_tokens
                                  - tps
                                  - trace_id
                                  - user_id
                              op:
                                type: string
                                enum:
                                  - eq
                                  - neq
                                  - gt
                                  - gte
                                  - lt
                                  - lte
                                  - in
                                  - is_null
                                  - is_not_null
                              value:
                                anyOf:
                                  - type: string
                                  - type: number
                                  - type: array
                                    items:
                                      anyOf:
                                        - type: string
                                        - type: number
                            required:
                              - field
                              - op
                            additionalProperties: false
                        required:
                          - as
                          - agg
                        additionalProperties: false
                      minItems: 1
                      maxItems: 8
                  required:
                    - from
                    - 'on'
                    - measures
                  additionalProperties: false
                order_by:
                  type: array
                  items:
                    type: object
                    properties:
                      measure:
                        type: string
                      direction:
                        type: string
                        enum:
                          - asc
                          - desc
                    required:
                      - measure
                      - direction
                    additionalProperties: false
                  maxItems: 2
                limit:
                  type: integer
                  exclusiveMinimum: 0
                  maximum: 500
              required:
                - from
                - start
                - end_exclusive
                - measures
              additionalProperties: false
      responses:
        '200':
          description: Analytics query rows
          content:
            application/json:
              schema:
                type: object
                properties:
                  rows:
                    type: array
                    items:
                      type: object
                      additionalProperties: {}
                  truncated:
                    type: boolean
                  window:
                    type: object
                    properties:
                      start:
                        type: string
                      end_exclusive:
                        type: string
                    required:
                      - start
                      - end_exclusive
                    additionalProperties: false
                required:
                  - rows
                  - truncated
                  - window
                additionalProperties: false
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                  code:
                    type: string
                  retryable:
                    type: boolean
                  retry_after_seconds:
                    type: number
                    minimum: 0
                required:
                  - detail
                  - code
                  - retryable
                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
                  retryable:
                    type: boolean
                  retry_after_seconds:
                    type: number
                    minimum: 0
                required:
                  - detail
                  - code
                  - retryable
                additionalProperties: false
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                  code:
                    type: string
                  retryable:
                    type: boolean
                  retry_after_seconds:
                    type: number
                    minimum: 0
                required:
                  - detail
                  - code
                  - retryable
                additionalProperties: false
        '503':
          description: Service unavailable
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                  code:
                    type: string
                  retryable:
                    type: boolean
                  retry_after_seconds:
                    type: number
                    minimum: 0
                required:
                  - detail
                  - code
                  - retryable
                additionalProperties: false
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

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