šØ EXECUTION NOTICE FOR CLAUDE
When you invoke this command via SlashCommand, the system returns THESE INSTRUCTIONS below.
YOU are the executor. This is NOT an autonomous subprocess.
- ā
The phases below are YOUR execution checklist
- ā
YOU must run each phase immediately using tools (Bash, Read, Write, Edit, TodoWrite)
- ā
Complete ALL phases before considering this command done
- ā DON't wait for "the command to complete" - YOU complete it by executing the phases
- ā DON't treat this as status output - it IS your instruction set
Immediately after SlashCommand returns, start executing Phase 0, then Phase 1, etc.
See @CLAUDE.md section "SlashCommand Execution - YOU Are The Executor" for detailed explanation.
Available Skills
This commands has access to the following skills from the openrouter plugin:
- model-routing-patterns: Model routing configuration templates and strategies for cost optimization, speed optimization, quality optimization, and intelligent fallback chains. Use when building AI applications with OpenRouter, implementing model routing strategies, optimizing API costs, setting up fallback chains, implementing quality-based routing, or when user mentions model routing, cost optimization, fallback strategies, model selection, intelligent routing, or dynamic model switching.
- openrouter-config-validator: Configuration validation and testing utilities for OpenRouter API. Use when validating API keys, testing model availability, checking routing configuration, troubleshooting connection issues, analyzing usage costs, or when user mentions OpenRouter validation, config testing, API troubleshooting, model availability, or cost analysis.
- provider-integration-templates: OpenRouter framework integration templates for Vercel AI SDK, LangChain, and OpenAI SDK. Use when integrating OpenRouter with frameworks, setting up AI providers, building chat applications, implementing streaming responses, or when user mentions Vercel AI SDK, LangChain, OpenAI SDK, framework integration, or provider setup.
To use a skill:
!{skill skill-name}
Use skills when you need:
- Domain-specific templates and examples
- Validation scripts and automation
- Best practices and patterns
- Configuration generators
Skills provide pre-built resources to accelerate your work.
Security Requirements
CRITICAL: All generated files must follow security rules:
@docs/security/SECURITY-RULES.md
Key requirements:
- Never hardcode API keys or secrets
- Use placeholders:
your_service_key_here
- Protect
.env files with .gitignore
- Create
.env.example with placeholders only
- Document key acquisition for users
Arguments: $ARGUMENTS
Goal: Configure intelligent model routing in OpenRouter to optimize cost, performance, and reliability with automatic fallback strategies.
Core Principles:
- Detect project language and existing OpenRouter setup
- Configure provider preferences and fallback chains
- Set up cost-aware routing strategies
- Enable monitoring and analytics
Phase 1: Discovery
Goal: Understand project setup and routing requirements
Actions:
- Load OpenRouter documentation:
@plugins/openrouter/docs/OpenRouter_Documentation_Analysis.md
- Detect project language:
!{bash test -f package.json && echo "Node.js" || test -f requirements.txt -o -f pyproject.toml && echo "Python" || echo "Unknown"}
- Check for existing OpenRouter configuration:
!{bash find . -name ".py" -o -name ".ts" -o -name "*.js" | xargs grep -l "openrouter" 2>/dev/null | head -5}
- Parse $ARGUMENTS for routing strategy (cost, speed, quality, balanced, custom)
Phase 2: Analysis
Goal: Understand current configuration and requirements
Actions:
- Check existing API configuration:
!{bash grep -r "OPENROUTER" .env .env.local 2>/dev/null || echo "No config found"}
- Identify use cases from codebase:
!{bash find . -name ".py" -o -name ".ts" -o -name "*.js" | xargs grep -l "ChatOpenAI|openai|anthropic" 2>/dev/null | wc -l}
- Check if monitoring is enabled:
!{bash grep -r "X-Title|HTTP-Referer" . 2>/dev/null || echo "No monitoring"}
Phase 3: Implementation
Goal: Configure model routing and optimization
Actions:
Task(description="Configure model routing", subagent_type="openrouter-routing-agent", prompt="You are the openrouter-routing-agent. Configure intelligent model routing for $ARGUMENTS.
Context from Discovery:
- Project language detected
- Existing OpenRouter setup status
- Routing strategy: $ARGUMENTS (cost/speed/quality/balanced/custom)
Tasks:
-
Create routing configuration file:
Python:
- File: src/openrouter_config.py or config/openrouter.py
- Define model routing strategies
- Set up fallback chains
- Configure provider preferences
TypeScript:
- File: src/config/openrouter.ts or lib/openrouter-config.ts
- Define typed routing configurations
- Set up fallback chains
- Configure provider preferences
-
Implement routing strategies based on $ARGUMENTS:
- Cost: Free/low-cost models with premium fallback
- Speed: Fastest models with streaming
- Quality: Premium models with high-quality fallbacks
- Balanced: Task-based routing with cost/quality tradeoffs
- Custom: User-defined preferences and rules
-
Set up fallback strategies:
- Primary model configuration
- Secondary fallback options
- Tertiary emergency fallbacks
- Error handling and retries
- Circuit breaker patterns
-
Configure monitoring and analytics:
- Add X-Title header for request tracking
- Add HTTP-Referer for attribution
- Set up cost tracking
- Enable usage analytics
- Configure alerts for cost thresholds
-
Update environment configuration:
- OPENROUTER_API_KEY (if not present)
- OPENROUTER_APP_NAME for tracking
- OPENROUTER_SITE_URL for attribution
- Cost limits and budgets
- Preferred providers list
-
Create helper utilities:
- Model selector function
- Cost calculator
- Performance tracker
- Fallback handler
- Provider availability checker
-
Generate usage examples:
- Basic routing usage
- Dynamic model selection
- Cost-aware prompting
- Fallback handling
- Monitoring integration
WebFetch latest documentation:
Deliverable: Complete routing configuration with examples and monitoring")
Phase 4: Verification
Goal: Ensure routing configuration works
Actions:
- Verify configuration file created:
!{bash find . -name "routing" -o -name "openrouterconfig*" | grep -v node_modules | head -3}
- Check environment variables:
!{bash grep -E "OPENROUTER_(API_KEY|APP_NAME|SITE_URL)" .env .env.local 2>/dev/null || echo "ā ļø Configure environment"}
- Test routing logic exists:
!{bash find . -name ".py" -o -name ".ts" -o -name "*.js" | xargs grep -l "fallback|routing" 2>/dev/null | wc -l}
Phase 5: Summary
Goal: Provide configuration overview
Actions: