Guides
Streaming
stream to true and the answer arrives token by token as server-sent events, in the format of the API you called, so the SDKs' stream helpers work unchanged.OpenAI API#
import osfrom openai import OpenAIclient = OpenAI(base_url="https://fullsendai.com/v1", api_key=os.environ["FULLSEND_API_KEY"])stream = client.chat.completions.create( model="deepseek-v4.1-flash", messages=[{"role": "user", "content": "Explain this stack trace: ..."}], stream=True,)for chunk in stream: if chunk.choices: # the last chunk carries only usage print(chunk.choices[0].delta.content or "", end="", flush=True)Each data: line is a chat.completion.chunk. Text arrives in delta.content, a reasoning model's thinking in delta.reasoning_content, and tool calls as delta.tool_calls fragments to join by index (see Tool calling). The chunk with finish_reason is followed by one with usage and empty choices, then data: [DONE]. Full event example: API reference.
Anthropic API#
import osimport anthropicclient = anthropic.Anthropic(base_url="https://fullsendai.com", api_key=os.environ["FULLSEND_API_KEY"])with client.messages.stream( model="deepseek-v4.1-flash", max_tokens=1024, messages=[{"role": "user", "content": "Explain this stack trace: ..."}],) as stream: for text in stream.text_stream: print(text, end="", flush=True) final = stream.get_final_message()Events follow Anthropic's order: message_start, ping, then content_block_start / content_block_delta / content_block_stop for each text or tool_use block, message_delta with the stop reason and token counts, and message_stop. Full example: API reference.
Usage and cost#
Usage always comes at the end: in the last chunk on the OpenAI API (whether or not you set stream_options.include_usage), and in message_delta on the Anthropic API. A stream is charged once it ends, for those counts.
Stopping early#
Close the connection (break out of the loop, call stream.abort() or controller.abort()) and the model stops too. You're charged only for what was generated; when the model hadn't sent its final count yet, output is estimated from the text at about four characters a token. The call shows as Stopped in Logs.
Errors mid-stream#
Problems found before the first token (a bad key, an empty balance, a busy model) come back as a normal JSON error with its HTTP status. If the model goes quiet for 60 seconds after the stream has started, it ends with an error event (upstream_timeout on the OpenAI API, an error event on the Anthropic API). Treat what arrived as partial. See Errors.
Behind a proxy#
Cache-Control: no-cache, no-transform and X-Accel-Buffering: no, so nginx and most CDNs pass tokens straight through. If tokens still arrive all at once, turn off response buffering for that route in your proxy, and use curl -N when testing.Stuck? Email [email protected]System statusChangelog