feat: Add OpenRouter LLM provider support
From the PR description
Summary
Adds full OpenRouter provider support to the LLM routing layer. The configuration layer (userApiKeys.ts) already supported storing and retrieving an OpenRouter API key, but there was no handler to actually use it. This change adds backend/src/lib/llm/openrouter.ts implementing streamOpenRouter() and completeOpenRouterText() following the same patterns as the existing Claude/Gemini/OpenAI adapters. OpenRouter model IDs are namespaced with an openrouter/ prefix (e.g. openrouter/meta-llama/llama-3.1-70b-instruct) which is stripped before sending to the API at https://openrouter.ai/api/v1/chat/completions. Tool use is handled via the OpenAI-compatible streaming format that OpenRouter exposes. The Provider type, providerForModel(), ALL_MODELS, and both routing functions in index.ts are all updated to recognise the new provider.
Changes
- Created
backend/src/lib/llm/openrouter.ts - Modified
backend/src/lib/llm/types.ts - Modified
backend/src/lib/llm/models.ts - Modified
backend/src/lib/llm/index.ts
Generated by Railway
Our analysis
Add OpenRouter as an LLM provider — read the full analysis →
Think the analysis missed something the PR description covers?
Commits in this PR (1)
| SHA | Subject | Author | Date | |
|---|---|---|---|---|
438b6f08 | feat: add OpenRouter LLM provider support | railway-app[bot] | 2026-06-28 | ↗ GitHub |
commit body- Add openrouter.ts with streamOpenRouter and completeOpenRouterText - Add OPENROUTER_MAIN/MID/LOW_MODELS constants to models.ts - Update providerForModel() to detect openrouter/ prefix - Expand ALL_MODELS set to include OpenRouter model IDs - Add "openrouter" to Provider union type in types.ts - Wire OpenRouter into streamChatWithTools and completeText in index.ts | ||||
Capture this PR into my fork
Download a Markdown prompt that tells Claude how to port every
commit in this PR into your working tree. Run it via
claude -p < capture-pull-5.md from
inside the repo you want the changes in.