Fluxio
← Back to the blog

Your First Token Stream: A Beginner’s AI API Path

SSE & APIsEN

§1 A streamed completion is a reply you can watch arrive

A completion is simply an AI model’s response to your input. With a non-streaming request, your application waits for the response before displaying it. With streaming, your application receives small pieces as the model generates its answer. That lets someone start reading while the rest is still arriving.

Imagine asking for a short explanation of rain. Instead of waiting for a finished paragraph, you see the opening words appear, followed by the next phrase. This is the basic experience behind a live AI chat interface.

Your first goal is modest: send one message, receive a stream, and print the arriving text. You do not need a database, a polished interface, or a complex agent.

§2 Tokens, chunks, and SSE in plain language

A token is a small unit of text processed by a model. It might be a word, part of a word, or punctuation. Tokens are not the same as characters or words.

A chunk is one piece of data delivered to your application. Although people describe streaming as “token by token,” a network chunk does not necessarily contain exactly one token. Some chunks contain no visible text at all.

Many streaming chat APIs use server-sent events, or SSE, to deliver these pieces over an HTTP connection. An SDK usually handles the event parsing, so a beginner can focus on reading chunks rather than decoding the underlying transport.

§3 Connect an OpenAI SDK client to Fluxio

Fluxio is a useful fit when you want a streaming-first, pay-per-token relay rather than separate integrations for multiple model providers. One API key gives you access to models through a shared interface, with replies arriving incrementally.

For a first experiment, use the official OpenAI Python SDK with Fluxio’s compatible endpoint. Keep the setup small:

  • – Install the Python package by running pip install openai in your terminal.
  • – Create an API key and store it in an environment variable named FLUXIO_API_KEY.
  • – Choose an available model, such as Gemini 2.5 Flash, and copy its exact API model identifier from Fluxio’s model listing.
  • – Initialize the SDK client with your key and set base_url to https://api.fluxioapi.com/v1.

Fluxio’s API base is https://api.fluxioapi.com; OpenAI-style clients use the additional /v1 path. Keep your key in server-side code or a local environment, never in browser JavaScript shipped to users.

§4 Request one message with streaming enabled

Use the SDK’s client.chat.completions.create method. Supply your chosen model identifier, a messages list containing one user message, and stream=True. A suitable first prompt is “Explain streaming in two short sentences.”

The messages list should contain an object with role set to user and content set to your prompt. Streaming changes how you receive the answer, not how you phrase the question.

The returned stream is something you iterate over. For each chunk, check whether it contains a choice, read the first choice’s delta.content, and print that content when present. In Python, printing with end="" and flush=True keeps the pieces together and displays them promptly.

§5 Recognize a successful first live reply

Success means text appears incrementally and the stream eventually finishes. Do not expect every chunk to contain a complete word or sentence. Preserve the received text exactly rather than adding a space after every piece.

If nothing appears, check your API key, account balance, model identifier, and base URL. If the whole answer appears at once, confirm streaming is enabled and that your output is not being buffered. When you later add a web server, its buffering settings can affect delivery too.

Streaming improves perceived responsiveness; it does not guarantee lower cost or a faster complete answer. Once your terminal displays a live reply, you have the core building block for real-time chat.

Sign up for Fluxio to try your first stream.

Create a Fluxio account →

More from the current