Agents are burning tokens you cannot attribute. One Cursor session, three models, two retries, an escalation you never asked for — and the invoice is still one line item with no project name on it.
We open-sourced ModelSpend for that.
Landing: /modelspend · Repo: github.com/rmencke2/modelspend · Release: v0.3.0b1
Two jobs
- Know where the money goes. Tag any call with
project,agent, optionalrun_id, and up to eight labels — SDK args, CLI flags, env, or OpenAI-compatible headers (X-ModelSpend-Project,-Agent,-Run,-Labels). Report tokens by type (input, cached, output, reasoning), cost, and overhead from failed calls, retries, and escalations. Pin a model if you only want measurement. - Spend less. Route each task to the lowest-cost model expected to fit, inside a USD or token budget. Hard budgets refuse before the provider call (HTTP 429). Soft budgets only warn.
Your keys for OpenAI, Anthropic, Google, and xAI. No prompts stored. Apache-2.0. Local OpenAI-compatible server — point the agent at model="auto".
Why this sits next to Influzer
Influzer is the MCP directory: search, handshake, paste, allowlist. That stack answers which tool server the agent may call.
ModelSpend answers the next bill: which model paid for the reasoning, under which project, and whether the next call is allowed to leave the machine. Same team. Different socket. Both refuse to pretend a demo is a control plane.
Drop it in front of any OpenAI client
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8787/v1", api_key="unused-unless-token-set")
r = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Classify: refund me as billing|bug|other"}],
extra_body={
"modelspend": {
"providers": ["anthropic", "openai"],
"max_budget_usd": 0.01,
"profile": "economy",
}
},
)
print(r.choices[0].message.content, r.model_extra["modelspend"]["explanation"])
Tag from the CLI the same way:
modelspend route "Classify: I was charged twice" \ --providers anthropic --project billing --agent invoice-bot modelspend report --by project,agent,model --since 7d modelspend budget set --project shop --period monthly --usd 50
Five minutes with no keys
Clone, install editable, print the policy, preview on the synthetic catalog (no call, no spend):
git clone https://github.com/rmencke2/modelspend.git cd modelspend python3 -m venv .venv && source .venv/bin/activate python -m pip install --upgrade pip && pip install -e . modelspend policy modelspend preview "Classify this ticket" --catalog synthetic --assume-keys
Full setup, pricing sync, and limitations live in the repo README and on /modelspend.
Honest status (beta)
ModelSpend does not guarantee the cheapest successful model. “Suitable” is an estimate from catalog tier priors and, as you run evaluations, measured evidence.
- Only Anthropic prices ship until you sync other providers’ catalogs. Tokens are always exact (provider-reported). Cost is
unknownwhen a model has no price. - Verified live on Anthropic and (partially) OpenAI for routing, token counts, and budgets. Gemini and xAI adapters are implemented; live reports welcome.
- Only calls that go through ModelSpend are counted. Traffic that bypasses it is invisible — which is the point of putting it in the path.
We would rather ship that disclaimer than a fake “always cheapest” badge.
Quick answers
Do I have to route to use it?
No. Pin a model (--model provider/id or a non-auto model on the server) and ModelSpend only measures.
Where do budgets apply?
Before every provider call — including retries, failovers, escalations, classifier/judge calls, and streams. Hard = refuse with 429. Soft = warn.
Is this an MCP server?
No. It is a local cost router and usage ledger in front of LLM providers. Influzer MCP Discovery stays the read-only catalog search path.
Windows / Gemini / xAI?
Open an issue. That feedback is the product right now.
Related
Final thought
Directories tell you which tool server to allowlist. ModelSpend tells you which model paid for the turn — and whether the next turn is allowed to leave.
Tag the project. Cap the budget. Route model="auto". Star the repo if agents should know their bill.
Start at /modelspend. Clone github.com/rmencke2/modelspend. Keep writes — and spend — on a list you can name.
One clear email each Thursday
Actionable frameworks on AI execution, agents, and MCP. Join 4,200+ builders.
Leave a comment
Be the first to share your thoughts.