API capabilities

Stream a completion

Set stream: true to receive OpenAI-compatible Server-Sent Events while the model produces its response.

Start a stream

Use the same Chat Completions endpoint and add stream: true. The optional stream_options.include_usage request asks for usage in the final chunk when the upstream route supplies it.

typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.gonka24.com/v1",
  apiKey: process.env.GONKA24_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "<model-id-from-/v1/models>",
  messages: [{ role: "user", content: "Explain streaming in one sentence." }],
  stream: true,
  stream_options: { include_usage: true },
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Read the response

  • Read text from choices[0].delta.content; a chunk may contain no text.
  • Keep accumulating deltas until the stream completes rather than treating one chunk as a complete answer.
  • Use the final chunk for usage only when it is present; clients must not assume token counts exist in every event.

Handle interruptions

Abort a request when the user leaves the page or cancels an operation. For transient 5xx failures, retry a new request with bounded exponential backoff. Do not blindly replay operations that may have already caused external side effects through your own tools.