Unaligned API
Streaming
Get the text as it is generated, then the cost and balance at the end.
Add "stream": true to a Chat request. The response is text/event-stream: one data: line per piece of text, and a last one with done.
data: {"text": "A"}
data: {"text": " token is"}
data: {"text": " a piece of text…"}
data: {"done": true, "finish": "stop", "usage": {"input_tokens": 21, "output_tokens": 48}, "cost": 0.0000510, "balance": 20.4999490}If the connection drops, you are billed for the tokens generated until then, not for the full answer.