Get AI Spend
get_ai_spendQuery the organization's AI / LLM spend. provider selects "direct" (default — Anthropic AND OpenAI API spend together), "anthropic" (Claude API spend only), "openai" (OpenAI API spend only), or one cloud-billed lens: "bedrock" (Amazon Bedrock), "azure_openai" (Azure AI Foundry — Azure OpenAI, the other models Microsoft sells through Foundry, and Claude bought through Azure Marketplace) or "vertex" (Google Gemini / Vertex AI generative usage). ⚠ By default this returns DIRECT provider spend only and does NOT include any cloud-billed AI. Bedrock, Azure AI Foundry and Gemini / Vertex AI are billed by AWS, Azure and Google and are already counted in your cloud spend (query_costs / the cloud surfaces). Set include_bedrock: true to add Bedrock only, or include_cross_billed: true to add all three (with the default "direct" they mean both direct providers plus the lens(es); alongside "anthropic" or "openai" they mean that provider plus the lens(es)); the response then reports directTotal (provider-billed, NOT in cloud totals), crossBilledTotal (cloud-billed, ALREADY in cloud totals) and allAiTotal (their sum) separately. Never add totalCost, allAiTotal or crossBilledTotal to a cloud total when a lens is included — that double-counts it. Break it down with group_by: "model" (default), "token_type" (provider-native values — Anthropic uncached_input/output/cache_read/cache_creation, OpenAI input_uncached/input_cached/output), "workspace" (Anthropic workspaces; for OpenAI this is its Projects), "api_key" (dollars and tokens per API key: dimension is the key id, label its latest name; Anthropic and OpenAI only), "user" (dollars and tokens per user email — the key's owner or the user who made the request; Anthropic and OpenAI only), "service_tier" (batch vs standard; batch bills at a 50% discount, so this shows batch-adoption savings headroom), "cost_type" (tokens vs web_search/code_execution/session_usage dollars), "provider", "day", or "none" for a grand total; for a cloud-billed lens also "model_developer" (Azure / Vertex), "account", "region", "routing" (deployment type) and "tag" (Bedrock, with tag_key). Add split_by for a second dimension (e.g. group_by "day" + split_by "model"). Each row returns cost (dollars, currency-correct for the org), tokens (token count), requests (server-tool request counts, e.g. web_search — kept separate from tokens), and tokenMeteredCost (the part of cost that actually bought tokens — divide by that, not by cost, for an effective $/1M rate). With "api_key" or "user", the "(unattributed)" row is spend and tokens the provider ties to no key or user (older history, non-token charges, shared keys); a service account appears as "service-account:". Report the unattributed row alongside the named rows, never drop it — together they sum to the total. Do NOT compute a per-key or per-user $/1M from these rows: tokens are tied to a key on every day but dollars only on days the provider ties them, so per-row rates mix windows; quote the response-level $/1M instead. If the answer carries unpricedTokens, those are Anthropic Priority Tier commitment tokens whose cost no API reports — divide tokenMeteredCost by (totalTokens - unpricedTokens) for $/1M. PER REQUEST (OpenAI only): set per_request: true for perRequest — model requests, tokensPerRequest and costPerRequest, total and per group (group_by "model", "api_key", or "day" with api_key for one key's trend). Per key, OpenAI attributes dollars to a key only on days its per-key cost reconciles, so a key's cost per request can read low; its note says so — repeat it. By model, OpenAI can name one model differently in its cost report and its usage (e.g. gpt-4 vs gpt-4-0613): when the two names match one to one, the cost-report model's row carries the pair's requests, tokens and cost per request, and the usage-name row reads 0 with null ratios and a group note (included in the matching cost-report model) — that is not $0 per request. WHY IT CHANGED: set explain_change: true to get changeExplanation vs the immediately preceding window of the same length — volume, mix, rate and non-token lines that add up to the change to the cent, plus the top drivers; quote its summary. A matched OpenAI cost-report / usage name pair counts as one model there (shown under its cost-report name), decided over both windows. EFFICIENCY: with group_by "token_type" (or split_by "token_type" under group_by "model", "api_key", "user", "workspace", "provider" or "day") the answer adds efficiency — cacheHitRate, inputOutputRatio, cacheWritePayback and a DERIVED netCacheSavings, for the whole selection and per group. Use these instead of computing ratios from rows yourself; a null metric is NOT zero (notAvailable says why). With group_by or split_by "service_tier" it adds tierExposure (each tier's share of dollars). Filter with model, token_type, workspace, integration_id (arrays; cloud-billed lenses also account, region, service_tier, routing) and the required start_date/end_date (YYYY-MM-DD). Every answer carries sources: included (the AI sources the figures cover), excluded (AI sources this organization has that the answer leaves out — each with a reason (cloud_billed, not_selected or not_entitled) and how to add it) and notConnected (a requested source with no integration). When excluded is non-empty, say in your answer which sources were left out and why — never present a partial AI figure as the organization's total AI spend. completeThrough is the last day WITH SPEND in the window, not a loading cut-off: when it is before end_date, read freshnessNote — usually those days simply had no spend. Read-only — never modifies anything. Example: { "group_by": "model", "start_date": "2026-06-01", "end_date": "2026-06-19" } returns month-to-date Anthropic + OpenAI spend by model; add "provider": "anthropic" or "openai" for one provider, "provider": "azure_openai" / "vertex" / "bedrock" for one cloud-billed lens, or "include_cross_billed": true for everything.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"start_date": "<start_date>",
"end_date": "<end_date>"
},
"name": "get_ai_spend"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | Filter to one or more model ids (e.g. ["claude-opus-4-6"]). Maps to ServiceName. | |
| region | No | Needs provider "bedrock", "azure_openai" or "vertex": filter to one or more cloud regions (as group_by "region" returns them). | |
| account | No | Needs provider "bedrock", "azure_openai" or "vertex": filter to one or more cloud accounts by ID, not name — the AWS linked-account ID, Azure subscription path or GCP project ID exactly as group_by "account" returns them. | |
| api_key | No | Direct providers only (Anthropic, OpenAI): filter to one or more API key ids (from group_by "api_key"). With group_by "day" and per_request: true this is one key's daily tokens-per-request trend. | |
| routing | No | Needs provider "bedrock", "azure_openai" or "vertex": filter to one or more routing / deployment types (see group_by "routing"). | |
| tag_key | No | The AWS resource-tag key to group by. Only with group_by "tag", which needs provider "bedrock". | |
| end_date | Yes | Window end, YYYY-MM-DD (e.g. "2026-06-19"). | |
| group_by | No | Dimension to break spend down by. Cloud-billed lenses only: "model_developer" (who built the model — OpenAI, DeepSeek, Google, Anthropic…; Azure AI Foundry and Vertex only), "account" (AWS linked account / Azure subscription / GCP project), "region", "routing" (Bedrock in-region vs cross-region; Azure global / data-zone / regional deployment; Vertex global vs regional), "tag" (Bedrock only — an AWS resource tag; requires tag_key). Anthropic and OpenAI only: "api_key" (dollars and tokens per API key — `dimension` is the key id and `label` its latest name when the provider has one; the "(unattributed)" row is spend and tokens the provider ties to no key, such as older history and non-token charges, so the rows sum to the total) and "user" (dollars and tokens per user — `dimension` is the email of the key's owner or the user who made the request; a service account shows as "service-account:<id>"; shared keys and spend tied to no key land in "(unattributed)"). Everywhere: "model" (default), "token_type" (provider-native values, e.g. Anthropic uncached_input/output/cache_read/cache_creation, OpenAI input_uncached/input_cached/output), "workspace" (Anthropic workspace; for OpenAI this is its Projects), "service_tier" (batch vs standard — batch bills at a 50% discount, so this split shows batch-adoption savings headroom), "cost_type" (tokens vs non-token costs: web_search / code_execution / session_usage; dollars only), "provider", "day", or "none" for a single grand total. | model |
| provider | No | Which AI source to report on: "direct" (default — Anthropic AND OpenAI API spend, everything the providers bill you directly), "anthropic" (Claude API spend only), "openai" (OpenAI API spend only), or one cloud-billed lens — "bedrock" (Amazon Bedrock, AWS-billed), "azure_openai" (Azure AI Foundry: Azure OpenAI plus the other models Microsoft sells through Foundry and Claude bought through Azure Marketplace, Azure-billed) or "vertex" (Google Gemini / Vertex AI generative usage, Google-billed). The cloud-billed lenses are ALREADY counted in your cloud spend: ask for one only when the question is specifically about it, and never add it to a cloud total. To span sources in one answer, use include_bedrock or include_cross_billed instead. | direct |
| split_by | No | Optional second dimension, e.g. group_by "day" + split_by "model" for a daily series per model, or group_by "day" + split_by "user" for each user's daily spend. Must differ from group_by and be supported by every selected source ("user" is Anthropic and OpenAI only; "api_key" and "tag" cannot be a split). Each row then carries `split` (and `source`). Beyond 8 distinct split values the tail is rolled into "Other", so rows still sum to the total. | |
| workspace | No | Filter to one or more workspace ids (Anthropic workspaces; OpenAI projects). Not applicable to the cloud-billed lenses, whose sub-accounts are cloud accounts (group_by "account"). | |
| start_date | Yes | Window start, YYYY-MM-DD (e.g. "2026-06-01"). | |
| token_type | No | Filter to one or more token types — values are provider-native (e.g. Anthropic ["output_tokens","cache_read_input_tokens"]); the cloud-billed lenses (Bedrock, Azure AI Foundry, Vertex) share one vocabulary ("input-tokens", "output-tokens", "cache-read-input-tokens", "cache-write-input-tokens"), and the backend translates the direct-provider names onto it. | |
| per_request | No | OpenAI only: also return `perRequest` — model requests, tokens per request and cost per request, for the total and per group (with group_by "model", "api_key" or "day"). Anthropic does not report model requests and is never included in it. | |
| service_tier | No | Needs provider "bedrock", "azure_openai" or "vertex": filter to one or more service tiers as the lens labels them (see group_by "service_tier"). | |
| explain_change | No | Also explain why spend changed vs the IMMEDIATELY PRECEDING window of the same length: `changeExplanation` splits the change into volume (more or fewer tokens at the old blended rate), mix (a shift between models / token types, incl. new models), rate (price per token within a model and token type) and nonToken (tools, sessions) — the four lines add up to totalChange to the cent. Costs two extra backend queries; ask for it only when the question is "why did it change". | |
| integration_id | No | Filter to one or more integration ids (from list_integrations) when the organization has several connections of the same provider. | |
| include_bedrock | No | Add AWS-billed Amazon Bedrock to the direct providers, in one answer (Bedrock only — not the Azure or Google lenses; use include_cross_billed for all of them). Off by default because Bedrock dollars are already inside your cloud spend — including them unasked would invite double-counting. When on, the response separates directTotal (provider-billed) from crossBilledTotal (Bedrock) so you can never add the wrong one to a cloud figure. Ignored when provider is a cloud-billed lens. | |
| response_format | No | concise = key fields only (default, lower token cost); detailed = the full parsed payload. | concise |
| include_cross_billed | No | Opt in to the full all-AI roll-up: the direct providers PLUS every cloud-billed AI lens — Amazon Bedrock (AWS), Azure AI Foundry (Azure) and Google Gemini / Vertex AI (GCP). Off by default because those dollars are already inside your cloud spend. When on, crossBilledTotal is the cloud-billed part and directTotal the provider-billed part; never add totalCost, allAiTotal or crossBilledTotal to a cloud figure. Supersedes include_bedrock. Ignored when provider is a cloud-billed lens. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | No | Per-dimension rows — `dimension`, `cost`, `tokens`, `tokenMeteredCost` (the honest $/1M numerator), `requests`, and when present `label` (group_by "api_key": the key's latest name; `dimension` is the key id), `unpricedTokens`, `split` and `source` (split_by rows). With group_by "api_key" or "user", the "(unattributed)" row is what the provider ties to no key or user. | |
| tool | No | Which tool truncated (only on a truncated result). | |
| groupBy | No | The dimension the rows are broken down by. | |
| message | No | How to narrow the request (only on a truncated result). | |
| sources | No | Which of the organization's AI sources this answer covers: `included`, `excluded` (each with `reason` cloud_billed | not_selected | not_entitled and how to add it), `notConnected` (requested but no integration) and a one-line `note`. When `excluded` is non-empty, say so in your answer. | |
| currency | No | The organization's display currency. | |
| costBasis | No | Which cost basis each arm summed (direct vs each cloud-billed source are not the same concept). | |
| totalCost | No | Total AI spend for the selection. NEVER add this to a cloud total when any cloud-billed source (Bedrock, Azure AI Foundry, Gemini / Vertex AI) is included. | |
| truncated | No | Present and true when the result exceeded the output-size budget and was WITHHELD. When you see this, no data fields are present — narrow the request as `message` says and call again. | |
| allAiTotal | No | directTotal + crossBilledTotal. | |
| efficiency | No | Present when token_type is the group_by or the split_by. `total` (the whole selection) and `groups` (one per value of `groupBy`, e.g. per model) carry cacheHitRate (0–1, cache-read ÷ cache-read + uncached input tokens), inputOutputRatio (input ÷ output tokens), cacheWritePayback (cache reads per cache-write token) and netCacheSavings (DERIVED money in `currency`, not billed; for OpenAI it is derived from observed per-model rates and only when grouped by model and the model's cost-report and usage names match one to one, otherwise null with a notAvailable reason). A null metric is NOT zero — `notAvailable[metric]` says why (e.g. "not available for this source"). | |
| directTotal | No | Provider-billed AI spend (Anthropic / OpenAI) — NOT part of cloud totals. | |
| approx_chars | No | Approximate size of the withheld result (only on a truncated result). | |
| tierExposure | No | Present when service_tier is the group_by or the split_by: each tier's cost and share (0–1) of the selection's dollars. | |
| unpricedNote | No | Explains unpricedTokens when present. | |
| freshnessNote | No | Present when completeThrough is before the window end: says whether those days had no spend (every source synced past them) or may still be syncing. | |
| efficiencyNote | No | How to read `efficiency` — present with it. | |
| unpricedTokens | No | Tokens served under an Anthropic Priority Tier commitment — real usage whose cost no API reports. Present only when non-zero; leave them out of any $/1M denominator. | |
| completeThrough | No | The last day in this window that has spend from every included source (the OLDEST per-source dataThrough). A date before the window end means those later days either have not synced yet or simply had no spend — read `freshnessNote`, never assume missing data. | |
| sourceFreshness | No | Per source: `dataThrough` (last day with spend in the window) and `lastSyncedAt` (when it last synced). | |
| crossBilledTotal | No | Cloud-billed AI spend — Amazon Bedrock, Azure AI Foundry, Google Gemini / Vertex AI — ALREADY inside cloud totals. Adding it to cloud spend double-counts. | |
| changeExplanation | No | With explain_change: priorPeriod, priorTotal, currentTotal, totalChange = volume + mix + rate + nonToken (to the cent), the top `drivers` (source, model, tokenClass, mix, rate, new) and a one-line `summary`. Null when it could not be computed (see changeExplanationNote). | |
| changeExplanationNote | No | Why changeExplanation is null, when it is. |