- MCP flow: your host already runs the Lava MCP server, and the agent should authenticate the current MCP session with
lava_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:lava_loginto launch the existing Lava browser auth flowlava_generate_forward_tokenwhen you need proxy auth for/v1/forwardor/v1/rewritelava_chat_completions,lava_messages,lava_forward, orlava_rewriteto route live traffic through Lava
lava_login loads the active secret key, creating one if needed. It also returns a usable wallet key if one is already available or creates the first wallet key if none exists.
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 primary SDK credential.Lava.login() also returns a usable wallet key if one is already available or creates the first wallet key if none exists:
Alternative: Exchange an Auth Code Directly
If you’re building a custom auth flow (for example, handling the browser callback yourself), useLava.exchangeAuthCode() instead: