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.
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-setupRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
Step-by-step: install openrouter-streaming-setup in Claude Code
git clone --depth 1 https://github.com/jeremylongshore/tons-of-skills-marketplace /tmp/tons-of-skills-marketplace && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/tons-of-skills-marketplace/skills/.curated/openrouter-streaming-setup ~/.gemini/antigravity-cli/skills/openrouter-streaming-setupAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Step-by-step: install openrouter-streaming-setup in Antigravity CLI
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 →Aligns a Qwen Code feature with a Codex or Claude Code reference agent. It runs both under the same scenario, captures HTTP and terminal traces, and compares them until behavior matches.
Searches, views, creates, updates, and deletes the user's Google Contacts from an AI assistant. It is for people who want to manage their address book through conversation. A one-time Google connect is required before it returns data.
Guides an AI assistant on error handling choices. It covers when to use Result, Option, ? propagation, unwrap, expect and panic, plus anyhow and thiserror.
Caveman is an agent skill that makes an AI assistant reply in a terse style. It cuts filler and keeps technical facts, code, commands and errors exact. It is built for users who want shorter, cheaper replies.
docs-sync audits or updates English SDK documentation against the requested implementation scope. It is for maintainers who want docs to match main branch features, configuration options, and defaults.
Guides an AI assistant through setting up and running monorepos with pnpm workspaces, Turborepo and Nx. Aimed at developers who need faster builds, shared code and managed dependencies across multiple packages.
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.
