AI Providers
Better Hub integrates three AI providers:Primary AI provider with access to 100+ models. Used for Ghost assistant conversations, code generation, and most AI features.Website: openrouter.ai
Direct Anthropic API access for Claude models. Used for specific high-quality tasks requiring Claude.Website: console.anthropic.com
Optional OpenAI API access for GPT models. Only needed if using GPT models directly.Website: platform.openai.com
OpenRouter Setup
OpenRouter provides unified access to models from OpenAI, Anthropic, Google, Meta, and more.Create OpenRouter account
Sign up at OpenRouter.
Generate API key
- Go to API Keys
- Click Create Key
- Copy your API key
Add credits
- Go to Credits
- Add credits (minimum $5)
- OpenRouter bills per-request based on model pricing
OpenRouter Pricing
Pricing varies by model:- Claude 4.5 Sonnet: 15.00 per million tokens (input/output)
- GPT-4o: 10.00 per million tokens
- Gemini 2.5 Pro: 5.00 per million tokens
- Kimi K2.5: 1.00 per million tokens (default)
Anthropic Setup
Direct Anthropic access for Claude models.Create Anthropic account
Sign up at Anthropic Console.
Generate API key
- Navigate to API Keys
- Click Create Key
- Copy your API key
When to Use Direct Anthropic
Use Anthropic API directly when:- You need specific Claude features not available via OpenRouter
- You want to avoid OpenRouter markup
- You need Anthropic’s prompt caching feature
Model Configuration
Configure which models Ghost uses for different tasks.Ghost Assistant Model
Primary model for Ghost AI conversations, code analysis, and general assistance.Default:
moonshotai/kimi-k2.5 (cost-effective, 256K context)Recommended alternatives:anthropic/claude-4.5-sonnet- Highest quality, best for complex tasksgoogle/gemini-2.5-pro- Excellent quality, 2M context windowopenai/gpt-4o- Strong general-purpose modelmeta-llama/llama-4-70b- Open source, cost-effective
Merge Model
Specialized model for merge conflict resolution and code merging tasks.Default:
google/gemini-2.5-pro-preview (excellent at code understanding)Why Gemini: Large context window (2M tokens) handles big merge conflicts.Model Selection Criteria
Choose models based on: For general use:- Budget-conscious:
moonshotai/kimi-k2.5,meta-llama/llama-4-70b - High quality:
anthropic/claude-4.5-sonnet,openai/gpt-4o - Large context:
google/gemini-2.5-pro,anthropic/claude-opus
- Code generation:
anthropic/claude-4.5-sonnet,openai/gpt-4o - Code review:
google/gemini-2.5-pro,anthropic/claude-4.5-sonnet - Debugging:
anthropic/claude-4.5-sonnet,openai/o4
- Natural dialogue:
anthropic/claude-4.5-sonnet,openai/gpt-4o - Technical Q&A:
google/gemini-2.5-pro,anthropic/claude-4.5-sonnet
User Model Selection
Users can override the default model in their settings:- Go to Settings > AI Preferences
- Select Ghost Model: Auto, or choose a specific model
- Enable Use Own API Key to use personal OpenRouter credits
Bring Your Own Key (BYOK)
Users can use their own OpenRouter API keys:
This is tracked in the database:
apps/web/prisma/schema.prisma:202-203.
Cost Management
Track AI Usage
All AI calls are logged for billing:Set Spending Limits
Users can set monthly spending caps:Optimize Costs
Use cost-effective default model
moonshotai/kimi-k2.5 is 10x cheaper than Claude while maintaining good quality.Cost Per Feature
Estimated costs for typical operations:- Chat message: 0.01 (depends on model and context)
- Code review: 0.10 (analyzing PR with diffs)
- Merge resolution: 0.25 (large conflicts)
- Search query: 0.005 (embedding + ranking)
Advanced Configuration
Model Router
Automatically select the best model based on task:Fallback Strategy
Handle model failures gracefully:Rate Limiting
Protect against abuse:Monitoring
Track Model Performance
Log response times and success rates:Cost Alerts
Alert when costs exceed thresholds:Troubleshooting
API Key Invalid
Error:Unauthorized or Invalid API key
Solutions:
- Verify API key is correct (check for extra spaces)
- Ensure key has credits/billing enabled
- Regenerate key if compromised
Rate Limit Exceeded
Error:429 Too Many Requests
Solutions:
- Implement exponential backoff
- Add rate limiting on your side
- Upgrade API plan for higher limits
- Use multiple API keys with load balancing
Model Not Found
Error:Model not found or Invalid model ID
Solutions:
- Check model ID is correct: openrouter.ai/models
- Some models require special access
- Model may be deprecated - choose alternative
Context Length Exceeded
Error:Context length exceeded
Solutions:
- Reduce context size (fewer files, shorter messages)
- Use model with larger context window (Gemini 2.5 Pro: 2M tokens)
- Implement context pruning strategy
High Costs
Symptoms: Unexpectedly high AI spending Solutions:- Check
AiCallLogtable for usage patterns - Switch to cheaper default model
- Implement caching for repeated queries
- Set lower spending limits
- Enable user BYOK to shift costs
Security
Environment-Specific Keys
Development
Production