Quickstart
Create a FleeexClient and make your first metered, OpenAI-compatible call.
This assumes you've installed the SDK and have an API key and a user id (see Authentication).
Create a client
import { FleeexClient } from "@fleeex/sdk";
export const client = new FleeexClient({
apiKey: process.env.FLEEEX_API_KEY!, // flx_… — server-side secret
userId: "user-123", // the end user your app vouches for
// baseURL: "http://localhost:3000", // local dev; defaults to the hosted endpoint
});apiKey and userId are the only required options. Everything else has a sensible
default — see the full options table.
Make a call
client.chat.completions.create is the OpenAI method, untouched — same params and
return types:
const completion = await client.chat.completions.create({
model: "anthropic.claude-3-haiku-20240307-v1:0",
messages: [{ role: "user", content: "Hello, Fleeex!" }],
});
console.log(completion.choices[0]?.message.content);The response is the standard OpenAI ChatCompletion object, including the usage
block (prompt_tokens, completion_tokens, total_tokens) that Fleeex meters and
bills against your wallet.
Handle "out of funds"
If the (app, user) has no funded, authorized wallet, the call throws a typed
PaymentRequiredError carrying a top-up link — redirect the end user there:
import { PaymentRequiredError } from "@fleeex/sdk";
try {
const completion = await client.chat.completions.create({
model: "anthropic.claude-3-haiku-20240307-v1:0",
messages: [{ role: "user", content: "Hello, Fleeex!" }],
});
return completion.choices[0]?.message.content;
} catch (err) {
if (err instanceof PaymentRequiredError) {
redirect(err.topupUrl); // send the end user through Checkout
}
throw err;
}See Balance & payments for the full flow, including
the onPaymentRequired hook for handling this in one place.
What just happened
The SDK sent an iso-OpenAI request to the Fleeex proxy with your bearer key and the
x-fleeex-user header. Fleeex authenticated the app, resolved the user, checked
solvency, called the model, metered the real token usage, and debited the wallet —
returning a standard OpenAI response. Next: streaming.