Skip to Content

List span groups with filters

POSThttps://api.respan.ai/api/request-logs/groups/

Group spans using the same query parameters as GET and optional standard Respan filters in the request body.

Servers

https://api.respan.ai: Respan API Server

Authentication

RespanApiKey

Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.

HTTP scheme: bearer; format: Respan API key.

HTTP
Authorization: Bearer $RESPAN_API_KEY

Or:

DashboardJwt

Use a dashboard JWT only for dashboard-authenticated endpoints. Respan API-key endpoints use the respanApiKey auth field instead.

HTTP scheme: bearer; format: Dashboard JWT.

HTTP
Authorization: Bearer $RESPAN_DASHBOARD_JWT

Query parameters

Parameter Type Required Description and constraints
group_by string Optional
Grouping dimension. trace and thread use entity rollups.
Allowed: "model", "provider_id", "organization_key_id", "prompt_id", "deployment_id", "deployment_name", "custom_identifier", "customer_identifier", "trace", "thread"
Default: model
sort_by string Optional
Default: number_of_requests
start_time string Optional
Format: date-time
end_time string Optional
Format: date-time
environment string Optional
-
page integer Optional
Minimum: 1
page_size integer Optional
Minimum: 1
Maximum: 1000

Request body

The request body is optional.

application/json

Field Type Requirement Description and constraints
$ object Optional body
-
filters object Optional
Narrows what’s grouped.

Each key is a field to filter on, and each value is a condition: {"<field>": {"operator": "<operator>", "value": [...]}}. Each span, trace or thread must match every condition. To set two conditions on one field, such as a range, pass a list of conditions.

Operators: "" (equals, the default), not, in, not_in, lt, lte, gt, gte, contains, not_contains, icontains (ignores case), startswith, not_startswith, endswith, not_endswith, empty, not_empty. Put values in a list: "" and in match any of the listed values, and not and not_in match none of them. Other operators take one value; for empty and not_empty, send [""].

Fields depend on group_by:
- trace: trace fields such as total_cost, error_count, span_count, customer_identifier and metadata__<key>, plus span fields such as model, which match a trace when any of its spans matches.
- thread: thread fields such as thread_identifier, customer_identifier, number_of_requests, total_cost and total_tokens.
- Any other value: span columns, such as model, provider_id, deployment_name, customer_identifier, custom_identifier, organization_key_id, prompt_id, log_type, status_code, cost, latency, prompt_tokens, completion_tokens and total_request_tokens, plus metadata__<key> (values are strings). Aliases such as total_tokens don’t work.

Example:

json<br />{<br /> "status_code": {"operator": "not", "value": [200]},<br /> "metadata__plan": {"operator": "", "value": ["pro"]}<br />}<br />
Additional properties are allowed

OpenAPI request schema

{
  "type": "object",
  "properties": {
    "filters": {
      "type": "object",
      "additionalProperties": true,
      "description": "Narrows what's grouped.\n\nEach key is a field to filter on, and each value is a condition: `{\"<field>\": {\"operator\": \"<operator>\", \"value\": [...]}}`. Each span, trace or thread must match every condition. To set two conditions on one field, such as a range, pass a list of conditions.\n\n**Operators:** `\"\"` (equals, the default), `not`, `in`, `not_in`, `lt`, `lte`, `gt`, `gte`, `contains`, `not_contains`, `icontains` (ignores case), `startswith`, `not_startswith`, `endswith`, `not_endswith`, `empty`, `not_empty`. Put values in a list: `\"\"` and `in` match any of the listed values, and `not` and `not_in` match none of them. Other operators take one value; for `empty` and `not_empty`, send `[\"\"]`.\n\n**Fields** depend on `group_by`:\n- `trace`: trace fields such as `total_cost`, `error_count`, `span_count`, `customer_identifier` and `metadata__<key>`, plus span fields such as `model`, which match a trace when any of its spans matches.\n- `thread`: thread fields such as `thread_identifier`, `customer_identifier`, `number_of_requests`, `total_cost` and `total_tokens`.\n- Any other value: span columns, such as `model`, `provider_id`, `deployment_name`, `customer_identifier`, `custom_identifier`, `organization_key_id`, `prompt_id`, `log_type`, `status_code`, `cost`, `latency`, `prompt_tokens`, `completion_tokens` and `total_request_tokens`, plus `metadata__<key>` (values are strings). Aliases such as `total_tokens` don't work.\n\n**Example:**\n\n```json\n{\n  \"status_code\": {\"operator\": \"not\", \"value\": [200]},\n  \"metadata__plan\": {\"operator\": \"\", \"value\": [\"pro\"]}\n}\n```"
    }
  }
}

