Assistant Billing

Getting Started

Set up your AI project with billing in 4 steps.

Step 1: Create a Project

  1. Sign up at the Dashboard and create a new project
  2. Note your gateway URL (gateway.assistant-billing.dev) or configure a custom domain
  3. Go to Settings > Platform and generate a platform key (sk_pj_*)
  4. Go to Providers and add at least one AI provider (OpenAI, Anthropic, Google, etc.)
# Save your platform key
ASSISTANT_BILLING_PLATFORM_API_KEY=sk_pj_live_abc123

Step 2: Install the SDK

npm install @assistant-billing/sdk

Step 3: Create Sessions and Proxy Requests

After authenticating a user with your own auth system, use BillingClient to create a session and GatewayClient to make AI requests.

import { BillingClient, GatewayClient } from "@assistant-billing/sdk"
 
// Server-side: create a session for your customer
const billing = new BillingClient({
  platformKey: process.env.ASSISTANT_BILLING_PLATFORM_API_KEY,
  workspaceId: "ws_team_123",
  userId: "user_456",
})
 
const { token, expires_at } = await billing.sessions.create()
// → { token: "sess_eyJhbG...", expires_at: "2026-03-15T00:00:00Z" }
 
// Make an AI request on behalf of the customer
const gateway = new GatewayClient({
  apiKey: "sk_ab_live_xyz789",
  baseURL: "https://gateway.assistant-billing.dev",
})
 
const response = await gateway.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello!" }],
})

Constructor Options

BillingClient

OptionTypeDefaultDescription
platformKeystringASSISTANT_BILLING_PLATFORM_API_KEY envPlatform key (sk_pj_*)
workspaceIdstring?—Customer workspace identifier
userIdstring?—User performing the action
baseURLstring?https://api.assistant-billing.dev/v1/platformPlatform API URL
getToken() => Promise<string>?—Session token callback (client-side auth)
timeoutnumber?30000Request timeout in ms

GatewayClient

OptionTypeDefaultDescription
apiKeystringASSISTANT_BILLING_GATEWAY_API_KEY envGateway API key (sk_ab_*)
baseURLstring?https://gateway.assistant-billing.devGateway URL
appTitlestring?—App name (sent as X-Title header)
appUrlstring?—App URL (sent as HTTP-Referer header)
defaultHeadersRecord<string, string>?—Extra headers for every request
timeoutnumber?60000Request timeout in ms

Step 4: Add Billing UI

Install the React component library to build a customer-facing billing UI.

npm install @assistant-billing/react
import { GatewayClient } from "@assistant-billing/react"
import { BillingClient } from "@assistant-billing/sdk"
 
const client = new BillingClient({
  baseURL: "https://api.assistant-billing.dev/v1/platform",
  getToken: () => fetchSessionToken(), // return the token from Step 3
})
 
export default function BillingPage() {
  return <GatewayClient client={client} />
}

The GatewayClient component renders wallet balance, API key management, and provider key management out of the box.

Next Steps

  • How It Works — Architecture, routing, and billing flows
  • SDK — Full BillingClient, GatewayClient, and AdminBillingClient reference
  • Stripe Setup — Connect Stripe for customer payments
  • API Reference — Platform API and Client API endpoints