Fleeexdocs

Errors

The typed errors the SDK raises — PaymentRequiredError, FleeexApiError, and OpenAI errors.

The SDK raises three kinds of error.

PaymentRequiredError

Thrown when the proxy or getBalance() answers 402 — the (app, user) has no funded, authorized wallet. Carries the signed top-up link.

import { PaymentRequiredError } from "@fleeex/sdk";
 
try {
  await client.chat.completions.create({ model, messages });
} catch (err) {
  if (err instanceof PaymentRequiredError) {
    redirect(err.topupUrl);
  }
}
PropertyTypeNotes
status402Always 402.
topupUrlstring | undefinedSigned, short-lived link to send the end user through Checkout.
codestring | undefinedMachine-readable error code from the envelope.
correlationIdstring | undefinedTrace id for support/debugging.
messagestringGeneric by design — never reveals whether a wallet exists.

The onPaymentRequired hook (see options) fires for the same condition before the error is thrown.

FleeexApiError

Any other non-2xx from a Fleeex billing helper (getConnection(), getUsageSummary(), or a non-402 from getBalance()) — for example a 400 when a redirectUri isn't on the app's allow-list.

PropertyTypeNotes
statusnumberHTTP status.
codestring | undefinedError code from the envelope.
correlationIdstring | undefinedTrace id.

OpenAI errors

For the proxy path, any error other than 402 is raised by the OpenAI SDK as OpenAI.APIError (and its subclasses) — e.g. a 400 for an unsupported model. Handle these exactly as you would with the OpenAI SDK.

import OpenAI from "openai";
import { PaymentRequiredError } from "@fleeex/sdk";
 
try {
  await client.chat.completions.create({ model, messages });
} catch (err) {
  if (err instanceof PaymentRequiredError) redirect(err.topupUrl);
  else if (err instanceof OpenAI.APIError) console.error(err.status, err.message);
  else throw err;
}

The error envelope

Fleeex's backend emits a consistent body, exposed as the FleeexErrorBody type. Only a 402 carries topupUrl.

interface FleeexErrorBody {
  error?: { code?: string; message?: string; correlationId?: string };
  topupUrl?: string;
}