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_… live, or flx_test_… for a test key. 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 and 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 itself, with OpenAI's own request and return types (including the
stream: true overload). The SDK only preconfigures the connection and maps a 402 to
PaymentRequiredError. It validates
nothing and rewrites no field.
The server's parameter surface is narrower than those types: a documented subset of
OpenAI's, where an unsupported parameter is a 400 naming itself. See
Supported parameters.
const completion = await client.chat.completions.create({
model: "nova-lite",
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 and 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, and no usage reads as zeros. Returns a
UsageSummary. See
Usage summary.