Docs

Streaming chat completions

Stream chat completions with abliteration.ai. Set stream: true and iterate over delta chunks.

Updated 2026-08-04

Streaming reduces time-to-first-token and delivers partial output as it is generated.

Use the OpenAI SDK with stream: true and iterate over chunks to render tokens immediately.

Streaming is ideal for chat UIs, typing indicators, and long-form generation where early feedback matters.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ABLIT_KEY,
  baseURL: "https://api.abliteration.ai/v1",
});

const stream = await client.chat.completions.create({
  model: "abliterated-model",
  messages: [{ role: "user", content: "Write a short haiku about the ocean." }],
  stream: true,
});

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

When to stream

Stream when you want faster perceived latency or to show partial output.

How streaming works

The response is sent as a series of chunks. Each chunk contains a delta that you append to the final message.

Python streaming example

The Python SDK yields chunks you can iterate over. Append delta content as it arrives.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.abliteration.ai/v1",
    api_key="YOUR_ABLIT_KEY",
)

stream = client.chat.completions.create(
    model="abliterated-model",
    messages=[{"role": "user", "content": "Write a short haiku about the ocean."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="")

UI and reliability tips

Streaming is best-effort over long-lived HTTP connections, so plan for reconnects and graceful fallbacks.

FAQ

Frequently asked questions.

How do I fix a 401 Unauthorized error from abliteration.ai?

Check that your API key is set and sent as a Bearer token.

How do I fix a 404 Not Found error from abliteration.ai?

Make sure the base URL ends with /v1 and you call /chat/completions.

How do I fix a 400 Bad Request error from abliteration.ai?

Verify the model id and that messages are an array of { role, content } objects.

How do I fix a 429 Rate limit error from abliteration.ai?

Back off and retry. Use the Retry-After header for pacing.