Start by choosing an auth path: Authenticate an Agent explains the difference between the MCP flow (
login inside the MCP) and the SDK flow (Lava.login() in your own code).Managed vs unmanaged: You can use managed keys (Lava pays the provider; you pay Lava) or unmanaged (bring your own key — you supply the provider API key; Lava still meters usage and may charge a service fee). Both use the same forward token; set the optional
provider_key in the token for unmanaged.MCP flow
If your agent is using the Lava MCP server, do not reimplement this in code. The MCP handles auth and routing automatically:loginto authenticate (auto-provisions a spend key for gateway access)promptto send chat completions to any AI model — all models use OpenAI format regardless of providercallto execute any API call through the gateway — auth is generated automaticallysearchto discover available providers and get ready-to-use request examplesget_provider_docsto fetch upstream API documentation when you need more detail
No manual forward token generation is needed.
prompt uses an auto-provisioned spend key, and call generates forward tokens internally.Provider fallbacks with prompt
The prompt tool accepts an optional fallbacks array. If the primary model returns a 5xx error, a 429, or a network failure, Lava retries each fallback in order until one succeeds:
{ url, model } object — url is a scheme-less provider URL and model is the model name to use at that provider. Fallbacks can cross providers (e.g. Claude primary → GPT fallback). Lava translates the request body into each provider’s format automatically.
SDK flow
If you are writing application code yourself, use the examples below with@lavapayments/nodejs.
How It Works
Lava’s gateway sits between your code and AI providers. You send requests to Lava’s forward URL instead of the provider’s URL directly. Lava proxies the request, tracks usage, and returns the provider’s response unchanged. The request body stays identical to what the provider expects. You only change the base URL and auth header.Make a Request
The simplest way to use the gateway is to pass your secret key directly in theAuthorization header. Costs are charged to your merchant wallet — no token generation needed.
Use the SDK’s pre-configured provider URLs, which point to Lava’s gateway with the correct upstream URL already set.
- OpenAI
- Anthropic
- Google (OpenAI-compatible)
Available Providers
The SDK includes pre-configured URLs for 25+ providers:Discover Available Models
List all models available through the gateway:Check Your Usage
After making requests, query your usage data:What’s Next?
Bill Your Customers
Add meters, plans, and checkout to charge for usage
Manage AI Spend
Create scoped API keys with spend and rate limits
Supported Providers
See all 25+ AI providers available through the gateway
Forward Proxy Details
Streaming, error handling, and advanced configuration