Analytics API overview
The Analytics API lets you run read-only SQL queries directly against your Paid data, including usage signals, AI costs, revenue, credits, and delivered value. Use it to build your own dashboards, reports, and in-product analytics without exporting data first.
Every query is automatically scoped to your organization: you can only ever see your own data, and no organization filter is needed (or possible) in your SQL.
Prerequisites
- Have your API key ready.
The data model
Your data is exposed as a small star schema
of dimension tables (dim_*, describing entities) and fact tables
(fact_*, describing events and transactions). Facts join to dimensions on
*_id columns.
See the Schema reference for every column, and the Query cookbook for ready-to-use examples.
Endpoints
The base URL is https://api.agentpaid.io/api/v2/analytics. All
endpoints authenticate with your API key via the Authorization: Bearer header.
POST /query
Run a single SQL statement. The request body is { "query": "<sql>" }.
The response gives you typed columns, rows in column order, and metadata:
GET /schema
Returns the queryable views with their columns, types, and descriptions. This is the same information as the Schema reference, live from your account. Useful for discovery and for building tooling.
GET /signals/metadata
Signals carry a free-form JSON data payload whose shape you define. This
endpoint lists the JSON paths (and their observed types) present in your
signals, grouped by signal name, so you know what you can filter and group on.
Each path says whether it is declared, that is, whether a signal summary can
be grouped by it for your organization; declared keys are listed first. The
slot field is deprecated and no longer returned.
The window may be read in whole UTC hours: every hour from the one holding
fromDate up to the one holding toDate. A toDate exactly on the hour
leaves that hour out, so fromDate=2026-09-01T00:00:00Z and
toDate=2026-10-01T00:00:00Z read September and nothing of October 1. A
window inside one hour, such as 10:30 to 10:45, reads the whole of 10:00 to
11:00, so a path seen up to an hour outside the window can be listed. When
the window is read in whole hours, a path also carries signals, the number
of signals in those hours that carried it (each revision of an edited signal
counts again). Otherwise it is omitted, so treat it as optional.
Writing queries
The API speaks ClickHouse SQL. A few rules and conventions:
- Read-only. Only a single
SELECT(orWITH … SELECT) statement is accepted. Anything else is rejected. - No org filter needed. Queries are automatically restricted to your
organization. Reference tables by their unqualified name (
FROM fact_signal), notanalytics.fact_signalordefault.*. - Money is in stored minor units. Monetary columns hold each currency’s
stored minor units: cents for USD and EUR, so divide by 100 for display. A
query’s
meta.storedCurrencyDecimalslists any currency stored at other decimals than its own:{ "JPY": 2 }means divide yen by 100 (150000 is ¥1,500),{ "JPY": 0 }means yen are whole and not divided. Keep each currency’s totals apart. Most are integers. The exceptions arefact_cost.cost_amountandfact_delivered_value.delivered_value_cents: always hundredths ofcost_currencyanddelivered_value_currency, respectively (Decimal, possibly fractional), whatevermeta.storedCurrencyDecimalssays, so divide them by 100. - Credits are a third case: not money, not whole. The
fact_credit_transactionamount and balance columns areDecimal(38, 15), so a single spend can be a fraction of a credit. They are counts of credits, not cents, so never divide them by 100. - 64-bit integers come back as strings. Counts, sums, amounts, and large
ids (
UInt64/Int64) are returned as JSON strings to preserve precision beyond 2^53. Parse them client-side as needed. Smaller integers, floats, booleans, and dates serialize natively. - Decimal columns come back as JSON numbers, not strings (e.g.
9.5). The 64-bit quoting above does not apply to them, so aDecimalbeyond 2^53 is already rounded by the time you receive it. SelecttoString(col)when you need its exact digits.
Limits
These limits are guardrails for interactive analytics. The API is not a bulk
export mechanism. For large extracts, aggregate or paginate with
LIMIT/WHERE on an indexed column such as created_at.
Errors
Errors return a JSON body with an error, a machine-readable code, and
usually a details message.
Deprecated experimental path
The former /api/v2/experimental/analytics/* path is deprecated and is not
supported for new integrations. It remains available for existing integrations;
use /api/v2/analytics/* instead.
Related
- Schema reference for every table and column you can query.
- Query cookbook for ready-to-use SQL recipes.
- Execute a SQL query in the API reference.