Architecture
Lava operates as a transparent proxy between your application and AI providers. It sits in the middle of API requests, adding usage tracking and monetization without changing the developer experience.Lava adds less than 20ms of latency to your AI requests through edge computing and Redis caching.
What Happens on Every Request
- Authorize — Lava validates the forward token and checks account balance
- Route — Lava strips its own auth headers and forwards the request to the target provider
- Respond — The provider processes the request and returns a response. For streaming requests, Lava passes SSE events through in real time
- Log — After the response is returned, Lava asynchronously records token counts, costs, provider, model, and any custom metadata
- Bill — Lava deducts usage costs from the relevant account balances
Why Use the Gateway
Fund your Lava account and start making requests to any supported provider — no need to sign up for OpenAI, Anthropic, Google, or any others:- Zero markup: you pay exactly what providers charge, at cost
- One integration: swap the provider URL to switch between 30+ providers without managing separate accounts or API keys
- Automatic tracking: every request is logged with token counts, costs, and model metadata
- Monetize integration: charge customers per-request with balance checks, usage-based billing, and autopay — no extra infrastructure needed
Two Modes: Track and Monetize
The gateway supports two levels of integration depending on whether you’re tracking your own usage or billing customers. Track your own usage — Use your self forward token (found in Gateway > Secrets) to route requests through Lava. You get usage tracking, cost logging, and provider switching. Costs are charged to your own Lava wallet. Charge customers — Generate forward tokens that include a customer’sconnection_id and a meter_slug. Lava automatically checks the customer’s balance before forwarding, deducts usage costs after the response, applies your meter’s pricing, and triggers autopay if their balance runs low.
See Quickstart: Charge Customers for the monetization setup flow.
Next Steps
Quickstart: Track Usage
Route your first AI request through Lava in under 5 minutes
Forward Proxy Guide
Forward tokens, URL construction, error handling, and provider examples
Supported Providers
Full list of 30+ AI providers with base URLs and capabilities
Gateway vs Post-Request
When to use the gateway vs reporting usage after the fact