Overview

OpenRouter provides a single API to access models from multiple providers. When integrated with Autohand, you get:

  • Access to 200+ models from Anthropic, OpenAI, Google, Meta, and more
  • Automatic fallback when a model is unavailable
  • Cost optimization with model routing
  • Single API key for all providers
  • Real-time model availability and pricing

Default provider: OpenRouter is the default provider for Autohand CLI, giving you immediate access to the best models without additional configuration.

Setup

Get started with OpenRouter in minutes.

Get your API key

  1. Go to openrouter.ai and create an account
  2. Navigate to Keys in your dashboard
  3. Click Create Key and copy your API key

Configure Autohand

Set your API key using environment variable or config file:

# Set environment variable (recommended)
export OPENROUTER_API_KEY="sk-or-v1-xxxxxxxxxxxx"

# Or configure via CLI
autohand config set openrouter.apiKey "sk-or-v1-xxxxxxxxxxxx"

Verify your configuration:

# Check current provider and model
autohand config get provider
autohand config get model

# Test with a simple prompt
autohand --prompt "Hello, which model are you?"

CLI configuration

Configure OpenRouter in your ~/.autohand/config.json:

{
  "provider": "openrouter",
  "openrouter": {
    "apiKey": "${OPENROUTER_API_KEY}",
    "model": "nvidia/nemotron-3-super-120b-a12b:free",
    "fallbackModels": [
      "anthropic/claude-3.5-sonnet",
      "openai/gpt-4o"
    ],
    "maxTokens": 4096,
    "temperature": 0.7,
    "siteUrl": "https://your-app.com",
    "siteName": "Your App"
  }
}

Configuration options

OptionDescriptionDefault
apiKeyYour OpenRouter API key-
modelDefault model to usenvidia/nemotron-3-super-120b-a12b:free
fallbackModelsModels to try if primary is unavailable[]
maxTokensMaximum tokens in response4096
temperatureResponse randomness (0-2)0.7
siteUrlYour app URL for rankings-
siteNameYour app name for rankings-

Available models

OpenRouter provides access to models from all major providers. Here are the recommended ones for coding:

Anthropic Claude

Model IDContextBest for
nvidia/nemotron-3-super-120b-a12b:free200KComplex coding, analysis
anthropic/claude-3.5-sonnet200KFast, high-quality code
anthropic/claude-3-opus200KMost capable reasoning
anthropic/claude-3-haiku200KQuick tasks, low cost

OpenAI GPT

Model IDContextBest for
openai/gpt-4o128KMultimodal, fast
openai/gpt-4-turbo128KComplex reasoning
openai/gpt-4o-mini128KCost-effective
openai/o1-preview128KAdvanced reasoning

Google Gemini

Model IDContextBest for
google/gemini-pro-1.51MLarge context tasks
google/gemini-flash-1.51MFast, large context

Open-source models

Model IDContextBest for
meta-llama/llama-3.1-405b128KMost capable open model
meta-llama/llama-3.1-70b128KStrong open model
mistralai/mixtral-8x22b64KEfficient MoE
deepseek/deepseek-coder128KCode generation
qwen/qwen-2.5-coder-32b128KMultilingual code

Switch models

# Set default model
autohand config set model "nvidia/nemotron-3-super-120b-a12b:free"

# Use a specific model for one session
autohand --model "openai/gpt-4o"

# Switch during a session
/model openai/gpt-4o

Features

Model fallback

Configure fallback models for automatic failover:

{
  "openrouter": {
    "model": "nvidia/nemotron-3-super-120b-a12b:free",
    "fallbackModels": [
      "anthropic/claude-3.5-sonnet",
      "openai/gpt-4o",
      "google/gemini-pro-1.5"
    ]
  }
}

Cost tracking

Monitor your usage and costs:

# View session costs
/stats

# Check account balance
curl -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  https://openrouter.ai/api/v1/auth/key

Model routing

Let OpenRouter choose the best model for your query:

{
  "openrouter": {
    "model": "openrouter/auto",
    "route": "fallback"
  }
}
RouteBehavior
fallbackTry models in order until one succeeds
cheapestUse the cheapest available model
fastestUse the fastest available model

Provider transforms

OpenRouter handles provider-specific features automatically:

System prompts

System prompts are converted to the correct format for each provider:

{
  "openrouter": {
    "transforms": ["middle-out"],
    "systemPrompt": "You are an expert software engineer."
  }
}

Context handling

Long conversations are automatically truncated to fit model limits:

{
  "openrouter": {
    "maxContextTokens": 100000,
    "truncateStrategy": "middle-out"
  }
}

Best practices

  • Use environment variables: Never commit API keys to version control.
  • Set fallback models: Ensure availability with multiple fallback options.
  • Match model to task: Use Claude for coding, GPT-4o for multimodal, Gemini for large context.
  • Monitor costs: Check usage regularly with /stats command.
  • Use site attribution: Set siteUrl and siteName for model leaderboards.

Recommended configurations

Coding tasks

{
  "openrouter": {
    "model": "nvidia/nemotron-3-super-120b-a12b:free",
    "temperature": 0.3,
    "maxTokens": 8192
  }
}

Creative tasks

{
  "openrouter": {
    "model": "anthropic/claude-3-opus",
    "temperature": 0.9,
    "maxTokens": 4096
  }
}

Large codebase analysis

{
  "openrouter": {
    "model": "google/gemini-pro-1.5",
    "maxContextTokens": 500000
  }
}

Troubleshooting

Common issues

IssueSolution
Invalid API keyVerify key at openrouter.ai/keys
Model unavailableConfigure fallback models
Rate limitedAdd delay between requests or upgrade plan
Context too longUse a model with larger context or enable truncation
High costsSwitch to a more cost-effective model

Check API status

# List available models
curl https://openrouter.ai/api/v1/models

# Check your credits
curl -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  https://openrouter.ai/api/v1/auth/key

Debug mode

# Enable verbose logging
AUTOHAND_DEBUG=true autohand --prompt "Test"

# View request/response details
autohand --verbose