Learning resourcesReviewed · OpenRouter

OpenRouter Python SDK Analytics Reference

OpenRouter's Python analytics reference helps developers build usage reports, but every operation requires a management key and access depends on its permissions. It documents recent activity retrieval, discovery of available analytics fields and configurable queries, including restrictions that can affect historical coverage and returned rows.

Researched 24 Nov 2026

In short.

OpenRouter's Python analytics reference is documentation for developers building usage reporting, with management-key permissions and workspace boundaries as its main catch. It covers get_user_activity, get_analytics_meta and query_analytics, including request-count queries grouped by model and day. Historical attribution, deleted-key filtering and row limits require care when interpreting results. Installation details, pricing, licensing, full response schemas and runtime correctness are not established by this page.

Researched and written by an AI model and checked by a second AI model. How it works

Covers the complete selected Analytics documentation page at the exact supplied address, including all three operations, examples, parameter tables, permission notices and error listings. The linked documentation index, management-key guide, request and response definitions, filter models and retry configuration are excluded. No code or API calls were executed; installation, returned data, performance and service behavior remain unverified.

The overview

Resource identity

This is the Analytics reference within OpenRouter's Python client SDK documentation at [https://openrouter.ai/docs/client-sdks/python/sdks/analytics/README.md]. It describes three methods accessed through an OpenRouter client's analytics interface. Its contents are API documentation with Python examples, parameter tables, response-type references and error listings.

Practical assessment

The reference provides useful guidance for adding usage reports to a Python application. Its strongest detail concerns access boundaries: which management keys can read which workspaces, what additional permissions filters need and when historical records are excluded. It also explains how query limits can truncate time buckets. It leaves installation, complete response structures and several operating limits unspecified, so it does not establish a complete integration on its own.

Who it helps

Likely users include Python developers building internal usage reports and developers managing reporting across OpenRouter workspaces. Beginners receive short client examples, but will need additional guidance on installing the SDK and obtaining a suitable management key. Experienced developers can use the permission rules and query-limit behavior to assess whether a report will cover the intended accounts, workspaces and time periods.

Documented capabilities

get_user_activity returns activity grouped by endpoint for the previous 30 completed UTC days. workspace_id restricts the response to one workspace. group_by=workspace separates rows by workspace and includes workspace_id; the default combines workspaces and omits that field.

get_analytics_meta discovers the available metrics, dimensions, filter operators and time granularities. query_analytics accepts metrics, dimensions, filters, a time range, ordering and row limits. Its example requests request_count by model and day.

Custom classifier dimensions can group metrics by classifier tags and require an active classifier on the workspace. Classifier filters restrict results by tag values. Combining classifier filters and classifier dimensions requires the same classifier_id; classifier filters can also accompany standard dimensions.

Using it

Access requirements

All three methods require a management key. For metadata and analytics queries, Custom access requires an organization-scoped key with analytics:view. Workspace-scoped keys with base Read Only or Read Write access are also accepted, subject to workspace restrictions.

For get_user_activity, a workspace-scoped management key needs activity:view_all on its own workspace. Omitting workspace_id defaults to that workspace; requesting another workspace returns 403. api_key_hash and user_id resolve only keys and members within that workspace. Custom-key filtering by api_key_hash additionally requires api_keys:view_all and cannot resolve deleted keys.

Activity filtering by user_id needs workspace_members:view for an explicitly specified non-default workspace. Organization-level and default-workspace member filtering require org_members:view, which is unavailable as a Custom grant. For analytics queries using Custom access, grouping or filtering by api_key_id or api_key_tag additionally requires api_keys:view_all; grouping or filtering by user requires org_members:view.

How queries work

The Python client exposes reporting methods through open_router.analytics. Metrics specify what to measure, such as request_count. Dimensions specify how to divide results, such as by model. Granularity divides a time range into intervals, while filters restrict which records contribute. The metadata method supplies supported choices that this page does not enumerate completely.

The query limit defaults to 1000 total rows. For time-series queries with dimensions and no explicit group_limit, the server calculates a per-group limit and may increase the total limit to accommodate expected combinations. An explicit group_limit overrides that behavior and may truncate time buckets. It has no effect when dimensions are absent.

