Skip to main content
Glama

Get AI Spend

get_ai_spend
Read-only

Query 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

NameRequiredDescriptionDefault
modelNoFilter to one or more model ids (e.g. ["claude-opus-4-6"]). Maps to ServiceName.
regionNoNeeds provider "bedrock", "azure_openai" or "vertex": filter to one or more cloud regions (as group_by "region" returns them).
accountNoNeeds 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_keyNoDirect 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.
routingNoNeeds provider "bedrock", "azure_openai" or "vertex": filter to one or more routing / deployment types (see group_by "routing").
tag_keyNoThe AWS resource-tag key to group by. Only with group_by "tag", which needs provider "bedrock".
end_dateYesWindow end, YYYY-MM-DD (e.g. "2026-06-19").
group_byNoDimension 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
providerNoWhich 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_byNoOptional 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.
workspaceNoFilter 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_dateYesWindow start, YYYY-MM-DD (e.g. "2026-06-01").
token_typeNoFilter 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_requestNoOpenAI 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_tierNoNeeds provider "bedrock", "azure_openai" or "vertex": filter to one or more service tiers as the lens labels them (see group_by "service_tier").
explain_changeNoAlso 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_idNoFilter to one or more integration ids (from list_integrations) when the organization has several connections of the same provider.
include_bedrockNoAdd 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_formatNoconcise = key fields only (default, lower token cost); detailed = the full parsed payload.concise
include_cross_billedNoOpt 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

NameRequiredDescriptionDefault
rowsNoPer-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.
toolNoWhich tool truncated (only on a truncated result).
groupByNoThe dimension the rows are broken down by.
messageNoHow to narrow the request (only on a truncated result).
sourcesNoWhich 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.
currencyNoThe organization's display currency.
costBasisNoWhich cost basis each arm summed (direct vs each cloud-billed source are not the same concept).
totalCostNoTotal 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.
truncatedNoPresent 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.
allAiTotalNodirectTotal + crossBilledTotal.
efficiencyNoPresent 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").
directTotalNoProvider-billed AI spend (Anthropic / OpenAI) — NOT part of cloud totals.
approx_charsNoApproximate size of the withheld result (only on a truncated result).
tierExposureNoPresent when service_tier is the group_by or the split_by: each tier's cost and share (0–1) of the selection's dollars.
unpricedNoteNoExplains unpricedTokens when present.
freshnessNoteNoPresent when completeThrough is before the window end: says whether those days had no spend (every source synced past them) or may still be syncing.
efficiencyNoteNoHow to read `efficiency` — present with it.
unpricedTokensNoTokens 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.
completeThroughNoThe 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.
sourceFreshnessNoPer source: `dataThrough` (last day with spend in the window) and `lastSyncedAt` (when it last synced).
crossBilledTotalNoCloud-billed AI spend — Amazon Bedrock, Azure AI Foundry, Google Gemini / Vertex AI — ALREADY inside cloud totals. Adding it to cloud spend double-counts.
changeExplanationNoWith 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).
changeExplanationNoteNoWhy changeExplanation is null, when it is.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only say read-only and open-world; the description layers on the real behavioral hazards: double-counting across cloud totals, the "(unattributed)" row's effect on sums, unpriced Priority Tier tokens distorting $/1M, OpenAI cost-report/usage name mismatches reading as zero, and completeThrough/freshnessNote semantics. It even discloses cost implications (explain_change costs two extra backend queries).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The purpose and the double-counting warning are front-loaded, which is good, but the body is a wall of run-on sentences that re-enumerates enums and caveats already fully documented in the 100%-covered schema. It reads as documentation prose rather than a selection aid, and an agent must wade through unsplit paragraphs to find the operative rules.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 20-parameter tool with an output schema, the description covers everything an agent needs: source coverage and exclusions, response fields worth quoting, double-counting rules, and failure/edge semantics. Nothing material about calling it correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% and the schema itself already spells out provider, group_by and per_request semantics, so much of the parameter discussion is restated. Beyond the schema it adds genuine interaction knowledge: split_by must differ from group_by, api_key cannot be a split, tag requires tag_key and bedrock, and group_by "day" + api_key + per_request yields one key's trend.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb and resource: "Query the organization's AI / LLM spend," then immediately delimits scope (direct Anthropic+OpenAI by default vs cloud-billed lenses). It differentiates from siblings by naming query_costs and "the cloud surfaces" as the place cloud-billed AI is already counted.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicit when-to-use rules throughout: use include_bedrock/include_cross_billed only when you want cloud-billed AI, never add crossBilledTotal/allAiTotal to a cloud total, use per_request only for OpenAI, request explain_change only when the question is "why did it change." It also names the alternative surface (query_costs) for cloud totals.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources