Skip to main content
This guide shows how to sign up and authenticate with Lava programmatically. By the end, you’ll have API credentials ready to use from code.

Prerequisites

  • Node.js 18+
  • A terminal

Install the SDK

npm install @lavapayments/nodejs

Authenticate

Lava.login() opens your browser, lets you sign up or log in, and returns your API credentials automatically.
import { Lava } from '@lavapayments/nodejs';

const credentials = await Lava.login();

console.log(credentials);
// {
//   secret_key: 'lava_sk_...',     // For merchant operations (meters, plans, checkout)
//   secret_key_id: 'sk_...',
//   wallet_key: 'lava_wk_...',     // For wallet operations (spend keys, wallet keys)
//   wallet_key_id: 'wk_...',
//   merchant_id: 'mer_...',
//   wallet_id: 'wa_...'
// }
If you don’t have an account yet, Lava.login() will take you through sign-up first. No separate registration step needed.

What happens under the hood

  1. A local HTTP server starts on a random port
  2. Your browser opens to Lava’s authorization page
  3. You sign up or log in and click “Authorize”
  4. Credentials flow back to your terminal
  5. The local server shuts down
The entire flow takes about 10 seconds.

Initialize the SDK

You get two keys back, each scoped to different operations:
// For merchant operations: meters, plans, checkout, connections, usage
const lava = new Lava(credentials.secret_key);

// For wallet operations: spend keys, wallet keys, models
const wallet = new Lava(credentials.wallet_key);
Store your credentials in environment variables or a secrets manager. You only need to run Lava.login() once.
# Save to your environment
export LAVA_SECRET_KEY="lava_sk_..."
export LAVA_WALLET_KEY="lava_wk_..."
Then initialize without hardcoding:
// Reads LAVA_SECRET_KEY from environment automatically
const lava = new Lava();

// Or pass explicitly
const wallet = new Lava(process.env.LAVA_WALLET_KEY);

Alternative: Exchange an Auth Code Directly

If you’re building a custom auth flow (for example, handling the browser callback yourself), use Lava.exchangeAuthCode() instead:
const credentials = await Lava.exchangeAuthCode({
  code: 'your_one_time_auth_code'
});
Auth codes expire after 60 seconds and can only be used once.

What’s Next?