>
March 2026 · 6 min read
Most API bills are driven by a small number of high-traffic endpoints. The problem is you usually don't know which ones until the invoice arrives — and even then, cloud providers typically give you total spend by service, not by endpoint or route.
This guide covers how to get route-level spend visibility without adding complex observability infrastructure.
Aggregate spend numbers don't tell you what to fix. "We spent $800 on Twilio this month" is a fact. "We sent 101,000 SMS messages, 94% of which came from the onboarding drip sequence" is actionable.
Route-level cost tracking tells you which code paths are expensive. With that, you can make informed decisions: cache the expensive call, reduce frequency, batch requests, or switch to a cheaper tier for specific use cases.
The cleanest approach for HTTP APIs is to route traffic through a proxy that records each request alongside its cost. Your application code doesn't change — you just point it at the proxy instead of the API directly.
Trough does this as a single binary. Set up an upstream, define cost rules per route, and every request is logged with a cost attached.
curl -fsSL https://stockyard.dev/trough/install.sh | sh TROUGH_ADMIN_KEY=secret trough
Register your API as an upstream:
curl -s -X POST http://localhost:8790/api/upstreams \
-H 'Authorization: Bearer secret' \
-H 'Content-Type: application/json' \
-d '{"name":"sendgrid","base_url":"https://api.sendgrid.com"}'
# Returns upstream_id
Add cost rules for the routes you care about:
curl -s -X POST http://localhost:8790/api/upstreams/{id}/rules \
-H 'Authorization: Bearer secret' \
-d '{"path_pattern":"/v3/mail/send","cost_cents":1,"description":"per email"}'
curl -s -X POST http://localhost:8790/api/upstreams/{id}/rules \
-d '{"path_pattern":"*","cost_cents":0,"description":"other routes - no charge"}'
Point your application at the proxy URL instead of the API:
# Before: https://api.sendgrid.com/v3/mail/send
# After: http://localhost:8790/proxy/{upstream_id}/v3/mail/send
After a day of traffic, query the spend summary:
curl -s http://localhost:8790/api/spend \
-H 'Authorization: Bearer secret' | jq '.by_endpoint'
# [
# {"path":"/v3/mail/send","method":"POST","requests":8420,"cost_cents":8420},
# {"path":"/v3/stats","method":"GET","requests":144,"cost_cents":0}
# ]
This tells you exactly which routes are driving cost. In this example, 8,420 emails at $0.01 each — $84.20. The stats endpoint is free. Now you know where to look.
Trough Pro can fire a webhook when daily or monthly spend crosses a threshold. Set a limit and get notified before spend compounds:
curl -s -X POST http://localhost:8790/api/alerts \
-d '{"threshold_cents":5000,"period":"daily","webhook_url":"https://your-slack-webhook"}'
If today's spend exceeds $50, Trough fires the webhook. You catch runaway usage before it turns into a $2,000 monthly bill.
Trough tracks at the request level using rules you define. It doesn't do token-level cost tracking (relevant for LLMs), it doesn't integrate with cloud billing APIs, and it doesn't correlate costs with code paths beyond the route pattern. For those needs, you're looking at more specialized tooling.
For LLM-specific cost tracking across multiple providers with token-level granularity, model routing, and prompt management, Stockyard handles that as part of its LLM proxy stack.
Single binary. Free for one service. $2.99/mo for teams.