Update OpenRouter Config skill with complete documentation
- Add official OpenRouter documentation source link - Include API endpoint (https://openrouter.ai/api) - Add all required environment variables with explanations - Document provider priority (Anthropic 1P) - Add detailed benefits: failover, budget controls, analytics - Include verification steps with /status command - Add troubleshooting section - Document advanced features: statusline, GitHub Action, Agent SDK - Add security and privacy notes - Include important notes about ANTHROPIC_API_KEY being empty - Reference official docs for up-to-date information
This commit is contained in:
@@ -1,27 +1,79 @@
|
||||
---
|
||||
name: openrouter-config
|
||||
description: Use this skill when the user asks to "configure OpenRouter", "set up OpenRouter API key", "enable OpenRouter as AI provider", "configure OpenRouter in Claude Code", "set OpenRouter model", or mentions configuring OpenRouter for Claude Code.
|
||||
description: Use this skill when the user asks to "configure OpenRouter", "set up OpenRouter API key", "enable OpenRouter as AI provider", "configure OpenRouter in Claude Code", "set OpenRouter model", "connect Claude Code to OpenRouter", or mentions configuring OpenRouter for Claude Code.
|
||||
version: 1.0.0
|
||||
---
|
||||
|
||||
# OpenRouter Config Skill
|
||||
|
||||
Helps users configure and enable OpenRouter as the AI provider in Claude Code by setting up the OpenRouter API key, configuring the model, and ensuring Claude Code uses OpenRouter exclusively.
|
||||
Helps users configure and enable OpenRouter as the AI provider for Claude Code by setting up the OpenRouter API key, configuring Anthropic-compatible environment variables, and ensuring proper provider priority and failover capabilities.
|
||||
|
||||
## Documentation Source
|
||||
Official OpenRouter Claude Code Integration Guide: https://openrouter.ai/docs/guides/claude-code-integration
|
||||
|
||||
## What It Does
|
||||
|
||||
1. **API Key Setup**: Securely configures the OpenRouter API key
|
||||
2. **Model Configuration**: Sets the default OpenRouter model (arcee-ai/trinity-mini:free)
|
||||
3. **Provider Configuration**: Ensures Claude Code uses OpenRouter exclusively
|
||||
4. **Configuration Verification**: Validates that the configuration is working correctly
|
||||
2. **Environment Configuration**: Sets up Anthropic-compatible environment variables
|
||||
3. **Provider Priority**: Ensures Anthropic 1P is set as top priority provider
|
||||
4. **API Endpoint Configuration**: Configures `https://openrouter.ai/api` as the base URL
|
||||
5. **Configuration Verification**: Validates that the configuration is working correctly
|
||||
6. **Failover Setup**: Enables automatic provider failover for high availability
|
||||
|
||||
## Quick Commands
|
||||
## Key Benefits
|
||||
|
||||
### 1. Provider Failover for High Availability
|
||||
Anthropic's API occasionally experiences outages or rate limiting. OpenRouter automatically fails over between multiple Anthropic providers, keeping coding sessions uninterrupted.
|
||||
|
||||
### 2. Organizational Budget Controls
|
||||
Centralized budget management with spending limits, credit allocation, and cost overrun prevention for teams.
|
||||
|
||||
### 3. Usage Visibility and Analytics
|
||||
Complete visibility into Claude Code usage across teams, including usage patterns, real-time cost monitoring, and resource consumption tracking via the [OpenRouter Activity Dashboard](https://openrouter.ai/dashboard/activity).
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Environment Variables to Configure
|
||||
```bash
|
||||
# The skill will handle all configuration automatically
|
||||
# No manual commands needed
|
||||
export OPENROUTER_API_KEY="<your-openrouter-api-key>"
|
||||
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
|
||||
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
|
||||
export ANTHROPIC_API_KEY="" # Important: Must be explicitly empty
|
||||
```
|
||||
|
||||
### Shell Profile Locations
|
||||
Add to one of these files:
|
||||
- `~/.bashrc` for Bash
|
||||
- `~/.zshrc` for Zsh
|
||||
- `~/.config/fish/config.fish` for Fish
|
||||
|
||||
**Important**: Do NOT add these to a project-level `.env` file - Claude Code's native installer does not read standard `.env` files.
|
||||
|
||||
### Verification
|
||||
Run `/status` inside Claude Code to verify:
|
||||
```
|
||||
/status
|
||||
```
|
||||
|
||||
Expected output:
|
||||
```
|
||||
Auth token: ANTHROPIC_AUTH_TOKEN
|
||||
Anthropic base URL: https://openrouter.ai/api
|
||||
```
|
||||
|
||||
## API Configuration
|
||||
|
||||
### Base URL
|
||||
```
|
||||
https://openrouter.ai/api
|
||||
```
|
||||
|
||||
### Authentication
|
||||
OpenRouter API key (get from https://openrouter.ai/keys)
|
||||
|
||||
### Provider Priority
|
||||
**Critical**: Set **Anthropic 1P** as top priority provider for maximum compatibility with Claude Code.
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
@@ -29,39 +81,119 @@ Helps users configure and enable OpenRouter as the AI provider in Claude Code by
|
||||
"Set up OpenRouter as my AI provider"
|
||||
"Enable OpenRouter in Claude Code"
|
||||
"Configure OpenRouter for Claude Code"
|
||||
"Connect Claude Code to OpenRouter"
|
||||
```
|
||||
|
||||
## Configuration File Location
|
||||
## How It Works
|
||||
|
||||
The skill updates the Claude Code configuration file with:
|
||||
- OpenRouter API key
|
||||
- Default model (arcee-ai/trinity-mini:free)
|
||||
- Provider settings
|
||||
### Direct Connection
|
||||
Claude Code speaks its native protocol directly to OpenRouter when `ANTHROPIC_BASE_URL` is set to `https://openrouter.ai/api`. No local proxy server is required.
|
||||
|
||||
## Supported Models
|
||||
### Anthropic Skin
|
||||
OpenRouter's "Anthropic Skin" behaves exactly like the Anthropic API, handling model mapping and passing through advanced features like "Thinking" blocks and native tool use.
|
||||
|
||||
Default: `arcee-ai/trinity-mini:free`
|
||||
### Billing
|
||||
Billed using OpenRouter credits. Usage (including reasoning tokens) appears in the OpenRouter dashboard.
|
||||
|
||||
You can configure any other OpenRouter model by modifying the configuration.
|
||||
## Important Notes
|
||||
|
||||
### Previous Anthropic Login
|
||||
If previously logged in to Claude Code with Anthropic, run `/logout` in a Claude Code session to clear cached credentials before OpenRouter configuration takes effect.
|
||||
|
||||
### Explicit Empty API Key
|
||||
`ANTHROPIC_API_KEY` must be set to an empty string (`""`), not unset. If unset (null), Claude Code may fall back to default behavior and authenticate with Anthropic servers directly.
|
||||
|
||||
### Shell Profile Persistence
|
||||
Environment variables should be added to your shell profile for persistence across sessions.
|
||||
|
||||
### Claude Code Models
|
||||
When using Claude Code through OpenRouter, you access Anthropic models including Claude 3.5 Sonnet, Claude 3 Opus, and Claude 3 Haiku.
|
||||
|
||||
## Advanced Features
|
||||
|
||||
### Cost Tracking Statusline
|
||||
Download statusline scripts from [openrouter-examples repository](https://github.com/openrouter/openrouter-examples) and add to `~/.claude/settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"statusLine": {
|
||||
"type": "command",
|
||||
"command": "/path/to/statusline.sh"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### GitHub Action Integration
|
||||
```yaml
|
||||
- name: Run Claude Code
|
||||
uses: anthropics/claude-code-action@v1
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.OPENROUTER_API_KEY }}
|
||||
env:
|
||||
ANTHROPIC_BASE_URL: https://openrouter.ai/api
|
||||
```
|
||||
|
||||
### Agent SDK Integration
|
||||
The Anthropic Agent SDK uses the same environment variables for OpenRouter integration.
|
||||
|
||||
## Security Notes
|
||||
|
||||
- The skill handles API keys securely
|
||||
- Stores credentials with appropriate file permissions
|
||||
- Follows best practices for credential management
|
||||
- API keys are stored in shell environment with appropriate file permissions
|
||||
- OpenRouter does not log source code prompts unless you explicitly opt-in to prompt logging
|
||||
- See [OpenRouter Privacy Policy](https://openrouter.ai/privacy) for details
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter issues:
|
||||
- Verify your API key is correct
|
||||
- Check configuration file permissions
|
||||
- Ensure Claude Code has write access to configuration directory
|
||||
- Test with a simple query to verify the connection
|
||||
### Auth Errors
|
||||
- Ensure `ANTHROPIC_API_KEY` is set to empty string (`""`)
|
||||
- Check that environment variables are set in shell profile (not just current session)
|
||||
- Restart terminal after updating shell profile
|
||||
|
||||
### Context Length Errors
|
||||
- Break tasks into smaller chunks
|
||||
- Start a new session
|
||||
|
||||
### Connection Issues
|
||||
- Verify OpenRouter API key is correct
|
||||
- Check all environment variables are set correctly
|
||||
- Run `/status` to verify configuration
|
||||
- Check [OpenRouter Activity Dashboard](https://openrouter.ai/dashboard/activity) for requests appearing
|
||||
|
||||
### Previous Credentials
|
||||
- Run `/logout` to clear cached Anthropic credentials
|
||||
- Restart Claude Code after environment variable changes
|
||||
|
||||
## Example Workflow
|
||||
|
||||
1. User requests: "Configure OpenRouter for Claude Code"
|
||||
2. Skill prompts for API key
|
||||
3. Skill updates configuration file
|
||||
4. Skill verifies configuration
|
||||
5. User can now use Claude Code with OpenRouter
|
||||
2. Skill prompts for OpenRouter API key
|
||||
3. Skill adds environment variables to shell profile
|
||||
4. Skill reminds user to restart terminal
|
||||
5. User restarts terminal and runs `claude`
|
||||
6. User runs `/status` to verify configuration
|
||||
7. User can now use Claude Code with OpenRouter's failover and analytics
|
||||
|
||||
## Configuration File Location
|
||||
|
||||
Environment variables are added to shell profile:
|
||||
- `~/.bashrc`, `~/.zshrc`, or `~/.config/fish/config.fish`
|
||||
|
||||
Claude Code settings (optional):
|
||||
- `~/.claude/settings.json` (for statusline)
|
||||
|
||||
## Supported Models
|
||||
|
||||
Anthropic models accessed through OpenRouter:
|
||||
- Claude 3.5 Sonnet
|
||||
- Claude 3 Opus
|
||||
- Claude 3 Haiku
|
||||
|
||||
Model selection depends on Claude Code configuration and OpenRouter model routing settings.
|
||||
|
||||
## Related Resources
|
||||
|
||||
- [OpenRouter Claude Code Integration Guide](https://openrouter.ai/docs/guides/claude-code-integration)
|
||||
- [OpenRouter Activity Dashboard](https://openrouter.ai/dashboard/activity)
|
||||
- [OpenRouter API Keys](https://openrouter.ai/keys)
|
||||
- [OpenRouter Examples Repository](https://github.com/openrouter/openrouter-examples)
|
||||
- [Anthropic Agent SDK](https://github.com/anthropics/anthropic-sdk-typescript)
|
||||
Reference in New Issue
Block a user