Docs
Client SDKs

Node.js Client SDK

Repository-preview typed Node.js SDK with real SSE streaming.

Implemented repository preview

The Node SDK is implemented and package-tested in qufas-node. It is repository-only and is not publicly available from npm. For a public first integration, use the official OpenAI npm package in the Quickstart.

1# From a checkout of this repository2npm install ./qufas-node

Non-streaming Chat

1import { Qufas } from "qufas";2const client = new Qufas({ apiKey: process.env.QUFAS_API_KEY!, baseUrl: "https://qufas-ai.vercel.app" });3const response = await client.openai.createChatCompletion({4  createChatCompletionRequest: {5    model: "kimi-k2.7-code",6    messages: [{ role: "user", content: "Hello" }],7  },8});9console.log(response.choices[0].message.content, response.requestId);

AsyncIterable streaming

1const stream = await client.openai.createChatCompletion({2  createChatCompletionRequest: {3    model: "kimi-k2.7-code",4    messages: [{ role: "user", content: "Hello" }],5    stream: true,6    stream_options: { include_usage: true },7  },8});9console.log(stream.requestId);10for await (const chunk of stream) {11  console.log(chunk.choices[0]?.delta.content, chunk.usage);12}

The parser handles text and tool deltas, usage chunks, in-band errors, and [DONE]. The canonical header ID is available as stream.requestId.

Stable resources

1const models = await client.openai.listModels();2const usage = await client.management.listUsage({ limit: 25 });3const balance = await client.management.getBillingBalance();4const keys = await client.management.listApiKeys();5const generations = await client.management.listGenerations({ limit: 20 });6const generation = await client.management.retrieveGeneration({ requestId: "req_original" });

URL image generation is available through client.openai.createImageGeneration. Public API key write methods are intentionally absent.

Generation list/detail responses keep the OpenAPI wire shape, including next_cursor and decimal-string cost. A failed Generation returned with HTTP 200 is data; only a failed lookup throws QufasAPIError.

Errors

1import { QufasAPIError } from "qufas";2 3try {4  await client.openai.listModels();5} catch (error) {6  if (error instanceof QufasAPIError) {7    console.log(error.status, error.type, error.param, error.code, error.requestId);8  }9}

Was this page helpful?