Rightshold™ Sign up

Answers · agent payments

How do I see how much each AI agent spends on LLM API calls?

Last updated

TL;DR: Attribute cost by key. If each agent has its own API key (or its own project or workspace), the providers' admin reporting APIs can split spend for you. OpenAI's Costs API (GET /v1/organization/costs) groups daily cost by project_id, api_key_id and line_item, and its Completions usage endpoint gives token counts by key in 1-minute, 1-hour or 1-day buckets. Anthropic's Usage and Cost Analytics API (GET /v1/organizations/analytics/cost, beta) groups cost by api_key_id and workspace_id; its older cost_report groups by workspace only. OpenRouter's GET /api/v1/key returns a key's usage for the current UTC day, week and month. These reports lag (Anthropic says its analytics data typically refreshes within 4 hours and can take up to 24), so use them for accounting and use per-key caps, not reports, to stop a runaway agent.

What should I check, step by step?

1. Give each agent its own key, and ideally its own OpenAI project or Claude workspace. Every report below splits by key or project, not by which agent happened to use a shared key.

  1. Create an admin credential for reporting only (OpenAI Admin API key; Anthropic Admin API key) and keep it away from the agents themselves.
  2. OpenAI: call GET /v1/organization/costs with group_by=project_id,api_key_id for dollars (daily buckets only), and GET /v1/organization/usage/completions with group_by=api_key_id,model for tokens and request counts.
  3. Anthropic: call GET /v1/organizations/analytics/cost with group_by[]=api_key_id (send the anthropic-beta: analytics-usage-cost-2026-08-24 header). A request can span at most 31 days, starting no earlier than January 1, 2026.
  4. OpenRouter: call GET /api/v1/key with each agent's key for usage_daily, usage_weekly and usage_monthly plus limit_remaining, or read the same numbers for all keys through the management API.
  5. Map key IDs to agent names in your own table when you create the keys, and record when a key is retired, so old spend still has an owner.
  6. Reconcile monthly: Anthropic says values can be revised until about 7 days after a calendar month ends, so close a month's per-agent numbers only after that.
  7. Count the calls these reports can't see: playground or console usage (Anthropic reports it with a null api_key_id) and paid tools outside the model provider, such as data APIs or x402 payments.

What each report can split by

OpenAI's Costs endpoint returns daily buckets and accepts group_by project_id, line_item, api_key_id (plus user_id and api_source in current SDKs) and filters such as project_ids and api_key_ids. Its Completions usage endpoint adds model, batch and service_tier grouping and finer time buckets.

Why reports aren't a brake

Anthropic says analytics data typically refreshes within 4 hours of the usage and can take up to 24 hours, and every response carries a data_refreshed_at timestamp after which numbers are partial. A loop can spend a lot in four hours.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “Record this agent's $0.12 call to api.openai.com against its own spending policy, tagged with my run ID, so its daily total stays separate from my other agents.”

One-click setup

{
  "tool": "authorize_spend",
  "arguments": {
    "credential_id": "<this agent's credential id>",
    "amount_minor": 12,
    "currency": "USD",
    "merchant_domain": "api.openai.com",
    "category": "llm_api",
    "reference": "<run id>"
  }
}

Rightshold only counts amounts your agent reports to authorize_spend before spending; it doesn't read OpenAI, Anthropic or OpenRouter billing, meter tokens or know the final price of a call. Use the providers' reports for what was actually billed. Not accounting or financial advice.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'