Setup guidance

The examples import OpenRouter from openrouter, read a credential from OPENROUTER_API_KEY and create the client inside a with block. The query example also imports parse_datetime from openrouter.utils. Although the environment variable has a general API-key name, the method descriptions explicitly require a management key.

The page supplies optional application-identification fields: http_referer, x_open_router_title and x_open_router_categories. It links to management-key documentation, but provides no installation command, supported Python version, pinned SDK release or key-creation procedure.

Documented example

The analytics example calls open_router.analytics.query_analytics with metrics=["request_count"], dimensions=["model"], granularity="day" and limit=100. Its time_range starts at 2025-01-01T00:00:00Z and ends at 2025-01-08T00:00:00Z, with both values parsed using parse_datetime. This illustrates requesting daily request counts broken down by model.

The example prints the response but includes no returned rows. Exact output fields, boundary inclusivity and successful execution are not established. The request for 100 rows should not be treated as proof that every model and day will be represented.

Assessment & evidence

Important limitations

Historical workspace coverage needs care. Activity recorded before workspace resolution existed is permanently assigned to the account's default workspace, with no backfill possible. Separately, workspace-scoped activity reads and analytics queries exclude legacy records with no workspace, including when accessing the default workspace.

Workspace-scoped analytics queries cannot request another workspace. Possible-cache metrics, including possible_cached_tokens, return 400 for these keys. Analytics key-hash filters resolve only non-deleted ordinary keys, so such filters cannot be assumed to recover every historical key's activity.

The activity parameter table marks request as required, while its example calls get_user_activity() without arguments. The exact invocation requirement is unresolved on this page. Full response schemas, analytics-query retention, data delay, pagination behavior and default retry behavior are not supplied. Runtime behavior remains unverified.

Interpreting results

The documented access rules imply that a report's completeness depends on the key, workspace scope, filters and row limits used to obtain it. A workspace report can omit legacy records, a key-filtered report can exclude deleted keys and a low explicit group_limit can remove time buckets. A successful response alone would therefore not establish complete account history. Missing rows should be investigated before interpreting them as zero usage.

Choosing an operation

Within this reference, get_user_activity suits the defined recent-activity view grouped by endpoint. query_analytics offers configurable metrics, grouping, filters and time ranges. get_analytics_meta helps discover valid query choices. Their historical coverage should not be assumed identical.

The page provides no comparison with other SDKs or analytics tools, so relative cost, ease of use and feature coverage are unknown.

Source and evidence

The evidence is the complete Analytics documentation page at [https://openrouter.ai/docs/client-sdks/python/sdks/analytics/README.md]. It supports the method names, examples, stated permissions, parameter behavior and listed error conditions.

The page references ActivityResponse, GetAnalyticsMetaResponse and QueryAnalyticsResponse, but their linked definitions are outside this evidence. It contains no example response data, benchmarks or demonstrated execution results.

Access & freshness

Costs and quotas

The page states no SDK price, analytics endpoint charge, free allowance or required subscription plan. It also gives no request-rate quota. The cost and permitted frequency of using these methods are unknown from this evidence.

Licensing and rights

The page contains no license statement or explicit redistribution permission for the documentation or examples. The SDK's license, applicable service terms and rights governing analytics data are also not established here.

Version and freshness

The documentation snapshot was captured on 24 November 2026 at 00:47:36 UTC. The page supplies no publication date, last-update date or pinned SDK version. Its January 2025 example dates illustrate query inputs and do not establish a release date. Compatibility with a particular installed SDK or the current service is unverified.

Suggested next steps

Before integrating, confirm the installation instructions and SDK version, resolve the activity request-argument discrepancy and obtain a management key with the permissions required for the intended report. Use get_analytics_meta to discover supported metrics and dimensions, then choose the reporting operation and workspace scope.

For a first query, use a short time range and inspect the actual response schema and time coverage. Check limits before relying on complete time-series results. Account for authorization failures, invalid requests and the query method's documented 408 timeout response. Each method accepts a retry override, but its default policy needs separate confirmation. Establish pricing, quotas and applicable terms before committing to recurring reporting.

Evidence for this report

selected-page.txtselected · checked 2026-11-24