> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://respan.ai/docs/apis/metrics/get-llm-metrics-over-time/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/_mcp/server. # Get LLM metrics over time POST https://api.respan.ai/api/dashboard/llm-metrics/ Content-Type: application/json Returns LLM usage metrics in time buckets set by `time_tick`. Reference: https://respan.ai/docs/apis/metrics/get-llm-metrics-over-time ## Authentication - `Authorization` header (bearer token, required) — Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer \. 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. - `Authorization` header (bearer token, required) — Use a dashboard JWT only for dashboard-authenticated endpoints. Respan API-key endpoints use the respanApiKey auth field instead. ## Request ### Query parameters - `summary_type` (enum, optional, default: all) — Preset time range. Use this or explicit `start_time` / `end_time`. - Allowed values: `daily`, `weekly`, `monthly`, `quarterly`, `yearly`, `last_24h`, `all` - `date` (date, optional) — Base date used with `summary_type` presets. - `start_time` (datetime, optional) — Optional explicit ISO start time. - `end_time` (datetime, optional) — Optional explicit ISO end time. - `time_tick` (enum, optional, default: hour) — Bucket granularity for time-series responses. - Allowed values: `minute`, `hour`, `day` - `timezone_offset` (double, optional, default: 0) — Timezone offset, in hours, used when resolving preset ranges. - `fetch_filters` (enum, optional, default: true) — Whether to include available filter options in the response. - Allowed values: `true`, `false` ### Body (application/json) This endpoint expects a DashboardFiltersRequest. - `filters` (Filters, optional) — Narrows the spans the metrics are computed from. Each key is a field to filter on, and each value is a condition: `{"": {"operator": "", "value": [...]}}`. A span 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:** span columns, such as `model`, `provider_id`, `deployment_name`, `customer_identifier`, `custom_identifier`, `organization_key_id`, `prompt_id`, `log_type`, `status_code`, `environment`, `cost`, `latency`, `prompt_tokens`, `completion_tokens` and `total_request_tokens`, plus `metadata__` (values are strings). Aliases such as `total_tokens` and `total_cost`, and `scores__`, don't work here. **Example:** ```json { "model": {"operator": "", "value": ["gpt-5.5"]}, "customer_identifier": {"operator": "", "value": ["alex@acme.dev"]} } ``` ## Response ### 200 Successful response. - `data` (list of DashboardLLMMetricsRow, required) - `summary` (map from string to any, required) - `filter_options` (map from string to any, required, nullable) ## Errors ### 403 Forbidden Error The API key is missing, invalid or expired. - `detail` (string, required) ## Types ### Filters Each key is a field to filter on, and each value is a condition: `{"": {"operator": "", "value": [...]}}`. A result 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 `[""]`. The fields you can filter on depend on the endpoint; `metadata__` filters custom metadata where the endpoint supports it. - `status` (FilterValue, optional) — A filter condition with an operator and value. - `status_code` (FilterValue, optional) — A filter condition with an operator and value. - `unique_id` (FilterValue, optional) — A filter condition with an operator and value. - `customer_identifier` (FilterValue, optional) — A filter condition with an operator and value. - `thread_identifier` (FilterValue, optional) — A filter condition with an operator and value. - `custom_identifier` (FilterValue, optional) — A filter condition with an operator and value. - `group_identifier` (FilterValue, optional) — A filter condition with an operator and value. - `prompt_id` (FilterValue, optional) — A filter condition with an operator and value. - `trace_unique_id` (FilterValue, optional) — A filter condition with an operator and value. - `span_parent_id` (FilterValue, optional) — A filter condition with an operator and value. - `is_root_span` (FilterValue, optional) — A filter condition with an operator and value. - `span_workflow_name` (FilterValue, optional) — A filter condition with an operator and value. - `span_name` (FilterValue, optional) — A filter condition with an operator and value. - `model` (FilterValue, optional) — A filter condition with an operator and value. - `log_type` (FilterValue, optional) — A filter condition with an operator and value. - `stream` (FilterValue, optional) — A filter condition with an operator and value. - `has_tool_calls` (FilterValue, optional) — Whether the span made tool calls. - `cache_bit` (FilterValue, optional) — Whether the response was served from the Respan cache. - `cache_key` (FilterValue, optional) — A filter condition with an operator and value. - `prompt_tokens` (FilterValue, optional) — A filter condition with an operator and value. - `completion_tokens` (FilterValue, optional) — A filter condition with an operator and value. - `total_tokens` (FilterValue, optional) — A filter condition with an operator and value. - `cost` (FilterValue, optional) — A filter condition with an operator and value. - `latency` (FilterValue, optional) — A filter condition with an operator and value. - `positive_feedback` (FilterValue, optional) — A filter condition with an operator and value. ### DashboardLLMMetricsRow - `date_group` (datetime, optional) - `number_of_requests` (integer, optional, nullable) - `total_cost` (double, optional, nullable) - `total_prompt_tokens` (integer, optional, nullable) - `total_completion_tokens` (integer, optional, nullable) - `total_tokens` (integer, optional, nullable) - `max_tpm` (integer, optional, nullable) - `error_count` (integer, optional, nullable) - `error_percentage` (double, optional, nullable) - `average_prompt_tokens` (double, optional, nullable) - `average_completion_tokens` (double, optional, nullable) - `average_tokens` (double, optional, nullable) - `average_cost` (double, optional, nullable) - `average_latency` (double, optional, nullable) - `average_tps` (double, optional, nullable) - `average_ttft` (double, optional, nullable) - `prompt_cache_hit_tokens` (integer, optional, nullable) - `reasoning_tokens` (integer, optional, nullable) - `cache_hit_percentage` (double, optional, nullable) - `requests_per_second` (double, optional, nullable) - `latency` (double, optional, nullable) — Legacy empty-bucket field. - `time_to_first_token` (double, optional, nullable) — Legacy empty-bucket field. ### FilterValue A filter condition with an operator and value. - `value` (list of any, required) — Value(s) to filter by. - `operator` (enum, optional, default: ) — Comparison operator. An empty string means equals. - Allowed values: ``, `not`, `in`, `not_in`, `lt`, `lte`, `gt`, `gte`, `contains`, `not_contains`, `icontains`, `startswith`, `not_startswith`, `endswith`, `not_endswith`, `empty`, `not_empty` ## Examples **Request** ```json {} ``` **Response** ```json { "data": [ { "date_group": "2024-01-15T09:30:00Z", "number_of_requests": 1, "total_cost": 1.1, "total_prompt_tokens": 1, "total_completion_tokens": 1, "total_tokens": 1, "max_tpm": 1, "error_count": 1, "error_percentage": 1.1, "average_prompt_tokens": 1.1, "average_completion_tokens": 1.1, "average_tokens": 1.1, "average_cost": 1.1, "average_latency": 1.1, "average_tps": 1.1, "average_ttft": 1.1, "prompt_cache_hit_tokens": 1, "reasoning_tokens": 1, "cache_hit_percentage": 1.1, "requests_per_second": 1.1, "latency": 1.1, "time_to_first_token": 1.1 } ], "summary": {}, "filter_options": {} } ``` **SDK Code** ```python import requests url = "https://api.respan.ai/api/dashboard/llm-metrics/" payload = {} headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.respan.ai/api/dashboard/llm-metrics/'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.respan.ai/api/dashboard/llm-metrics/" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.respan.ai/api/dashboard/llm-metrics/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.respan.ai/api/dashboard/llm-metrics/") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php request('POST', 'https://api.respan.ai/api/dashboard/llm-metrics/', [ 'body' => '{}', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.respan.ai/api/dashboard/llm-metrics/"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/dashboard/llm-metrics/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```