import httpx
with httpx.stream(
"POST",
"https://api.lucid.foundation/v1/chat/completions",
headers={"Authorization": f"Bearer {LUCID_API_KEY}"},
json={
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": True,
},
) as response:
for line in response.iter_lines():
if line.startswith("data: ") and line != "data: [DONE]":
chunk = json.loads(line[6:])
content = chunk["choices"][0]["delta"].get("content", "")
print(content, end="", flush=True)