Your First Live AI Reply with Token Streaming
§1 Start with a reply that appears as it arrives
Your first streaming milestone is simple: send a prompt and watch the answer arrive incrementally instead of waiting for the complete response. This walkthrough uses curl in a terminal, so you can understand the network behavior before adding an SDK or building a chat interface.
Fluxio fits this experiment because it is a streaming-first, pay-per-token AI API relay with an OpenAI-compatible interface. Its base address is https://api.fluxioapi.com; OpenAI-style requests use the /v1 prefix. One API key lets you access multiple model providers without rebuilding your connection for each one.
§2 Prepare curl and your Fluxio API key
You need a terminal running Bash, curl, a Fluxio API key, and sufficient account balance for a small request. Run curl --version to confirm that curl is installed.
Keep your key out of browser code, screenshots, and source control. To load it without putting the secret directly into your shell history, run this command, paste your key, and press Enter. The input will remain hidden:
$ read -r -s FLUXIO_API_KEY; export FLUXIO_API_KEYThe remaining commands read that environment variable. Treat it as a secret even though it is not visible in the commands themselves.
§3 Find an available model identifier
API requests need an exact model identifier, which may differ from a model's display name. Check the available models rather than guessing the identifier:
$ curl -sS https://api.fluxioapi.com/v1/models -H "Authorization: Bearer $FLUXIO_API_KEY"Inspect the returned model entries and copy the identifier for a model you can access. For example, look for Gemini 2.5 Flash if it is available to your account. Store the exact returned identifier with this command, replacing the placeholder:
$ export FLUXIO_MODEL='YOUR_MODEL_ID'This discovery step also checks that your key and network connection work before you introduce streaming.
§4 Send a completion request with streaming enabled
Paste the following command as one line. It sends a short prompt to the chat completions endpoint and requests a streamed response:
curl -N -sS https://api.fluxioapi.com/v1/chat/completions -H "Authorization: Bearer $FLUXIO_API_KEY" -H "Content-Type: application/json" -d '{"model":"'"$FLUXIO_MODEL"'","messages":[{"role":"user","content":"Explain token streaming to a beginner in three short sentences."}],"stream":true}'
The stream field enables streaming, while curl's -N option disables its output buffering. Both matter: the server must stream the response, and your client must display incoming data promptly.
Keep the first prompt short. A small request makes it easier to inspect the response and avoids spending tokens on an unnecessarily long test.
§5 Read the incoming SSE events
The terminal should show server-sent events, commonly called SSE. In an OpenAI-style stream, events typically contain data lines carrying JSON chunks, separated by blank lines.
Look inside choices[0].delta.content for incoming text. Some chunks contain role information or other metadata instead, so an empty content field does not automatically mean the request failed. A final data event containing [DONE] typically marks the end.
Although streaming is often described as token-by-token delivery, network chunks do not necessarily correspond to individual tokens. A chunk may contain several characters or a longer text fragment.
§6 Fix the first common streaming problems
- – An authentication error: Confirm that the environment variable contains the correct key and that the Authorization header starts with Bearer.
- – A model access error: Recheck the returned model identifier and your account's access to that model.
- – A reply that appears all at once: Confirm that stream is true and curl includes -N. Proxies and application layers can also buffer output.
- – An unexpected response body: Inspect the HTTP status and error message before trying to parse the response as SSE.
§7 Turn terminal chunks into a live chat message
Once the terminal test works, move the same request into a server-side application or an OpenAI-compatible SDK configured with the Fluxio key and https://api.fluxioapi.com/v1. Iterate over incoming chunks, append text deltas to one message, and update the interface as they arrive.
Keep the API key on your server. Add cancellation, visible error handling, and sensible output limits before expanding beyond your first experiment.
Sign up for Fluxio to stream your first reply.