Astrodyne

Streaming

Set "stream": true and the response arrives as Server-Sent Events — token deltas as they are generated, in the OpenAI chunk shape.

Enabling streaming

curl
curl https://api.astrodyne.ai/v1/chat/completions \
  -H "Authorization: Bearer $ASTRODYNE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "model": "YOUR_MODEL_ID",
       "stream": true,
       "messages": [{"role": "user", "content": "Hello"}]
     }'
Python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.astrodyne.ai/v1",
    api_key=os.environ["ASTRODYNE_API_KEY"],
)

stream = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)
JavaScript
import OpenAI from "openai";

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

const stream = await client.chat.completions.create({
  model: "YOUR_MODEL_ID",
  messages: [{ role: "user", content: "Hello" }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

How chunks arrive

The response has Content-Type: text/event-stream. Each event is a data: line containing a JSON chunk; text arrives at choices[0].delta.content. A final chunk carries finish_reason, then the stream ends with:

SSE
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

What is available during the stream

Mid-stream failures and disconnects

If a failure occurs after streaming has begun, Astrodyne emits one sanitized error event in the standard error shape with "object": "error", then closes the stream without [DONE]. If your client disconnects mid-stream, the request is settled for what was actually delivered — you are never charged when nothing was delivered, and the final state is visible in the Request Explorer either way.

Cancelling from a client
Aborting the HTTP request (for example with an AbortController) is the supported way to stop a stream early. The Playground's Stop button does exactly this.