Skip to content

Fix hardcoded Opus defaults and improve provider flexibility#174

Open
inpassing wants to merge 21 commits intocloudflare:mainfrom
inpassing:fix-hardcoded-opus-defaults
Open

Fix hardcoded Opus defaults and improve provider flexibility#174
inpassing wants to merge 21 commits intocloudflare:mainfrom
inpassing:fix-hardcoded-opus-defaults

Conversation

@inpassing
Copy link

Pull Request: Fix Hardcoded Opus Defaults and Improve Provider Flexibility
Problem
The current start-moltbot.sh script has several issues that force users into expensive configurations:
Issue 1: Hardcoded Opus Default
The script sets anthropic/claude-opus-4-5-20251101 as the fallback model when OPENROUTER_API_KEY is not detected:
javascriptif (!process.env.OPENROUTER_API_KEY) {
config.agents.defaults.model.primary = 'anthropic/claude-opus-4-5';
}
Impact: Users who set up OpenRouter configuration in R2 or use AI Gateway without the OpenRouter env var get forced into Opus ($15-75/1M tokens) instead of more cost-effective options like Sonnet ($3-15/1M tokens) or Kimi K2.5 via OpenRouter ($0.45-2.50/1M tokens).
Issue 2: Configuration Override on Every Startup
The script runs on EVERY container restart and overwrites whatever model is configured in R2, making it impossible to persist model choices across restarts.
Issue 3: No OpenRouter-First Logic
Even when OPENROUTER_API_KEY is set, the script doesn't default to cost-effective models like Kimi K2.5. Users must manually configure this or risk falling back to expensive providers.
Issue 4: Limited Provider Support
The script only checks for Anthropic and OpenRouter, but doesn't properly support other providers that moltbot/OpenClaw supports (like OpenAI, custom endpoints, etc.).
Solution
This PR updates start-moltbot.sh to:

Respect existing configuration: If a model is already configured in R2, don't override it
Smart provider detection: Check for API keys in priority order:

OpenRouter (most cost-effective) → Default to Kimi K2.5
AI Gateway or Direct Anthropic → Default to Sonnet 4.5 (NOT Opus)
Fallback safely to Sonnet if no keys detected

Make Opus opt-in: Only add Opus as an available model option, never as the default
Better logging: Show which provider is detected and which model is being used

Key Changes
Before
javascript// Old logic - always overrides to Opus if no OpenRouter key
if (!process.env.OPENROUTER_API_KEY) {
config.agents.defaults.model.primary = 'anthropic/claude-opus-4-5';
}
After
javascript// New logic - respects existing config, smart defaults
const hasExistingModel = config.agents.defaults.model.primary;

if (!hasExistingModel) {
if (hasOpenRouter) {
config.agents.defaults.model.primary = 'openrouter/moonshotai/kimi-k2.5';
} else if (hasAIGateway || hasAnthropic) {
config.agents.defaults.model.primary = 'anthropic/claude-sonnet-4-5-20250929';
}
}
Cost Impact
For a user with 100K messages/month at average 1K tokens each:
Before (forced Opus)

Input: 100M tokens × $15 = $1,500
Output: 100M tokens × $75 = $7,500
Total: $9,000/month

After (Sonnet default)

Input: 100M tokens × $3 = $300
Output: 100M tokens × $15 = $1,500
Total: $1,800/month (80% savings)

After (OpenRouter Kimi K2.5)

Input: 100M tokens × $0.45 = $45
Output: 100M tokens × $2.50 = $250
Total: $295/month (97% savings)

Testing
Tested with the following configurations:

✅ Fresh deployment with OPENROUTER_API_KEY → Defaults to Kimi K2.5
✅ Fresh deployment with ANTHROPIC_API_KEY → Defaults to Sonnet 4.5
✅ Fresh deployment with AI_GATEWAY_* → Defaults to Sonnet 4.5
✅ Existing config in R2 → Respects existing model choice
✅ Container restart → Preserves model configuration
✅ No API keys set → Falls back to Sonnet (safest option)

Breaking Changes
None. This is fully backward compatible:

Users with OPENROUTER_API_KEY will now get better defaults (Kimi K2.5 instead of first available)
Users with existing R2 configs will see no change
Users forced to Opus previously will now default to Sonnet (significant cost savings)

Additional Benefits

Clearer provider detection logging: Shows which provider is detected on startup
Better model options: Pre-configures sensible model choices for each provider
Configuration summary: Displays active model and available options on startup
Safer fallbacks: Never defaults to the most expensive option

Files Changed

start-moltbot.sh - Complete rewrite of model configuration logic

Related Issues

Fixes #50 (OpenRouter support)
Addresses cost concerns mentioned in multiple issues
Improves overall developer experience

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.

Support for GLM-4.7 through Z.AI endpoint (or OpenRouter)?

1 participant