TokenGuard

Go reverse proxy · financial firewall

TokenGuard

Sit between your app and LLM providers. Reserve budget, trip agent loops, block unpriced models — then forward. Or return before money leaves.

What it catches

Four ways LLM spend goes blind — and how TokenGuard stops them.

One proxy. Fail closed. Money as micro-USD integers. No guessing model prices.

  1. 01

    Runaway spend

    LLM calls look cheap one-by-one, but an app or agent can burn hundreds of dollars before anyone notices.

    When: Retries, long contexts, high max_tokens, traffic spikes, or a bug that loops the API.

    How: Before forwarding, TokenGuard estimates cost from the pricing catalog, reserves micro-USD against the user budget, and returns 402 if there isn’t enough. After the response it settles actual cost (or releases the reservation on failure).

    402budget
  2. 02

    Agent loops

    Autonomous agents send the same prompt or tool payload over and over — and each attempt still costs tokens.

    When: Stuck planners, tool failures that retry the same step, identical session traffic past a threshold.

    How: With X-TokenGuard-Session-ID, it hashes session + semantic payload in Redis. After the threshold (default 3), it returns 409 and does not call the provider.

    409loop
  3. 03

    Blind multi-provider cost

    Teams use OpenAI + OpenRouter + Anthropic with separate dashboards and no single “who spent what” view.

    When: Multi-model apps, agencies, or route-this-request-to-provider-X setups.

    How: One proxy host, X-TokenGuard-Provider routing, and one Turso ledger of usage events (tokens, cost, status) per TokenGuard user — across providers.

    ledgerunified
  4. 04

    Unknown / unpriced models

    A new or mistyped model ID gets billed upstream with no local cost estimate, so the firewall can’t reserve safely.

    When: Model renames, OpenRouter IDs you never added, or deploy without updating prices.

    How: Fail-closed: if the model isn’t in the pricing catalog, the request gets 400 pricing_not_configured and never hits the provider. Operators sync OpenRouter or upsert rates.

    400blocked

Under the hood

One request path. Fail closed.

Budget reserve in Turso, loop counters in Upstash Redis, live pricing from OpenRouter sync into the catalog. Management dashboard stays on the Go binary — this site tells the story.

  • Micro-USD integersno float ledger math.
  • Strip X-TokenGuard-*before upstream; provider auth passes through.
  • Never invent pricesunknown models get 400, not a guess.
  • 503 when stores are downin guarded mode — never soft-fail open.

Put a firewall in front of your tokens.

Open source Go proxy. Docs and dashboard ship with the binary; operators provision users and sync pricing when guard is enabled.