Installation
Install the Lava Node.js SDK using npm:Initialize the Client
Import and initialize the Lava client with your secret key:Your First Request: Complete Flow
Here’s a complete example showing the full integration workflow from checkout to AI request:What’s Happening Here?
- Create checkout session - Generate a session for wallet creation and payment collection
- User completes checkout - Frontend displays Lava’s checkout UI (using
@lavapayments/checkout) - Retrieve connection - Get the connection details after checkout completes
- Generate forward token - Create authentication token combining secret key, connection, and product
- Make AI request - Call AI provider through Lava’s transparent proxy with automatic billing
- Check balance - Verify wallet balance and usage
The SDK automatically detects test vs production mode based on your secret key prefix:
aks_test_*→ Routes to sandbox (sandbox-api.lavapayments.com)- Other prefixes → Routes to production (
api.lavapayments.com)
Environment Variables
Set up these environment variables for the example above:Next Steps
Authentication
Learn about forward tokens and authentication patterns
Checkout Sessions
Complete API reference for wallet onboarding
Provider Integration
See examples for OpenAI, Anthropic, Google, and more
Usage Tracking
Retrieve analytics and usage statistics
How the SDK Works
The SDK provides a clean TypeScript interface to Lava’s REST API with five main resource classes:| Resource | Purpose | Key Methods |
|---|---|---|
checkoutSessions | Wallet onboarding and payment collection | create(), list(), retrieve() |
connections | Manage wallet-merchant relationships | list(), retrieve(), delete() |
requests | Track individual AI API calls | list(), create(), retrieve() |
usage | Retrieve aggregated statistics | retrieve() |
subscriptions | Manage recurring billing plans | listConfigs(), createConfig(), listActiveSubscriptions() |
generateForwardToken()- Create authentication tokens for AI requestsproviders.*- Pre-configured URLs for 27 AI providers
Support
Need help getting started?- Documentation: Explore the complete SDK reference in the navigation sidebar
- Dashboard: View requests and usage at lavapayments.com/dashboard
- Support: Contact [email protected]