Skip to content

feat(llm): add OpenRouter as a native LLM provider#363

Open
amiraijaz wants to merge 1 commit intoSmythOS:mainfrom
amiraijaz:feature/openrouter-llm-connector
Open

feat(llm): add OpenRouter as a native LLM provider#363
amiraijaz wants to merge 1 commit intoSmythOS:mainfrom
amiraijaz:feature/openrouter-llm-connector

Conversation

@amiraijaz
Copy link
Copy Markdown

Summary

  • Adds OpenRouterConnector — a dedicated LLM connector giving SmythOS agents
    access to 100+ models (Mistral, Llama, Qwen, Gemma, DeepSeek, Phi, Command R+)
    through a single OpenRouter API key
  • Registers the connector in LLM.service/index.ts (+3 lines, zero changes to core engine)
  • Adds 7 initial model entries to models.ts under a new #region OpenRouter section
  • Adds 5 integration tests (prompt, system message, JSON mode, streaming, tool calling)
    — all passing against the live API

Why OpenRouter and not just Groq

Groq = speed (LPU hardware, ~15 curated models)
OpenRouter = choice (100+ models, automatic provider fallback, day-of-release availability)

They are complementary, not redundant. Users wanting Mistral, Llama 3.3, Qwen 2.5,
Gemma 3, or DeepSeek R1 currently have no path in SmythOS. This PR fixes that
with one connector.

Why a dedicated connector (not reusing OpenAIConnector)

OpenRouter requires identifying HTTP headers (HTTP-Referer, X-Title) that the
existing OpenAI connector has no mechanism to send. A dedicated connector also
provides a clean foundation for future OpenRouter-specific features such as
provider routing config and per-request cost tracking via the usage.cost field
returned in every OpenRouter response.

Files changed

File Change
connectors/OpenRouter.class.ts New — full connector (395 lines)
LLM.service/index.ts +3 lines: import, register, init
models.ts +7 model entries in new #region OpenRouter
tests/integration/003-LLM/openrouter/openrouter.test.ts New — 5 integration tests

Test plan

  • Simple prompt returns valid response
  • System message handled correctly
  • JSON response format (responseFormat: json) works
  • Streaming via EventEmitter works end-to-end
  • Tool calling (function calling) works — tested with Mistral Large
  • Full TypeScript build passes — no new errors, no regressions
  • All 157 existing unit tests still pass

Adds OpenRouter as a first-class LLM connector, giving SmythOS agents
access to 100+ models (Mistral, Llama, Qwen, Gemma, DeepSeek, Phi,
Command R+) through a single OpenRouter API key and zero changes to
the core engine.

## What changed

### New: OpenRouter connector
- Full implementation of all 4 abstract LLMConnector methods:
  request, streamRequest, reqBodyAdapter, reportUsage
- Streaming via EventEmitter + setImmediate (prevents race conditions)
- Tool calling (function calling) support
- JSON response format support
- OpenRouter-specific headers: HTTP-Referer and X-Title

### Modified: LLM service registry (+3 lines)
- Import, register, and init OpenRouterConnector

### Modified: Model catalog (+7 entries)
- openrouter/mistral-large
- openrouter/meta-llama/llama-3.3-70b
- openrouter/qwen/qwen-2.5-72b
- openrouter/google/gemma-3-27b
- openrouter/deepseek/deepseek-r1
- openrouter/microsoft/phi-4
- openrouter/cohere/command-r-plus

### New: Integration tests (5 tests, all passing)
- Simple prompt, system message, JSON mode, streaming, tool calling

## Why a dedicated connector (not reusing OpenAIConnector)
OpenRouter requires HTTP-Referer and X-Title headers that the existing
OpenAI connector cannot send. A dedicated connector also provides a
foundation for future features: provider routing config and per-request
cost tracking via the usage.cost field in every OpenRouter response.

## Why OpenRouter (not just Groq)
Groq = speed (LPU hardware, ~15 curated models)
OpenRouter = choice (100+ models, automatic fallback, day-of release)
They are complementary, not redundant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SyedZawwarAhmed
Copy link
Copy Markdown
Contributor

@amiraijaz Thanks for putting this together and taking the time to make this contribution. Adding OpenRouter is a great fit for the platform.

We'll do our own tests end to end on our to make sure everything works correctly and then we'll get this merged. Thanks again for the contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants