Skip to content
SETU by SUPREME AI

Integrations

Plain HTTP from Python

Stream a chat reply with httpx, without the OpenAI SDK.

Streaming with httpx

Read the Server-Sent Events line by line and stop at data: [DONE].

# For servers that call Setu without the OpenAI SDK.
import json, os
import httpx

headers = {"Authorization": f"Bearer {os.environ['SETU_API_KEY']}"}
body = {"model": "quantum-lite", "stream": True, "messages": [{"role": "user", "content": "Namaste!"}]}

with httpx.stream("POST", "https://setu.supremeai.services/api/setu/v1/chat/completions", headers=headers, json=body, timeout=60) as r:
    for line in r.iter_lines():
        if line.startswith("data: ") and line != "data: [DONE]":
            delta = json.loads(line[6:])["choices"][0]["delta"].get("content")
            if delta:
                print(delta, end="", flush=True)