Streaming
Get the reply token by token as server-sent events.
Pass "stream": true to get the reply token by token as server-sent events, ending with data: [DONE]. Leave it out, or pass false, to get one JSON reply.
curl:
curl -N https://api.thesapientdirective.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_GHOST_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"ghost-x2","stream":true,"messages":[{"role":"user","content":"Count to five"}]}'
Python:
stream = client.chat.completions.create(
model="ghost-x2",
messages=[{"role": "user", "content": "Count to five"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")