Skip to main content

Minimal request

{
  "model": "gpt-4.1",
  "messages": [
    { "role": "user", "content": "Explain SSE streaming while streaming the answer." }
  ],
  "stream": true
}

cURL example

curl https://mass.apigo.ai/v1/chat/completions \
  -H "Authorization: Bearer $TIDEMIND_API_KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      { "role": "user", "content": "Explain SSE streaming while streaming the answer." }
    ],
    "stream": true
  }'

Python example

from openai import OpenAI

client = OpenAI(
    base_url="https://mass.apigo.ai/v1",
    api_key="<TIDEMIND_API_KEY>",
)

stream = client.chat.completions.create(
    model="gpt-4.1",
    messages=[
        {"role": "user", "content": "Explain SSE streaming while streaming the answer."}
    ],
    stream=True,
)

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

Node.js example

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://mass.apigo.ai/v1",
  apiKey: process.env.TIDEMIND_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "gpt-4.1",
  messages: [
    { role: "user", content: "Explain SSE streaming while streaming the answer." }
  ],
  stream: true
});

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

Best practices

  • Render incrementally from streamed chunks
  • Consider responses streaming if you will later add tools or structured output
  • Handle reconnection and chunk assembly on the server