OpenCode Token Streams: A Five-Minute Multi-Model Setup
§1 Five minutes to live replies in OpenCode
A useful coding session should not feel like waiting for a finished document. With streaming, OpenCode displays the reply as tokens arrive, so you can start reading while the model continues working. This quick start connects OpenCode to Fluxio and makes two models available through one provider configuration.
Fluxio is a streaming-first, pay-per-token AI API relay. It fits this setup because one API key can reach multiple model families through an OpenAI-compatible endpoint. You keep your terminal workflow while choosing different models for different tasks.
Before starting: Have Node.js and npm available, a Fluxio API key, and a project directory you can safely experiment in. The five-minute target assumes those prerequisites are ready.
§2 Minute one: Install OpenCode and expose your key
Install the CLI with npm install -g opencode-ai, then open a terminal in your project directory. If OpenCode is already installed, check that it launches before changing its configuration.
In a macOS or Linux shell, set your key with export FLUXIO_API_KEY='YOUR_API_KEY'. In PowerShell, use $env:FLUXIO_API_KEY='YOUR_API_KEY'. Replace the placeholder with your actual key, and launch OpenCode from that same terminal so it inherits the variable.
Keep the key out of committed configuration files. Environment-variable substitution lets the project describe its connection without embedding a credential.
§3 Minute two: Find two exact Fluxio model IDs
Choose two models available to your account, such as Claude Sonnet 5.5 and Gemini 2.5 Flash. Copy their exact API model IDs from Fluxio rather than deriving identifiers from their display names.
The configuration below uses PRIMARY_MODEL_ID and SECOND_MODEL_ID as deliberate placeholders. Replace every occurrence with the corresponding real identifier before running OpenCode. These placeholders are not model names or usable API values.
For coding-agent work, also confirm that each selected route supports the tool-calling behavior OpenCode needs. Streaming text support alone does not guarantee compatibility with file edits, shell commands, or other agent actions.
§4 Minute three: Add the Fluxio provider to OpenCode
Create opencode.json in the project root, or merge these settings into your existing configuration without removing other providers:
{ "provider": { "fluxio": { "npm": "@ai-sdk/openai-compatible", "name": "Fluxio", "options": { "baseURL": "https://api.fluxioapi.com/v1", "apiKey": "{env:FLUXIO_API_KEY}" }, "models": { "PRIMARY_MODEL_ID": { "name": "Claude Sonnet 5.5" }, "SECOND_MODEL_ID": { "name": "Gemini 2.5 Flash" } } } }, "model": "fluxio/PRIMARY_MODEL_ID" }
The provider key, fluxio, becomes the prefix in OpenCode's model selector. The default model value combines that prefix with your exact model ID. Fluxio's API base is https://api.fluxioapi.com; this OpenAI-compatible configuration adds /v1.
§5 Minute four: Verify a live token stream
Run opencode and ask: “Describe this project's structure without modifying any files.” Watch whether the answer appears progressively rather than arriving as one completed block.
OpenCode handles the streaming transport through its provider adapter; you do not need to write a separate SSE client. Visible text may arrive in small batches because of buffering, so do not expect every token to appear as an individual screen update.
§6 Minute five: Switch models inside the session
Enter /models and select your second Fluxio model. Ask a follow-up about the same project, then check the selected model before requesting any edits.
This is multi-model access within your workflow, not automatic routing or parallel execution. Switching models also does not merge their context limits or guarantee identical tool behavior.
- – Use a fresh session with /new when comparing models on the same prompt without earlier conversation influencing the result.
- – For authentication errors, check the inherited environment variable; for missing-model errors, check the exact ID and account access.
- – If replies arrive all at once, check proxy buffering and route streaming support before treating the issue as model latency.
Sign up for Fluxio to try live multi-model replies.