Skip to main content
Spend keys are scoped API keys that work as drop-in replacements for provider API keys. Use them to give agents, team members, or developer tools access to AI models with built-in spend limits, model restrictions, and rate controls.
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 call login, a spend key is provisioned automatically for the MCP session.
  • login to authenticate — auto-provisions a spend key for prompt and call access
  • prompt or call to route traffic, spending against the auto-provisioned key
  • search to discover available providers before routing
To create spend keys with custom limits, model restrictions, or expiration — use the SDK code below.

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

The full key value is only returned when you create or rotate a spend key. Store it securely right away.

Spend key options

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 with request_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