Integrations
Gateway URL (any language)
Section titled “Gateway URL (any language)”curl -H "X-Spendctl-Agent: researcher" "http://127.0.0.1:8402/https://api.example.com/report?id=42"Or send the target in X-Spendctl-Target and request http://127.0.0.1:8402/. spendctl adds x-spendctl-attempt, x-spendctl-decision and x-spendctl-amount to responses.
wrapFetch (TypeScript / JavaScript)
Section titled “wrapFetch (TypeScript / JavaScript)”import { wrapFetch, readRefusal, AgentClient } from "@spendctl/client";
const pay = wrapFetch({ agent: "researcher" });const res = await pay("https://api.example.com/report");const refusal = await readRefusal(res); // undefined when paid or freeconst budget = await new AgentClient({ agent: "researcher" }).budget();claude mcp add spendctl -e SPENDCTL_AGENT=researcher -- npx spendctl mcpTools: pay (fetch a URL that may cost money), check_budget, list_receipts. The MCP server is a thin client: no keys, no approvals.
HTTP_PROXY
Section titled “HTTP_PROXY”spendctl run --agent researcher -- python agent.pySets HTTP_PROXY (with the agent name in the proxy credentials). Plain http:// requests are governed; https:// is tunnelled without inspection, so paid HTTPS APIs should use the gateway URL.
Framework examples
Section titled “Framework examples”- Claude Agent SDK — pass the MCP server through
mcpServers. - OpenAI Agents SDK — a function tool over
wrapFetch. - LangGraph —
tool()+createReactAgentoverwrapFetch.
Runnable examples for these three are planned for the public client SDK repository, github.com/miraistudio/spendctl-sdk.
Agent → agent chains
Section titled “Agent → agent chains”spendctl reads and forwards W3C baggage entries spend.root, spend.parent, spend.depth. If your agent is itself a paid service, propagate incoming baggage to outgoing calls (OpenTelemetry does this for you). spendctl trace <attempt-id> prints the tree.