OpenRouter Provider
Claude-mem supports OpenRouter as an alternative provider for observation extraction. OpenRouter provides a unified API to access 100+ models from different providers including Google, Meta, Mistral, DeepSeek, and many others—often with generous free tiers.Why Use OpenRouter?
- Access to 100+ models: Choose from models across multiple providers through one API
- Free tier options: Several high-quality models are completely free to use
- Cost flexibility: Pay-as-you-go pricing on premium models with no commitments
- Errors throw clearly: 429s, 5xx, and network failures throw — leaving messages pending so they can be retried
- Hot-swappable: Switch providers without restarting the worker
- Multi-turn conversations: Full conversation history maintained across API calls
Free Models on OpenRouter
OpenRouter actively supports democratizing AI access by offering free models. These are production-ready models suitable for observation extraction.Featured Free Models
Default Model: Claude-mem uses
xiaomi/mimo-v2-flash:free by default—a 309B parameter mixture-of-experts model that ranks #1 on SWE-bench Verified and excels at coding and reasoning tasks.Free Model Considerations
- Rate limits: Free models may have stricter rate limits than paid models
- Availability: Free capacity depends on provider partnerships and demand
- Queue times: During peak usage, requests may be queued briefly
- Max tokens: Most free models support 65,536 completion tokens
- Tool use and function calling
- Temperature and sampling controls
- Stop sequences
- Streaming responses
Getting an API Key
- Go to OpenRouter
- Sign in with Google, GitHub, or email
- Navigate to API Keys
- Click Create Key
- Copy and securely store your API key
Configuration
Settings
Using the Settings UI
- Open the worker URL printed on startup
- Click the gear icon to open Settings
- Under AI Provider, select OpenRouter
- Enter your OpenRouter API key
- Optionally select a different model
Manual Configuration
Edit~/.claude-mem/settings.json:
Model Selection Guide
For Free Usage (No Cost)
Recommended:xiaomi/mimo-v2-flash:free
- Best-in-class performance on coding benchmarks
- 256K context window handles large observations
- 65K max completion tokens
- Mixture-of-experts architecture (15B active parameters)
google/gemini-2.0-flash-exp:free- 1M context, Google’s flagshipdeepseek/deepseek-r1:free- Excellent reasoning capabilitiesmeta-llama/llama-3.1-70b-instruct:free- Strong general purpose
For Paid Usage (Higher Quality/Speed)
Context Window Management
The full conversation history is sent to the model on each request. claude-mem does not apply any client-side truncation or message-count cap — the provider and model own their own context window. If you need to bound context for a specific model, choose a model with an appropriate context length or manage limits at the OpenRouter/provider level.Cost Tracking
Logs include detailed usage information:Provider Switching
You can switch between providers at any time:- No restart required: Changes take effect on the next observation
- Conversation history preserved: When switching mid-session, the new provider sees the full conversation context
- Seamless transition: All providers use the same observation format
Switching via UI
- Open Settings in the viewer
- Change the AI Provider dropdown
- The next observation will use the new provider
Switching via Settings File
Error Behavior
If OpenRouter errors, claude-mem logs the failure and re-throws so the message stays pending for later retry. There is no Claude SDK fallback — earlier docs claimed automatic Claude fallback, but the wiring was never actually engaged in production (#2087). To switch providers, changeCLAUDE_MEM_PROVIDER in settings.
Throwing conditions:
- Rate limiting (HTTP 429)
- Server errors (HTTP 500, 502, 503)
- Network issues (connection refused, timeout)
- 4xx errors other than 429
- Missing API key
Multi-Turn Conversation Support
OpenRouter agent maintains full conversation history across API calls:- Coherent multi-turn exchanges
- Context preservation across observations
- Seamless provider switching mid-session
Troubleshooting
”OpenRouter API key not configured”
Either:- Set
CLAUDE_MEM_OPENROUTER_API_KEYin~/.claude-mem/settings.json, or - Set the
OPENROUTER_API_KEYenvironment variable
Rate Limiting
Free models may have rate limits during peak usage. If you hit rate limits:- The agent throws and leaves the message pending — it will be retried later
- Consider switching to a different free model
- Add credits for premium model access
Model Not Found
Verify the model ID is correct:- Check OpenRouter Models for current availability
- Use the
:freesuffix for free model variants - Model IDs are case-sensitive
High Token Usage
If a session accumulates a large conversation history, requests can grow. To keep per-request cost down:- Choose a model with pricing suited to your usage
- Consider a model with a larger context window if you hit provider-side limits
Connection Errors
If you see connection errors:- Check your internet connection
- Verify OpenRouter service status at status.openrouter.ai
- The agent throws and leaves the message pending for later retry
API Details
OpenRouter uses an OpenAI-compatible REST API: Endpoint:https://openrouter.ai/api/v1/chat/completions
Headers:
Comparing Providers
Next Steps
- Configuration - Full settings reference
- Gemini Provider - Alternative free provider
- Getting Started - Basic usage guide
- Troubleshooting - Common issues

