Skip to content

feat: add OpenRouter LLM and embedding support#125

Open
nanxingw wants to merge 1 commit into
mainfrom
feat/openrouter-support
Open

feat: add OpenRouter LLM and embedding support#125
nanxingw wants to merge 1 commit into
mainfrom
feat/openrouter-support

Conversation

@nanxingw
Copy link
Copy Markdown
Collaborator

Summary

  • Add OpenRouterClient (inherits OpenAIClient) that skips convert_to_structured_output — non-OpenAI models (Anthropic, Gemini) routed through OpenRouter do not support strict mode / additionalProperties
  • Add OpenRouterEmbedding (inherits EmbeddingEndpoint) with Bearer auth header for OpenRouter's embedding API
  • Register "openrouter" as a new model_endpoint_type / embedding_endpoint_type in schemas and LLMClient factory

Files changed

  • mirix/llm_api/openrouter_client.py — new LLM client
  • mirix/embeddings.py — new embedding client + registration
  • mirix/llm_api/llm_client.py — factory registration
  • mirix/schemas/llm_config.py — schema Literal
  • mirix/schemas/embedding_config.py — schema Literal
  • tests/test_openrouter.py — 14 unit tests

Usage

llm_config:
  model: "anthropic/claude-haiku-4.5"
  model_endpoint_type: "openrouter"
  api_key: your-api-key
  model_endpoint: "https://openrouter.ai/api/v1"
  context_window: 128000

embedding_config:
  embedding_model: "google/gemini-embedding-001"
  embedding_endpoint_type: "openrouter"
  api_key: your-api-key
  embedding_endpoint: "https://openrouter.ai/api/v1"
  embedding_dim: 3072

Test plan

  • 14 unit tests covering schema validation, factory, tool schema (no strict), tool_choice, force_tool_call, embedding auth, error handling, and OpenAI regression
  • Smoke test: successfully created and searched 7 memories via OpenRouter
  • LoCoMo eval: 69.1% accuracy (105/152) with Claude Haiku via OpenRouter

🤖 Generated with Claude Code

Add a dedicated OpenRouterClient (inherits OpenAIClient) that skips
convert_to_structured_output — non-OpenAI models (Anthropic, Gemini)
routed through OpenRouter do not support strict mode. Also adds
OpenRouterEmbedding with Bearer auth for the embedding endpoint.

New endpoint type "openrouter" is registered in LLMClient factory,
LLMConfig, and EmbeddingConfig schemas.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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