Docs · Guide

Token usage and cost per agent

Every request through magpie is recorded: the agent, the model asked for and the one that answered, the account, the tokens, an estimated cost, the time and the status. The Usage page sums them per agent, model and subscription account, and the Requests page lists each one. With Claude Code, Codex and the rest, you see where the money goes without another tracking tool.

On the command line

The same numbers are on the command line, the last 30 days by default:

Terminal
magpie usage                      # the last 30 days: tokens and cost per agent, model and account
magpie usage today                # or 7d, 30d, all
magpie usage --last 24h           # a window ending now (90m, 1.5 days…)
magpie usage --csv 7d             # every request as CSV
magpie usage --csv --account  30d

--last and --days count a window ending now, not from a midnight. Each CSV row is one request: the model asked for, sent and served, tokens, cost, time, status and account.

What each session cost

The Sessions page and magpie sessions list the latest Claude Code, Codex, OpenCode, Pi and other agents' sessions with what each cost, filtered by model or project folder:

Terminal
magpie sessions                   # the latest sessions, with what each cost
magpie sessions --days 7          # what every session spent, day by day
magpie sessions --model  --folder  --json
magpie sessions read              # which agents' history magpie may read

An agent's own session files are read only once you allow that agent; none are read until then. Once allowed, calls that didn't go through magpie (Claude Code signed in to claude.ai directly, say) reach Usage from those files too.

Where a price comes from

A call is counted at its effective price: what you set for that provider and model if you did, otherwise what the provider's own catalogue lists, otherwise what models.dev lists for the model's maker.

A relay that resells at a discount or a multiplier isn't charging the maker's price. Say what it actually charges, and Usage and the session totals use that:

Terminal
magpie model price relay-a/gpt-5.5                        # what it is counted at, and where that came from
magpie model price relay-a/gpt-5.5 0.12,0.60,0.01,0.15   # input,output,cache read,cache write
magpie model price relay-a/gpt-5.5 --reset
magpie model prices                                       # every model you priced

Calls with no price

A call with no price is left out of a total's cost, never counted as free. The Usage page says how many calls it couldn't price beside the sum (3 unpriced, say), and magpie usage says so after its totals. magpie doesn't guess a variant's price from a similar name: -auto, -max and -fast can each cost differently, so give it one with magpie model price.

Claude Code's status line

magpie statusline prints one line for Claude Code's status line: the model the session's latest turn went to, then each subscription account's windows, with * on the one that answered last. Turn it on from Claude Code's row on the Agents page, or:

Terminal
magpie claude statusline on
# → claude/claude-opus-5-5 | claude a@example.com* 5h 62% 7d 41% | claude B 5h 8% 7d 30%

A status line of your own (claude-hud, a script) is never written over. It works however Claude Code signs in to the gateway.

From other programs

The Usage page's summary and request list are served by the gateway too, read-only and without conversation text:

Terminal
GET /v1/magpie/usage
GET /v1/magpie/usage/requests

From another computer they need a gateway key. A key held to a budget, models or accounts is refused the summary and gets only its own requests in the list.

FAQ

How do I see what Claude Code costs?

With Claude Code going through magpie, every request is recorded with its tokens and an estimated cost. See it per agent on the Usage page or with magpie usage, and per session on the Sessions page or with magpie sessions.

My relay charges less than list price. How do I get the cost right?

Set what it charges with magpie model price / input,output,cache read,cache write (USD per million tokens), and Usage and the session totals use it.

Can I export every request?

Yes. magpie usage --csv exports each request with its models, tokens, cost, time, status and account; --account limits it to one account.

Why do some calls have no cost?

A call with no known price is left out of the total, and the Usage page says how many are unpriced. Give the model a price and they are counted.

Related: Quota left on every subscription and key, Round robin and failover across accounts, keys and providers. Hit an error? See Fixing common errors: 401, 429, 502, 504 and more, or ask on Discord.