Sponsored byOutsenseAI that finds your next clients
SponsorGROUOutbound, LinkedIn content and leads for B2B teamsSponsorOutsenseAI that finds your next clientsAd+Your tool hereSeen by people installing AI tools@Weekly picksThe best new tools, one email a week

openrouter-streaming-setup

Skill by jeremylongshore

Explains how to implement streaming responses with OpenRouter for real-time chat interfaces. It covers Python and TypeScript streaming, SSE forwarding to browsers, and error recovery.

  • Score 76
  • 3k stars
  • MIT
  • Updated
Works withClaude CodeClaude apps Antigravity CLI

Install openrouter-streaming-setup

Built from the published package, never by AI.

git clone --depth 1 https://github.com/jeremylongshore/tons-of-skills-marketplace /tmp/tons-of-skills-marketplace && mkdir -p ~/.claude/skills && cp -r /tmp/tons-of-skills-marketplace/skills/.curated/openrouter-streaming-setup ~/.claude/skills/openrouter-streaming-setup

Run in your terminal. Claude Code loads skills from ~/.claude/skills automatically.

Step-by-step: install openrouter-streaming-setup in Claude Code

Skills can run scripts on your machine. Some need an API key: check the README.

About

This skill explains how to implement streaming responses with OpenRouter for real-time user interfaces. It uses the OpenAI SDK pointed at OpenRouter with stream set to true, which returns server-sent events. Tokens arrive as they are generated, which the skill says reduces time-to-first-token from seconds to milliseconds.

The skill includes Python and TypeScript examples, a metrics wrapper that records time-to-first-token and total time, and an async pattern built on AsyncOpenAI. It also shows a FastAPI endpoint that forwards tokens to a browser, plus a JavaScript reader loop that renders them. A table lists mid-stream failures and their fixes. It is aimed at developers building chat interfaces or processing long completions.

Written from the project's SKILL.md and checked against it.

What it can do

  • Python basic streamingStreams tokens with stream=True and prints token counts from the final chunk.
  • Streaming with metricsCaptures time-to-first-token, total time, and usage for each request.
  • TypeScript streamingUses a for await loop over a streamed OpenRouter chat completion.
  • SSE forwarding to browserRe-emits each token as a data SSE line from a FastAPI endpoint and ends with data: [DONE].
  • Browser client readerReads the SSE stream in JavaScript and appends tokens to the page as they arrive.
  • Async streamingStreams completions with AsyncOpenAI for async web frameworks.
  • Error handling guideLists fixes for cut-offs, missing usage, empty keep-alive chunks, and length limits.

What you need

  • OpenRouter API key exported as OPENROUTER_API_KEY
  • Python 3.8+ or Node.js 18+ with the OpenAI SDK
  • FastAPI for forwarding the stream to browsers
  • Client timeout of about 120s for streaming requests

Try asking

  • Add streaming to my OpenRouter chat endpoint and show tokens as they arrive.
  • Measure time to first token for my OpenRouter streaming requests.
  • Forward an OpenRouter stream to my browser over SSE with FastAPI.

Good to know

  • Streams can be cut off mid-response, so partial content must be saved and retried.
  • Streaming requests need longer client timeouts than non-streaming requests.
  • Token usage appears only when stream_options include_usage is set.

Security check

B
  • Allowed to use Write, Edit without limitsIn SKILL.md

Checked automatically: skills/.curated/openrouter-streaming-setup/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work

Inside the skill

Allowed tools: ReadWriteEditGrepBash(python3:*)Bash(node:*)

Alternatives to openrouter-streaming-setup

All alternatives →

Compare with agent-reproduce-align, google_contacts or m06-error-handling

openrouter-streaming-setup: common questions

What does streaming change for OpenRouter responses?

Tokens are returned as the model generates them, which the source says reduces time-to-first-token.

Can I get token counts when streaming?

Yes. Setting stream_options to include_usage makes the final chunk carry prompt and completion token counts.

How do browsers receive the stream?

A FastAPI endpoint re-emits each token as a data SSE line and ends the stream with data: [DONE].

How do I install openrouter-streaming-setup?

Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.

Is openrouter-streaming-setup free?

The code is published under the MIT licence. The service it connects to may have its own pricing.

Is openrouter-streaming-setup safe to use?

It scores 76 of 100. Grades: maintenance A, licence A, quality A. Security check: grade B (allowed to use write, edit without limits). Review the code before you install. How grades work.

What are alternatives to openrouter-streaming-setup?

Similar skills: agent-reproduce-align, google_contacts, m06-error-handling, caveman.

openrouter-streaming-setup Install

Add to stack

Loading.