When you need to bill customers, apply metering, or use your own provider keys, use a forward token — a base64-encoded JSON that bundles your secret key with billing parameters.
Any combination can include provider_key to use your own provider credentials (BYOK) instead of Lava’s managed keys.disable_billing is only meaningful together with customer_id and meter_slug — it preserves full customer context while redirecting charges to your merchant wallet. Use it for free trials, testing, or promotional requests. See Meter-Only Mode & Disable Billing for details.
To bill a customer’s wallet, include their customer_id and your pricing meter_slug in the token:
SDK
TypeScript
Python
cURL
import { Lava } from '@lavapayments/nodejs';const lava = new Lava();const forwardToken = lava.generateForwardToken({ customer_id: 'conn_xyz789', // optional — charges this customer's plan meter_slug: 'my-meter', // optional — prices usage with this meter provider_key: 'sk-your-key', // optional — uses your own provider key (BYOK) disable_billing: false, // optional — when true, tracks usage without charging});
const tokenData = { secret_key: 'aks_live_abc123...', // your Lava secret key customer_id: 'conn_xyz789...', // optional — charges this customer's plan meter_slug: 'my-meter', // optional — prices usage with this meter provider_key: null, // optional — uses your own provider key (BYOK) disable_billing: false, // optional — when true, tracks usage without charging};const forwardToken = btoa(JSON.stringify(tokenData));
import base64, jsontoken_data = { "secret_key": "aks_live_abc123...", # your Lava secret key "customer_id": "conn_xyz789...", # optional — charges this customer's plan "meter_slug": "my-meter", # optional — prices usage with this meter "provider_key": None, # optional — uses your own provider key (BYOK) "disable_billing": False, # optional — when True, tracks usage without charging}forward_token = base64.b64encode(json.dumps(token_data).encode()).decode()
# secret_key: required. All other fields are optional.# customer_id: charges this customer's plan. meter_slug: prices usage with this meter.# provider_key: uses your own provider key (BYOK). disable_billing: tracks without charging.FORWARD_TOKEN=$(echo -n '{"secret_key":"aks_live_abc123...","customer_id":"conn_xyz789...","meter_slug":"my-meter","provider_key":null,"disable_billing":false}' | base64)
Provider-specific headers (like anthropic-version) are passed through unchanged. The request body uses the provider’s native format — Lava doesn’t modify it.
Add "stream": true to your request body. Lava proxies SSE chunks in real-time without buffering — the response is identical to calling the provider directly. Usage and billing are recorded after the stream completes.