> ## Documentation Index
> Fetch the complete documentation index at: https://lava.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How Lava Gateway Works

Lava Gateway is a transparent proxy that sits between your application and AI providers. It gives you access to 285+ providers through a single integration with zero markup — you pay exactly what providers charge.

> [!TIP]
>
> **New to Lava?** Start with the [Track Your First Request](https://lava.so/docs/get-started/quickstart-track.md) quickstart for a step-by-step tutorial. This page explains how the gateway works under the hood.

## 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.

```mermaid theme={null}
graph LR
    A[Your Application] -->|API Request| B[Lava Proxy]
    B -->|Forward Request| C[AI Provider]
    C -->|Response| B
    B -->|Response + Usage Data| A
    B -.->|Record Usage| D[(Database)]
    B -.->|Update Balance| E[Customer]
```

> [!NOTE]
>
> Lava adds **less than 20ms of latency** to your AI requests through edge computing and Redis caching.

### What Happens on Every Request

1. **Authorize** — Lava validates your secret key or forward token and checks account balance
2. **Route** — Lava strips its own auth headers and forwards the request to the target provider
3. **Respond** — The provider processes the request and returns a response. For streaming requests, Lava passes SSE events through in real time
4. **Log** — After the response is returned, Lava asynchronously records token counts, costs, provider, model, and any custom metadata
5. **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](https://lava.so/docs/gateway/supported-providers.md) — 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 285+ 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

Alternatively, use **unmanaged** (bring your own key): supply your own provider API key in the forward token; Lava still meters usage and can charge a service fee. Both managed and unmanaged work through the same proxy interface.

## 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** — Pass your secret key directly in the `Authorization` header to route requests through Lava. You get usage tracking, cost logging, and provider switching. Costs are charged to your own Lava wallet. No customer, meter, or token generation needed.

**Charge customers** — Generate forward tokens that include a customer's `customer_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](https://lava.so/docs/get-started/quickstart-charge.md) for the monetization setup flow.

## Next Steps

> [card] [Quickstart: Track Usage](https://lava.so/docs/get-started/quickstart-track.md)
>
> Route your first AI request through Lava in under 5 minutes

> [card] [Forward Proxy Guide](https://lava.so/docs/gateway/forward-proxy.md)
>
> Forward tokens, URL construction, error handling, and provider examples

> [card] [Supported Providers](https://lava.so/docs/gateway/supported-providers.md)
>
> Full list of 285+ AI providers with base URLs and capabilities

> [card] [Gateway vs Post-Request](https://lava.so/docs/monetize/gateway-vs-post-request.md)
>
> When to use the gateway vs reporting usage after the fact


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.