import json
import requests
response = requests.post(
"https://api.hostlinku.com/v1/chat/completions",
headers={
"Authorization": "Bearer sk-isi-api-key-kamu",
"Content-Type": "application/json",
},
json={
"model": "gpt-5-5",
"messages": [{"role": "user", "content": "Halo!"}],
"stream": True,
},
stream=True,
)
for line in response.iter_lines():
if not line:
continue
text = line.decode("utf-8")
if not text.startswith("data: "):
continue
payload = text[6:]
if payload == "[DONE]":
break
chunk = json.loads(payload)
if "error" in chunk:
raise RuntimeError(chunk["error"])
delta = chunk["choices"][0].get("delta", {}).get("content")
if delta:
print(delta, end="", flush=True)