- MCP flow: your host already runs the Lava MCP server, and the agent should authenticate the current MCP session with
login - SDK flow: you are writing Node.js agent code and want to call
Lava.login()directly
Prerequisites
- Node.js 18+
- A terminal
MCP flow
Use this when the agent is running inside Claude Code, Claude Desktop, Cursor, or another MCP-capable host with the Lava MCP server configured.1. Install the MCP server
- Claude Code
- Codex
- Manual JSON
2. Authenticate the MCP session
Ask the agent to call:loginto authenticate via the Lava browser login flowpromptto send chat completions to any AI model (all models use OpenAI format)callto execute any API call through the gateway (non-LLM APIs or native provider format)searchto find available API providers by natural language queryget_provider_docsto fetch upstream API documentation for a provider
login loads your merchant credentials and auto-provisions a spend key for gateway access. No manual token generation needed.
Use the MCP flow if your goal is to operate Lava from an agent host. Do not import the SDK just to get credentials when the MCP is already available.
SDK flow
Use this when you are writing application or CLI code yourself and want to authenticate from Node.js.1. Install the SDK
2. Authenticate
Lava.login() opens your browser, lets you sign up or log in, and returns your API credentials automatically.
If you don’t have an account yet,
Lava.login() will take you through sign-up first. No separate registration step needed.3. What happens under the hood
- A local HTTP server starts on a random port
- Your browser opens to Lava’s authorization page
- You sign up or log in and click “Authorize”
- Credentials flow back to your terminal
- The local server shuts down
Initialize the SDK
Use the secret key as your SDK credential:Alternative: Exchange an Auth Code Directly
If you’re building a custom auth flow (for example, handling the browser callback yourself), useLava.exchangeAuthCode() instead:
What’s Next?
Route Traffic
Route live traffic after choosing MCP or SDK flow
Bill Your Customers
Set up usage-based pricing and checkout
Manage AI Spend
Create scoped API keys with spend limits
SDK Reference
Full Node.js SDK documentation