Build

Streaming

Forge streams responses as Server-Sent Events identical to OpenAI's wire format. Any client that handles OpenAI SSE works without changes.

Enable streaming

typescripttypescript
const stream = await ai.chat.completions.create({
  model: "anthropic/claude-4.5-sonnet",
  stream: true,
  messages: [{ role: "user", content: "Tell me a story." }],
});

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

Raw fetch

If you need full control, parse SSE manually. Each event is a JSON object prefixed with data: ; the stream ends with data: [DONE].

typescripttypescript
const res = await fetch("https://api.cytokenhub.com/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.FORGE_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "openai/gpt-5",
    stream: true,
    messages: [{ role: "user", content: "hi" }],
  }),
});

const reader = res.body!.getReader();
const decoder = new TextDecoder();
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  for (const line of decoder.decode(value).split("\n")) {
    if (!line.startsWith("data: ")) continue;
    const payload = line.slice(6);
    if (payload === "[DONE]") return;
    const evt = JSON.parse(payload);
    process.stdout.write(evt.choices[0]?.delta?.content ?? "");
  }
}
Streaming requests still count against your quota at completion time based on the final token usage.