> For the complete documentation index, see [llms.txt](https://infronai.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infronai.gitbook.io/docs/billing-apis/analytics-api/query-analytics-data.md).

# Query Analytics Data

## Query Analytics Data

> Use a \[Management Key]\(<https://infronai.gitbook.io/docs/billing-apis/analytics-api/management-keys>) to query and aggregate cost, token, and rate data for your team.

```json
{"openapi":"3.1.0","info":{"title":"Infron Analytics API","version":"1.0.0"},"tags":[{"name":"Query Analytics Data"}],"servers":[{"url":"https://llm.onerouter.pro","description":"Infron API"}],"paths":{"/v1/analytics/query":{"post":{"operationId":"queryAnalyticsData","summary":"Query Analytics Data","description":"Use a [Management Key](https://infronai.gitbook.io/docs/billing-apis/analytics-api/management-keys) to query and aggregate cost, token, and rate data for your team.","tags":["Query Analytics Data"],"parameters":[{"name":"Authorization","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalyticsQuery"}}}},"responses":{"200":{"description":"Analytics query results","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalyticsResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"408":{"$ref":"#/components/responses/RequestTimeout"},"500":{"$ref":"#/components/responses/InternalServerError"}}}}},"components":{"schemas":{"AnalyticsQuery":{"type":"object","additionalProperties":false,"required":["metrics"],"properties":{"metrics":{"type":"array","description":"One or more supported metrics.","minItems":1,"uniqueItems":true,"items":{"$ref":"#/components/schemas/Metric"}},"time_range":{"type":"object","description":"The `[start, end)` query interval. If omitted, defaults to the rolling previous 720 hours.","additionalProperties":false,"required":["start","end"],"properties":{"start":{"type":"string","format":"date-time","description":"Inclusive start of the query interval in RFC 3339 format. Must include `Z` or a UTC offset."},"end":{"type":"string","format":"date-time","description":"Exclusive end of the query interval in RFC 3339 format. Must be later than `start` and include `Z` or a UTC offset."}}},"dimensions":{"type":"array","description":"Up to two supported dimensions. Results are grouped by each unique combination. `member` identifies an Infron team member; `user_id` identifies an end user in your application, not an Infron team member.","maxItems":2,"uniqueItems":true,"items":{"$ref":"#/components/schemas/Dimension"}},"filters":{"type":"array","description":"Up to 20 exact-match dimension filters. Multiple filters are combined with AND.","maxItems":20,"items":{"type":"object","additionalProperties":false,"required":["field","operator","value"],"properties":{"field":{"type":"string","description":"The dimension to filter by.","enum":["api_key","model","provider","member","user_id","session_id","app_id","tag"]},"operator":{"type":"string","description":"Exact match.","enum":["eq"]},"value":{"description":"The exact field value to match. For `member`, use the User ID copied from **Team Members → select a member → User ID**, not the member’s name or email.","type":"string"}}}},"granularity":{"type":"string","description":"Groups results into natural time buckets in `timezone`. Each row includes `date__<granularity>` with the bucket start and UTC offset. Weeks start Monday at 00:00:00; months start on the first day at 00:00:00.","enum":["minute","hour","day","week","month"]},"timezone":{"type":"string","description":"IANA time zone used for time-bucket boundaries. Defaults to `UTC` and has no effect without `granularity`.","default":"UTC"},"limit":{"type":"integer","description":"Maximum number of rows. Additional results set `truncated` to `true`; pagination is not supported.","minimum":1,"maximum":5000,"default":1000}}},"Metric":{"type":"string","description":"Supported metrics. Cost and Token metrics are summed; TPM and RPM are averaged.","enum":["usage_cost","list_cost","saved","prompt_tokens","completion_tokens","reasoning_tokens","cache_tokens","total_tokens","tpm","rpm"]},"Dimension":{"type":"string","enum":["api_key","model","provider","member","user_id","session_id","app_id","tag"]},"AnalyticsResponse":{"type":"object","additionalProperties":false,"required":["data"],"properties":{"data":{"type":"object","additionalProperties":false,"required":["data","metadata"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/AnalyticsRow"}},"metadata":{"$ref":"#/components/schemas/AnalyticsMetadata"}}}}},"AnalyticsRow":{"type":"object","description":"A dynamic flat object containing only the time field produced by the query, requested dimensions, and requested metrics.","additionalProperties":true},"AnalyticsMetadata":{"type":"object","additionalProperties":false,"required":["query_time_ms","row_count","truncated"],"properties":{"query_time_ms":{"type":"integer"},"row_count":{"type":"integer"},"truncated":{"type":"boolean"}}},"ErrorResponse":{"type":"object","additionalProperties":false,"required":["error"],"properties":{"error":{"type":"object","additionalProperties":false,"required":["code","message"],"properties":{"code":{"type":"integer"},"message":{"type":"string"}}}}}},"responses":{"BadRequest":{"description":"Invalid fields, time range, time zone, parameter count, or enum value.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Unauthorized":{"description":"The Authorization header is missing.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"The credential is not a valid, active Management Key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"RequestTimeout":{"description":"The query timed out.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"InternalServerError":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://infronai.gitbook.io/docs/billing-apis/analytics-api/query-analytics-data.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
