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

export const providerCountLabel = "185+";

Lava Gateway is a transparent proxy that sits between your application and AI providers. It gives you access to {providerCountLabel} 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](/get-started/quickstart-track) quickstart for a step-by-step tutorial. This page explains how the gateway works under the hood.
</Tip>

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

### 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](/gateway/supported-providers) — 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 {providerCountLabel} 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](/get-started/quickstart-charge) for the monetization setup flow.

## Next Steps

<CardGroup cols={2}>
  <Card title="Quickstart: Track Usage" icon="rocket" href="/get-started/quickstart-track">
    Route your first AI request through Lava in under 5 minutes
  </Card>

  <Card title="Forward Proxy Guide" icon="arrow-right" href="/gateway/forward-proxy">
    Forward tokens, URL construction, error handling, and provider examples
  </Card>

  <Card title="Supported Providers" icon="robot" href="/gateway/supported-providers">
    Full list of {providerCountLabel} AI providers with base URLs and capabilities
  </Card>

  <Card title="Gateway vs Post-Request" icon="scale-balanced" href="/monetize/gateway-vs-post-request">
    When to use the gateway vs reporting usage after the fact
  </Card>
</CardGroup>
