Fleeexdocs

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

fleeex.ts
import { FleeexClient } from "@fleeex/sdk";
 
export const client = new FleeexClient({
  apiKey: process.env.FLEEEX_API_KEY!, // flx_…, a 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 itself, with OpenAI's own request and return types. The wire is iso-OpenAI, and the parameters the server honors are a documented subset of what those types allow.

const completion = await client.chat.completions.create({
  model: "nova-lite",
  messages: [{ role: "user", content: "Hello, Fleeex!" }],
});
 
console.log(completion.choices[0]?.message.content);

nova-lite is an alias, a stable public name Fleeex re-points at the next model revision, so this snippet keeps working. Which models you may call depends on your app, so don't hardcode a list. Ask GET /v1/models.

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: "nova-lite",
    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 and 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, then returned a standard OpenAI response. Next: streaming.