FleeexClient
Constructor options and methods of the FleeexClient.
The main entry point. Construct one per (app, user):
import { FleeexClient } from "@fleeex/sdk";
const client = new FleeexClient({
apiKey: process.env.FLEEEX_API_KEY!,
userId: "user-123",
});The constructor throws if apiKey or userId is missing, or if no fetch is
available (Node < 18 without the fetch option).
Options
new FleeexClient(options) takes a FleeexClientOptions:
| Option | Type | Default | Notes |
|---|---|---|---|
apiKey | string | — | Required. App API key (flx_…). Sent as Authorization: Bearer. |
userId | string | — | Required. End user the app vouches for. Sent as x-fleeex-user. |
baseURL | string | https://api.fleeex.dev | Fleeex API root, without a trailing /v1. Point at http://localhost:3000 for local dev. |
onPaymentRequired | (err) => void | Promise<void> | — | Hook fired on any mapped 402, before the error is thrown. |
maxRetries | number | OpenAI default | Forwarded to the underlying OpenAI client (network / 5xx retries). |
defaultHeaders | Record<string, string> | — | Extra headers merged onto every request (after the Fleeex-managed ones). |
fetch | typeof fetch | global fetch | Custom transport (proxies, tests). |
Methods
chat.completions.create
The OpenAI method, untouched — same params and return types (including the
stream: true overload). The SDK only preconfigures the connection and maps a 402
to PaymentRequiredError.
const completion = await client.chat.completions.create({
model: "anthropic.claude-3-haiku-20240307-v1:0",
messages: [{ role: "user", content: "Hello!" }],
});See Streaming for the stream: true form.
getBalance
getBalance(): Promise<BalanceResponse>Remaining prepaid balance for the configured (app, user). Throws
PaymentRequiredError on a 402 (after
onPaymentRequired fires). Returns a
BalanceResponse. See
Balance & payments.
getConnection
getConnection(options?: GetConnectionOptions): Promise<ConnectionStatus>Whether the (app, user) is connected and funded, plus an onboarding link — with no
chat call. Never raises a 402. Pass redirectUri (registered on the app) to be
returned there once connected. Returns a
ConnectionStatus. See
Connecting users.
getUsageSummary
getUsageSummary(): Promise<UsageSummary>Month-to-date usage (spend, tokens, requests) for the configured (app, user).
Never raises a 402 — no usage reads as zeros. Returns a
UsageSummary. See Usage summary.