Streaming
Stream responses in real-time using the requests library
Python Streaming with requests
import requests
BASE_URL = "https://api.llmzone.net/v1"
API_KEY = "YOUR_API_KEY"
def main():
response = requests.post(
f"{BASE_URL}/chat/completions",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json={
"model": "claude-opus-4-6",
"messages": [
{"role": "user", "content": "Hello!"}
],
"stream": True,
},
stream=True,
)
for line in response.iter_lines():
if line:
print(line.decode("utf-8"))
if __name__ == "__main__":
main()Expected Output
data: {"choices":[{"index":0,"delta":{"content":"Hello! How are","role":"assistant"}}],...}
data: {"choices":[{"index":0,"delta":{"content":" you doing today?","role":"assistant"}}],...}
data: {"choices":[{"index":0,"delta":{"content":" Is there something","role":"assistant"}}],...}
data: {"choices":[{"index":0,"delta":{"content":" I can help you with?","role":"assistant"}}],...}
data: [DONE]For Node.js streaming examples, see the Node.js / TypeScript page.