Analytics API (Python)

Methods, examples, and parameters for client.analytics.

Module Overview

Track usage, latency, and provider-level breakdowns for your TheRouter.ai traffic.

Available Methods

  • client.analytics.list() - Fetch recent analytics buckets.
  • client.analytics.query() - Run filtered analytics queries.
  • client.analytics.export() - Export analytics rows as CSV.

Examples

Python
from therouter import TheRouter.ai

client = TheRouter.ai(
    api_key=os.getenv("THEROUTER_API_KEY"),
    base_url="https://api.therouter.ai/v1",
)

report = client.analytics.query(
    start="2026-02-01T00:00:00Z",
    end="2026-02-02T00:00:00Z",
    group_by=["model"],
)

print(len(report.data))
analytics-response.json
{
  "id": "req_01HXYZ123",
  "module": "analytics",
  "status": "ok"
}

Parameter Types

NameTypeRequiredDescription
start
string (ISO datetime)RequiredStart time for the analytics window.
end
string (ISO datetime)RequiredEnd time for the analytics window.
group_by
string[]Dimension keys such as model or provider.
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.