Responses

200

Paginated groups and aggregate metrics.

application/json

Field Type Requirement Description and constraints
$ object Body
-
count integer Required in parent
Number of results on this page, not the total. Request pages until next is null to get every result.
next string or null Optional
-
previous string or null Optional
-
current_filters object Optional
Additional properties are allowed
filters_data object Optional
Additional properties are allowed
results array<object> Required in parent
-
results[] object Array item
Aggregated metrics plus the selected group key. Trace and thread groups include their richer entity fields.
Additional properties are allowed
results[].date_group string Optional
Format: date-time
results[].model string Optional
-
results[].provider_id string Optional
-
results[].organization_key_id string Optional
-
results[].prompt_id string Optional
-
results[].deployment_id string Optional
-
results[].deployment_name string Optional
-
results[].custom_identifier string Optional
-
results[].customer_identifier string Optional
-
results[].trace_unique_id string Optional
-
results[].thread_identifier string Optional
-
results[].number_of_requests integer or null Optional
-
results[].span_count integer or null Optional
-
results[].total_cost number or null Optional
-
results[].total_tokens integer or null Optional
-
results[].error_count integer or null Optional
-
results[].error_percentage number or null Optional
-
results[].average_cost number or null Optional
-
results[].average_tokens integer or null Optional
-
results[].average_latency number or null Optional
-
results[].average_ttft number or null Optional
-
results[].average_tps number or null Optional
-
results[].cache_hit_percentage number or null Optional
-

OpenAPI response schema

{
  "type": "object",
  "required": [
    "count",
    "results"
  ],
  "properties": {
    "count": {
      "type": "integer",
      "description": "Number of results on this page, not the total. Request pages until `next` is null to get every result."
    },
    "next": {
      "type": "string",
      "nullable": true
    },
    "previous": {
      "type": "string",
      "nullable": true
    },
    "current_filters": {
      "type": "object",
      "additionalProperties": true
    },
    "filters_data": {
      "type": "object",
      "additionalProperties": true
    },
    "results": {
      "type": "array",
      "items": {
        "type": "object",
        "description": "Aggregated metrics plus the selected group key. Trace and thread groups include their richer entity fields.",
        "properties": {
          "date_group": {
            "type": "string",
            "format": "date-time"
          },
          "model": {
            "type": "string"
          },
          "provider_id": {
            "type": "string"
          },
          "organization_key_id": {
            "type": "string"
          },
          "prompt_id": {
            "type": "string"
          },
          "deployment_id": {
            "type": "string"
          },
          "deployment_name": {
            "type": "string"
          },
          "custom_identifier": {
            "type": "string"
          },
          "customer_identifier": {
            "type": "string"
          },
          "trace_unique_id": {
            "type": "string"
          },
          "thread_identifier": {
            "type": "string"
          },
          "number_of_requests": {
            "type": "integer",
            "nullable": true
          },
          "span_count": {
            "type": "integer",
            "nullable": true
          },
          "total_cost": {
            "type": "number",
            "nullable": true
          },
          "total_tokens": {
            "type": "integer",
            "nullable": true
          },
          "error_count": {
            "type": "integer",
            "nullable": true
          },
          "error_percentage": {
            "type": "number",
            "nullable": true
          },
          "average_cost": {
            "type": "number",
            "nullable": true
          },
          "average_tokens": {
            "type": "integer",
            "nullable": true
          },
          "average_latency": {
            "type": "number",
            "nullable": true
          },
          "average_ttft": {
            "type": "number",
            "nullable": true
          },
          "average_tps": {
            "type": "number",
            "nullable": true
          },
          "cache_hit_percentage": {
            "type": "number",
            "nullable": true
          }
        },
        "additionalProperties": true
      }
    }
  }
}

