Agent skill · software engineering · jeremylongshore

openrouter-streaming-setup

Implement streaming responses with OpenRouter for real-time UIs. Use

Why this skill is useful

Adds executable scripts for real-time streaming with OpenRouter, including error handling and performance metrics that aren't in public docs.

What it needs

Requires node, python3 installed locally. Requires openrouter account access. About 5k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.

What this skill does

OpenRouter Streaming Setup Overview OpenRouter supports Server-Sent Events (SSE) streaming via stream: true, compatible with the OpenAI SDK. Streaming returns tokens as they're generated, reducing time-to-first-token (TTFT) from seconds to milliseconds. Usage stats are available via streamoptions: {includeusage: true} in the final chunk. This skill covers Python and TypeScript streaming, SSE forwarding to browsers, and error recovery. Prerequisites An OpenRouter API key (sk-or-v1-...) exported as OPENROUTERAPIKEY — see the openrouter-install-auth skill for setup Python 3.8+ or Node.js 18+ with the OpenAI SDK (the async example uses AsyncOpenAI from the same Python package) FastAPI if you plan to forward the SSE stream to browsers per the SSE Forwarding section A streaming-appropriate client timeout (e.g. 120s) — longer than for non-streaming requests Instructions 1. Start with Python: Basic Streaming — pass stream=True plus streamoptions={"includeusage": True} so the final chunk carries token counts, and print each chunk.choices[0].delta.content as it arrives. 2. Wrap that loop in the Python: Streaming with Metrics generator to capture TTFT and total time per request; the metrics dict is available after the generator is exhausted. 3. For Node services, use the TypeScript: Streaming for await loop over the same stream: true request. 4. To reach a browser UI, expose the FastAPI endpoint in SSE Forwarding to Browser — it re-emits each token as a data: {"token": ...} SSE line and terminates with data: [DONE]. 5. Consume that endpoint with the Browser Client (JavaScript) reader loop, appending tokens to the DOM as they decode. 6. In async web frameworks, switch to the Async Streaming pattern built on AsyncOpenAI. 7. Handle mid-stream failures (cut-offs, missing usage, keep-alive pings, finishreason: "length") per the Error Handling table. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills jeremylongshore/openrouter-streaming-setup

View the source on GitHub

Browse the @skills marketplace