Start here: Authenticate an Agent explains when to use MCP session auth versus the SDK login flow.
MCP flow
The Lava MCP server auto-manages a spend key for gateway access. When you calllogin, a spend key is provisioned automatically for the MCP session.
loginto authenticate — auto-provisions a spend key forpromptandcallaccesspromptorcallto route traffic, spending against the auto-provisioned keysearchto discover available providers before routing
SDK flow
If you are writing code directly, use the examples below with@lavapayments/nodejs.
How Spend Keys Work
A spend key is an OpenAI-compatible API key that routes through Lava’s gateway. Any tool that accepts an OpenAI API key can use a Lava spend key instead. You control which models are allowed, how much can be spent, and how fast requests can be made.Create a Spend Key
Spend key options
| Parameter | Options | Description |
|---|---|---|
allowed_providers | Array of provider names, or null for all | Restrict which providers can be used |
allowed_models | Array of model IDs, or null for all | Restrict which models can be used |
request_shape | openai, anthropic | Request format (default: openai) |
spend_limit | { amount, cycle } | Max spend per cycle (daily, weekly, monthly, total) |
request_limit | { count, cycle } | Max requests per cycle |
rate_limit | { rpm, burst? } | Requests per minute, with optional burst allowance |
expires_at | ISO 8601 date, or null | Auto-expire the key after a date |
status | active, paused | Pause a key without revoking it |
Use a Spend Key
Spend keys work anywhere an OpenAI API key is accepted. Point the tool at Lava’s base URL and use the spend key as the API key.With the OpenAI SDK
With the Anthropic SDK
For Anthropic-shaped requests, create the key withrequest_shape: 'anthropic':
Update a Spend Key
Change restrictions on an existing key without rotating the key itself:Rotate a Key
Generate a new key value for the same spend key. The old key stops working immediately:Monitor Spend
Check current spend and usage for a key:Revoke a Key
Permanently disable a spend key:What’s Next?
Spend Key Setup Guides
Step-by-step setup for Cursor, Claude Code, Vercel AI SDK, and more
AI Spend Overview
How AI Spend works, dashboard features, and team management
Route Traffic
Forward requests through the gateway with usage tracking
SDK Reference
Full spend key API documentation