400

Unsupported group_by value. Invalid sort_by falls back to number_of_requests.

application/json

Field Type Requirement Description and constraints
$ object Body
-
error string Required in parent
-

OpenAPI response schema

{
  "type": "object",
  "required": [
    "error"
  ],
  "properties": {
    "error": {
      "type": "string"
    }
  }
}
Example
JSON
{ "error": "Not supported group_by value" }

403

The API key is missing, invalid or expired, or it doesn’t grant analytics read access.

application/json

Field Type Requirement Description and constraints
$ object Body
-
detail string Required in parent
-

OpenAPI response schema

{
  "type": "object",
  "required": [
    "detail"
  ],
  "properties": {
    "detail": {
      "type": "string"
    }
  }
}
Example
JSON
{ "detail": "Your API key is invalid or expired, please check your API key in the platform settings." }

OpenAPI source

The operation and referenced components below retain the complete OpenAPI definitions, including constraints and examples.

OpenAPI operation

{
  "tags": [
    "Spans"
  ],
  "parameters": [
    {
      "name": "group_by",
      "in": "query",
      "required": false,
      "schema": {
        "type": "string",
        "enum": [
          "model",
          "provider_id",
          "organization_key_id",
          "prompt_id",
          "deployment_id",
          "deployment_name",
          "custom_identifier",
          "customer_identifier",
          "trace",
          "thread"
        ],
        "default": "model"
      },
      "description": "Grouping dimension. `trace` and `thread` use entity rollups."
    },
    {
      "name": "sort_by",
      "in": "query",
      "required": false,
      "schema": {
        "type": "string",
        "default": "number_of_requests"
      }
    },
    {
      "name": "start_time",
      "in": "query",
      "required": false,
      "schema": {
        "type": "string",
        "format": "date-time"
      }
    },
    {
      "name": "end_time",
      "in": "query",
      "required": false,
      "schema": {
        "type": "string",
        "format": "date-time"
      }
    },
    {
      "name": "environment",
      "in": "query",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "page",
      "in": "query",
      "required": false,
      "schema": {
        "type": "integer",
        "minimum": 1
      }
    },
    {
      "name": "page_size",
      "in": "query",
      "required": false,
      "schema": {
        "type": "integer",
        "minimum": 1,
        "maximum": 1000
      }
    }
  ],
  "responses": {
    "200": {
      "description": "Paginated groups and aggregate metrics.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "count",
              "results"
            ],
            "properties": {
              "count": {
                "type": "integer",
                "description": "Number of results on this page, not the total. Request pages until `next` is null to get every result."
              },
              "next": {
                "type": "string",
                "nullable": true
              },
              "previous": {
                "type": "string",
                "nullable": true
              },
              "current_filters": {
                "type": "object",
                "additionalProperties": true
              },
              "filters_data": {
                "type": "object",
                "additionalProperties": true
              },
              "results": {
                "type": "array",
                "items": {
                  "type": "object",
                  "description": "Aggregated metrics plus the selected group key. Trace and thread groups include their richer entity fields.",
                  "properties": {
                    "date_group": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "model": {
                      "type": "string"
                    },
                    "provider_id": {
                      "type": "string"
                    },
                    "organization_key_id": {
                      "type": "string"
                    },
                    "prompt_id": {
                      "type": "string"
                    },
                    "deployment_id": {
                      "type": "string"
                    },
                    "deployment_name": {
                      "type": "string"
                    },
                    "custom_identifier": {
                      "type": "string"
                    },
                    "customer_identifier": {
                      "type": "string"
                    },
                    "trace_unique_id": {
                      "type": "string"
                    },
                    "thread_identifier": {
                      "type": "string"
                    },
                    "number_of_requests": {
                      "type": "integer",
                      "nullable": true
                    },
                    "span_count": {
                      "type": "integer",
                      "nullable": true
                    },
                    "total_cost": {
                      "type": "number",
                      "nullable": true
                    },
                    "total_tokens": {
                      "type": "integer",
                      "nullable": true
                    },
                    "error_count": {
                      "type": "integer",
                      "nullable": true
                    },
                    "error_percentage": {
                      "type": "number",
                      "nullable": true
                    },
                    "average_cost": {
                      "type": "number",
                      "nullable": true
                    },
                    "average_tokens": {
                      "type": "integer",
                      "nullable": true
                    },
                    "average_latency": {
                      "type": "number",
                      "nullable": true
                    },
                    "average_ttft": {
                      "type": "number",
                      "nullable": true
                    },
                    "average_tps": {
                      "type": "number",
                      "nullable": true
                    },
                    "cache_hit_percentage": {
                      "type": "number",
                      "nullable": true
                    }
                  },
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "400": {
      "description": "Unsupported group_by value. Invalid sort_by falls back to number_of_requests.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "error"
            ],
            "properties": {
              "error": {
                "type": "string"
              }
            }
          },
          "example": {
            "error": "Not supported group_by value"
          }
        }
      }
    },
    "403": {
      "description": "The API key is missing, invalid or expired, or it doesn't grant analytics read access.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "detail"
            ],
            "properties": {
              "detail": {
                "type": "string"
              }
            }
          },
          "example": {
            "detail": "Your API key is invalid or expired, please check your API key in the platform settings."
          }
        }
      }
    }
  },
  "security": [
    {
      "RespanApiKey": []
    },
    {
      "DashboardJwt": []
    }
  ],
  "summary": "List span groups with filters",
  "operationId": "request_logs_groups_filter",
  "description": "Group spans using the same query parameters as GET and optional standard Respan filters in the request body.",
  "requestBody": {
    "required": false,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "filters": {
              "type": "object",
              "additionalProperties": true,
              "description": "Narrows what's grouped.\n\nEach key is a field to filter on, and each value is a condition: `{\"<field>\": {\"operator\": \"<operator>\", \"value\": [...]}}`. Each span, trace or thread must match every condition. To set two conditions on one field, such as a range, pass a list of conditions.\n\n**Operators:** `\"\"` (equals, the default), `not`, `in`, `not_in`, `lt`, `lte`, `gt`, `gte`, `contains`, `not_contains`, `icontains` (ignores case), `startswith`, `not_startswith`, `endswith`, `not_endswith`, `empty`, `not_empty`. Put values in a list: `\"\"` and `in` match any of the listed values, and `not` and `not_in` match none of them. Other operators take one value; for `empty` and `not_empty`, send `[\"\"]`.\n\n**Fields** depend on `group_by`:\n- `trace`: trace fields such as `total_cost`, `error_count`, `span_count`, `customer_identifier` and `metadata__<key>`, plus span fields such as `model`, which match a trace when any of its spans matches.\n- `thread`: thread fields such as `thread_identifier`, `customer_identifier`, `number_of_requests`, `total_cost` and `total_tokens`.\n- Any other value: span columns, such as `model`, `provider_id`, `deployment_name`, `customer_identifier`, `custom_identifier`, `organization_key_id`, `prompt_id`, `log_type`, `status_code`, `cost`, `latency`, `prompt_tokens`, `completion_tokens` and `total_request_tokens`, plus `metadata__<key>` (values are strings). Aliases such as `total_tokens` don't work.\n\n**Example:**\n\n```json\n{\n  \"status_code\": {\"operator\": \"not\", \"value\": [200]},\n  \"metadata__plan\": {\"operator\": \"\", \"value\": [\"pro\"]}\n}\n```"
            }
          }
        }
      }
    }
  }
}

OpenAPI path metadata

{}

Referenced OpenAPI components

{
  "securitySchemes": {
    "DashboardJwt": {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "Dashboard JWT",
      "description": "Use a dashboard JWT only for dashboard-authenticated endpoints. Respan API-key endpoints use the respanApiKey auth field instead.",
      "x-fern-bearer": {
        "name": "dashboardJwt",
        "env": "RESPAN_DASHBOARD_JWT"
      }
    },
    "RespanApiKey": {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "Respan API key",
      "description": "Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.",
      "x-fern-bearer": {
        "name": "respanApiKey",
        "env": "RESPAN_API_KEY"
      }
    }
  }
}