Let your coding agent track API spend with MCP

Give Claude Code, Cursor or Codex a read-only view of every metered API you build with, so it can check what a run cost, spot a leak, and notice a provider running dry.

Add the Argus MCP server (https://api.argus.town/mcp) to your coding agent with an MCP key. The agent gets read tools over every provider you've connected: get_overview for balances, burn and days to zero, get_request_costs for what recent calls cost, and get_advisories for low credits, spend spikes and rate limits. It can then answer "what did that run cost?" without you opening ten dashboards.

Why the agent should hold the meter

While you're developing, most API spend is the agent's: test runs against a real model, an eval loop, a scraper you asked it to try on a few hundred URLs. It knows what it just ran. It doesn't know what that cost, and provider dashboards lag by hours and cover one vendor each. Give it the meter and it can check its own work the way it checks a test suite.

Set it up

  1. 1
    Connect your providers

    Paste a key per provider in Argus. OpenAI and Anthropic need an org admin key, not a normal API key; the integration pages list the exact credential for each. For per-call costs, also wrap fetch with the SDK or send events to the ingest API.

  2. 2
    Create an MCP key

    Settings → API keys, type mcp. The key is scoped to one project, so an agent holding it can only see and act on that project.

  3. 3
    Add the server to your agent

    Claude Code:

    claude mcp add --transport http argus https://api.argus.town/mcp \
      --header "Authorization: Bearer $ARGUS_MCP_KEY"

    Cursor (.cursor/mcp.json) and most other clients take the same server block:

    {
      "mcpServers": {
        "argus": {
          "url": "https://api.argus.town/mcp",
          "headers": { "Authorization": "Bearer argus_mcp_..." }
        }
      }
    }
  4. 4
    Ask about spend

    "What has OpenRouter cost today?" "Which provider runs out first?" "What did the last 50 Firecrawl calls cost, by endpoint?" The agent picks the tool.

What a run cost

get_request_costs returns the most recent itemized calls for a provider, up to 100. Each carries its cost and where that number came from: provider_reported when the provider put the cost on the response (OpenRouter, Perplexity, Exa), derived when Argus priced tokens or units from its rate catalog.

// get_request_costs { "provider": "openrouter", "limit": 3 }
[
  {
    "endpoint": "/api/v1/chat/completions",
    "model": "anthropic/claude-sonnet-4.5",
    "status": 200,
    "latencyMs": 4120,
    "units": { "input_tokens": 18234, "output_tokens": 912, "cached_tokens": 16000 },
    "costUsd": 0.0231,
    "provenance": "provider_reported",
    "occurredAt": "2026-10-17T14:02:11.000Z"
  },
  …
]

To cost a run, the agent notes the time before it starts and sums costUsd for calls after it. Polled meters alone give daily totals, so per-run numbers need the SDK or ingest path.

Leaks, dry providers, and what to change

get_advisories returns the warnings Argus has computed for every provider. These are the codes and what trips them:

CodeFires when
credits_criticalCredits run out in 3 days or less at the current burn.
credits_lowCredits run out in 7 days or less.
spend_spikeSpend is up 50% or more week over week.
rate_limit_low10% or less rate-limit headroom left.
error_rate_high20% or more of requests are erroring or rate-limited.
plan_near_exhaustionA subscription's included allowance is nearly used.
plan_exhaustedThe allowance is used up.
under_utilized_planYou're paying for a bigger plan than you use.
models_unmatchedA model has no rate, so its cost is a fallback estimate.

A spend spike on a provider you didn't touch this week is usually a cron or a retry loop. Finding the leak walks through narrowing it down. For optimizing, ask the agent to group recent calls by model and endpoint: the expensive call that runs a thousand times is almost always the one worth changing.

Make it a habit, not a question

Agents follow repo instructions. A few lines in AGENTS.md or CLAUDE.md turn the check into part of every task:

## API spend

This repo calls paid APIs (OpenRouter, Firecrawl, Tavily). The Argus MCP server
is configured as "argus".

- Before a task that will call them in a loop, note the time and run get_overview.
- After it, call get_request_costs for each provider you used and report the
  total for calls since that time.
- If get_advisories returns credits_low, credits_critical or spend_spike,
  stop and tell me before continuing.

What the agent can and can't do

  • Read: get_overview, list_connections, get_provider, get_rate_limit_status, get_advisories, get_cost_accuracy, get_request_costs.
  • Manage: list_available_providers, connect_provider (with a key you give it), sync_connection to force a refresh.
  • Never: remove a connection. Deleting one erases its ledger, so that stays a human action in the dashboard.

Questions

Can my coding agent see my provider API keys through Argus?
No. The read tools return metrics: balances, spend, runway, itemized call costs and advisories. Provider keys are stored encrypted and never returned. The agent can connect a provider if you hand it a key, but there is no tool to read or delete one.
Which coding agents work with the Argus MCP server?
Any MCP client that supports remote HTTP servers with a header: Claude Code, Cursor, Codex, Gemini CLI, OpenCode and others. They all use the same URL and bearer header.
How fresh is what the agent sees?
Polled meters (balances, daily spend, plans) refresh hourly. Per-call costs from the SDK arrive within seconds of each flush, and the SDK flushes every five seconds.
Can the agent tell me what a single run cost?
Yes, if the calls go through the SDK or ingest API. get_request_costs returns recent itemized calls with costUsd and occurredAt, so the agent sums the calls since the run started. There is no run-id filter on the tool yet, so it filters by time.

Related

Let your coding agent watch the meter.

Connect a provider key, point Claude Code or Cursor at the Argus MCP server, and ask what the last run cost.