Prerequisites: You need a Lava merchant account with a secret key. See Quickstart: Make Your First Request to get started.
Authentication
Lava supports two ways to authenticate gateway requests:Using Your Secret Key (Simplest)
Pass your secret key directly in theAuthorization header. Costs are charged to your merchant wallet — no token generation needed.
- cURL
- SDK
Forward Tokens
When you want to use your own provider API key, use a forward token: a base64-encoded JSON that bundles your Lava secret key with your provider key.Token Fields
Creating a Forward Token
- SDK
- TypeScript
- Python
- cURL
Constructing the Request URL
Lava routes requests by wrapping the provider’s API endpoint (e.g., OpenAI’s chat completions URL) as a query parameter using Lava’s forward endpoint:Provider Examples
The pattern is the same for every provider — only the URL, body format, and provider-specific headers change.- OpenAI
- Anthropic
- Google Gemini
- SDK
Provider-specific headers (like
anthropic-version) are passed through unchanged. The request body uses the provider’s native format — Lava doesn’t modify it.Connector Accounts
A provider can hold several connected accounts, for example a personal and a work Gmail. A request that names none uses the default account, the one connected first (markeddefault: true in connections). To use another, send its id in the x-lava-connector-account header; the ids are the connections that get_provider_details returns.
When a provider holds several accounts, or the request named one, the response carries x-lava-connector-account (the account’s id) and x-lava-connector-account-label (its URI-encoded name), so you can tell which account answered.
Streaming
Add"stream": true to your request body. Lava proxies SSE chunks in real-time without buffering — the response is identical to calling the provider directly. Usage and billing are recorded after the stream completes.
Error Handling
Provider error responses are forwarded unchanged — check your request body against the provider’s API docs if you see provider-level errors.
Troubleshooting
CORS errors in browser
CORS errors in browser
Lava blocks frontend requests to prevent token exposure. Always call Lava from your backend:
Frontend → Your Backend → Lava → AI Provider.Next Steps
Supported Providers
Full list of providers you can access with Lava AI Gateway
Rewrite Proxy
Send one request format to any provider with automatic translation