pi Cost Tracking: No Native Hook, So Cost Comes From the Proxy
Just want the answer? pi has no cost hook, so you change where the model traffic goes. Install the tool-call extension, then add a provider for the cost X-ray:
curl -sf https://agenticcontrolplane.com/install.sh | bash
# ~/.pi/agent/models.json
{
"providers": {
"acp": {
"baseUrl": "https://api.agenticcontrolplane.com/v1",
"api": "openai-completions",
"apiKey": "!cat ~/.acp/credentials",
"compat": { "supportsDeveloperRole": false, "supportsReasoningEffort": false },
"models": [{ "id": "gemini-3.5-flash" }]
}
}
}
# then: pi --model acp/gemini-3.5-flash
pi is small on purpose: four tools, no permission system, and you extend it yourself. That also means there is nothing to hook for cost. The two events an extension gets, tool_call and tool_result, fire on tools. They see arguments and results. They never see a token count or a model’s usage fields. pi’s core loop talks to the model provider directly, outside the extension pipeline, so an extension can’t intercept a model call the way it intercepts a tool call.
That puts pi closer to Codex CLI than to Hermes. Hermes has an in-process hook on every model request. With pi and Codex, the only way to see what a call cost is to change where it goes.
What the extension covers
The ACP extension for pi checks every tool call. tool_call fires before each bash, read, write, edit or custom tool call and can deny it or rewrite it. tool_result fires after and can redact or rewrite what the model reads back. pi has no MCP layer and no second way to dispatch a tool, so that pair sees everything the agent does.
It doesn’t see what the model calls cost. So the extension gets you allow, ask, deny and redact on tool calls, plus an audit trail, and nothing about spend. With no UI (pi -p or piped input), an ask is denied on the spot. A held call otherwise waits on the console or the approval email. You approve it there, then ask the agent to retry.
The config
pi can send model calls through the ACP proxy the way any OpenAI-compatible client can. Add a provider entry in ~/.pi/agent/models.json:
{
"providers": {
"acp": {
"baseUrl": "https://api.agenticcontrolplane.com/v1",
"api": "openai-completions",
"apiKey": "!cat ~/.acp/credentials",
"compat": { "supportsDeveloperRole": false, "supportsReasoningEffort": false },
"models": [{ "id": "gemini-3.5-flash" }]
}
}
}
Then start pi against it:
pi --model acp/gemini-3.5-flash
The proxy reads the usage fields on the way through and prices the call. The call shows up as a row next to the tool-audit rows for the same session, in the console.
What you get once it’s routed
Calls made with --model acp/... show the same cost picture described in turning on the cost X-ray:
- Per-call cost. Tokens in and out, priced in dollars, rolled up per run.
- Prompt-cache hit rate. A cold cache can double a session’s cost without anyone noticing.
- Loop versus leaf. How much of the spend is the agent re-reading its own context to pick the next step, and how much is doing the work.
None of this shows up while pi still points at its default provider. The extension and the provider entry are independent. You can run the extension alone (tool-call checks, no cost), the provider alone (cost, no tool-call checks), or both. Both gets you one console with everything.
One thing to know: with this entry, pi’s model calls go through ACP’s model broker instead of your own provider login. Check the pi integration guide for how those calls are billed before you point a long run at it.
Troubleshooting
I added the provider but see nothing in the console. Check that you started pi with --model acp/<id>. Adding the block to models.json makes the option available. It doesn’t change pi’s default model.
"apiKey": "!cat ~/.acp/credentials" fails. That syntax runs a shell command to read the file at launch. Confirm the file exists and holds a workspace key (gsk_...), which the install script writes when you sign in. A missing or malformed file means pi can’t authenticate the request. It doesn’t mean the proxy is down.
Tool-call rows show up but cost rows don’t, or the other way round. That’s expected if only one of the two pieces is installed.
Frequently asked questions
Does pi track cost natively?
No. pi gives extensions two typed events, tool_call and tool_result, and neither carries token usage or pricing. There is no /usage command, no dollar figure in the status line and no cost metric.
If pi has no cost hook, how does ACP show cost for it?
Not through the extension. The ACP pi extension checks tool calls and writes the audit trail, but it never sees a model call, so it can’t price one. Cost is a second step: add a provider entry in ~/.pi/agent/models.json whose baseUrl points at the ACP proxy. Then pi’s model traffic passes through a point that can read token usage off the response.
Does routing model calls through the proxy change what pi does?
The proxy forwards the request and returns the response while reading the usage fields to price the call. You pick it by model id (pi --model acp/gemini-3.5-flash), so it is a choice you make per run. It is not a silent redirect.
Can I get both tool-call checks and cost from pi in one setup?
Yes, but they are two separate pieces. The extension covers tool calls. The models.json provider entry covers the model calls you route through the proxy. Installing one does not install the other.
Where to read more
- pi’s control model, explained: what the extension covers, and where its two events end
- Prime Agent cost tracking: the same proxy pattern on pi’s hard fork
- Hermes Agent cost tracking: the in-process hook, for comparison
- Claude Code cost tracking reference and Codex CLI cost tracking
Running pi? One command adds a hook. Each tool call it sees is recorded, and a force-push, destructive SQL or curl | sh is blocked until you approve it on the console or from the email.
curl -fsSL https://agenticcontrolplane.com/install.sh | bash
irm https://agenticcontrolplane.com/install.ps1 | iex
What the installer writes · pi guide · free up to 5 agents