> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorcost.com/llms.txt
> Use this file to discover all available pages before exploring further.

# REST API

> Read spend, budgets, routing decisions and recommendations from your own scripts with an API key.

The REST API lets you pull what the console shows into your own tools: dashboards, reports, scheduled jobs. With an API key it is read-only in practice today; see [What a key can do](#what-a-key-can-do).

## Base URL and paths

```text theme={null}
https://api.tensorcost.com/v1/api/<service>/...
```

Every path starts with `/v1/api/`. For example, AI spend by customer is:

```text theme={null}
GET https://api.tensorcost.com/v1/api/ai/spend?by=customer&window=30d
```

> [!WARNING]
>
> Paths of the form `/api/<service>/...` without `/v1` do not accept API keys. They answer 401. The proxy, observation and OpenTelemetry endpoints are the opposite: they live under `/api/inference-proxy/` and take a short-lived token, not an API key. See [the proxy](https://docs.tensorcost.com/developers/proxy.md).

## Authenticate

Send an API key as a bearer token:

```bash theme={null}
curl "https://api.tensorcost.com/v1/api/ai/spend?by=customer&window=30d" \
  -H "Authorization: Bearer $TENSORCOST_REST_KEY"
```

An API key starts with `tc_`. It is different from the SDK key (which authenticates the SDK and the proxy) and from an MCP key. Each key belongs to your workspace.

The console's **Connect › API keys** page creates SDK keys, MCP keys, [usage keys](https://docs.tensorcost.com/developers/usage-pull.md) and [revenue signing secrets](https://docs.tensorcost.com/developers/revenue-push.md). It does not create REST API keys. To create one, call the key endpoint from a signed-in session, with the session's token as the bearer. A scope is `read`, `write` or `admin`:

```bash theme={null}
curl -X POST https://api.tensorcost.com/v1/api/identity/api-keys \
  -H "Authorization: Bearer $SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"reporting","scopes":"read"}'
```

The response contains the key once. Store it then; it cannot be shown again. `GET /v1/api/identity/api-keys` lists keys, `DELETE /v1/api/identity/api-keys/<id>` revokes one, and `POST /v1/api/identity/api-keys/<id>/rotate` replaces one.

## What a key can do

> [!NOTE]
>
> This is how keys behave today. Reads work. Anything that needs a workspace role returns 403 with an API key, whatever scope the key was created with. Automate writes from a signed-in session, or make them in the console.

A `read` key can only make `GET` requests; any other method returns 403 with `This API key is read-only: it can make GET requests only.` A `write` or `admin` key is allowed other methods, but a key carries no role. So creating or changing budgets, routing policies, run and period caps, alert rules and webhooks, accepting recommendations, stopping a run and minting SDK keys all return 403. Writes that need no role, such as export jobs for cost, usage and events, work.

## Useful reads

All paths below are under `https://api.tensorcost.com/v1`.

| Path | Returns |
| - | - |
| `/api/ai/spend?by=<dimension>&window=30d` | AI spend grouped by `model`, `endpoint`, `feature`, `dimension`, `team`, `provider` or `customer`. The top 50 groups, with no time axis. |
| `/api/ai/spend/customers` | Cost per customer |
| `/api/ai/spend/events` | Raw call events, paged with `limit` and `offset` |
| `/api/cost/story?from=2026-11-01&to=2026-12-01` | One deduplicated total for the range, split by AI calls, owned GPUs and cloud bills, with a series |
| `/api/cost/budgets` | Budgets |
| `/api/cost/budgets/status?ids=<id>,<id>` | Status of several budgets at once |
| `/api/cost/summary`, `/api/cost/series` | Cloud cost totals and time series |
| `/api/cost/forecast` | Cost forecast |
| `/api/cost/recommendations` | Savings recommendations |
| `/api/ai/routing-policies` | Routing policies |
| `/api/ai/decisions` | Routing decisions |
| `/api/ai/agent-runs` | Agent runs |
| `/api/alert/alerts` | Alerts |

`window` is a number of days from 1 to 365 and defaults to 30. You can use `since` and `until` as `YYYY-MM-DD` instead; `until` counts only with `since`.

### Spend by customer

```bash theme={null}
curl "https://api.tensorcost.com/v1/api/ai/spend?by=customer&window=30d" \
  -H "Authorization: Bearer $TENSORCOST_REST_KEY"
```

```json theme={null}
{
  "data": [
    {
      "key": "acme",
      "cost_cents": 18240,
      "prompt_tokens": 9120000,
      "completion_tokens": 1210000,
      "request_count": 5120
    }
  ],
  "window_days": 30,
  "generated_at": "2026-11-14T12:00:00.000Z"
}
```

### The month's total

`from` is included and `to` is excluded. Add `compare_from` and `compare_to` for a comparison period, and `grain=day`, `week` or `month` for the series.

```bash theme={null}
curl "https://api.tensorcost.com/v1/api/cost/story?from=2026-11-01&to=2026-12-01&grain=day" \
  -H "Authorization: Bearer $TENSORCOST_REST_KEY"
```

The total counts each dollar once, even when it appears in a provider's usage and on a cloud bill. See [How TensorCost counts AI spend](https://docs.tensorcost.com/concepts.md).

### Export rows

```bash theme={null}
curl "https://api.tensorcost.com/v1/api/cost/export?kind=usage&window_start=2026-11-01T00:00:00Z&window_end=2026-11-08T00:00:00Z&limit=1000" \
  -H "Authorization: Bearer $TENSORCOST_REST_KEY"
```

`kind` is `cost`, `usage` or `events`; `limit` is at most 1000, and `offset` pages. The FOCUS export needs a finance or admin role and cannot be called with a key.

> [!NOTE]
>
> The response shapes above are as the services return them today. Fields are added over time, so read the ones you need and ignore the rest.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.