Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

OpenRouter

Access Claude, GPT-4, Llama, Mistral and 200+ AI models through a unified API. Switch between providers without changing your code.

What is the Autohand OpenRouter integration?

The Autohand OpenRouter integration connects the coding agent to models routed through one OpenRouter API account. It uses a single API key while keeping the chosen upstream provider and model explicit in Autohand.

Status Available
Requires An OpenRouter API key, account credit, and access to the selected routed model.
Configure with Put your key in openrouter.apiKey, set provider to openrouter, and choose a provider-qualified model ID available in OpenRouter.
Best for Switching among hosted model providers through one API connection.

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
  • OpenRouter’s own routing through the openrouter/auto model ID
  • Single API key for all providers
  • Live model list: the /model picker fetches the models your key can use

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

The CLI reads the key from openrouter.apiKey in your config file. It does not read an OPENROUTER_API_KEY environment variable. Save the key and provider with autohand config set:

autohand config set provider openrouter
autohand config set openrouter.apiKey "sk-or-v1-xxxxxxxxxxxx"
autohand config set openrouter.model "anthropic/claude-sonnet-5"

Verify your configuration:

# Browse provider, model and other settings interactively
autohand config

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

Inside a session, /status shows the active provider and model.

CLI configuration

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

{
  "provider": "openrouter",
  "openrouter": {
    "apiKey": "sk-or-v1-xxxxxxxxxxxx",
    "model": "anthropic/claude-sonnet-5"
  }
}

The value of apiKey is used as written. The CLI does not expand ${VAR} placeholders, so keep the config file out of version control.

Configuration options

Option Description Default
apiKey Your OpenRouter API key -
model Model ID to use anthropic/claude-sonnet-5
baseUrl OpenRouter API endpoint https://openrouter.ai/api/v1
contextWindow Context window in tokens for a model the catalogue does not describe From model metadata

The CLI sets response length per request and sends its own attribution headers to OpenRouter. There are no maxTokens, temperature, siteUrl or siteName config keys; use --temperature to set sampling temperature for a run.

Available models

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

Anthropic Claude

Model ID Context Best for
anthropic/claude-sonnet-5 1M Complex coding, analysis (CLI default)
anthropic/claude-3.5-sonnet 200K Fast, high-quality code
anthropic/claude-3-opus 200K Most capable reasoning
anthropic/claude-3-haiku 200K Quick tasks, low cost

OpenAI GPT

Model ID Context Best for
openai/gpt-4o 128K Multimodal, fast
openai/gpt-4-turbo 128K Complex reasoning
openai/gpt-4o-mini 128K Cost-effective
openai/o1-preview 128K Advanced reasoning

Google Gemini

Model ID Context Best for
google/gemini-pro-1.5 1M Large context tasks
google/gemini-flash-1.5 1M Fast, large context

Open-source models

Model ID Context Best for
meta-llama/llama-3.1-405b 128K Most capable open model
meta-llama/llama-3.1-70b 128K Strong open model
mistralai/mixtral-8x22b 64K Efficient MoE
deepseek/deepseek-coder 128K Code generation
qwen/qwen-2.5-coder-32b 128K Multilingual code

Switch models

# Set default model
autohand config set openrouter.model "anthropic/claude-sonnet-5"

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

# Switch during a session (opens the model picker)
/model

/model opens an interactive picker and ignores any argument typed after it.

Features

Model switching instead of fallback

The CLI sends each request to the one model in openrouter.model. It has no fallback list. If a model is unavailable, pick another with /model, or use --profile to keep a second configuration ready.

Cost tracking

Monitor your usage and costs:

# In a session: token activity, sessions and usage
/usage

# Check your OpenRouter balance (export the key in your shell first)
curl -H "Authorization: Bearer $YOUR_OPENROUTER_KEY" \
  https://openrouter.ai/api/v1/auth/key

Model routing

Let OpenRouter choose a model for each request with its Auto Router model ID. There is no Autohand route option.

{
  "openrouter": {
    "model": "openrouter/auto"
  }
}

Prompts and context

Autohand builds the system prompt itself and sends it to OpenRouter, which converts it for the upstream provider. To change the prompt, use --sys-prompt or --append-sys-prompt, not provider settings.

The CLI manages context length itself: it reads the model’s context window from the catalogue (or openrouter.contextWindow) and compacts the conversation as it fills. There are no transforms, maxContextTokens or truncateStrategy options.

Best practices

  • Keep the config file private: the key is stored in ~/.autohand/config.json as written. Never commit it to version control.
  • Keep a second model ready: save an alternative in a config profile and switch with --profile if a model is unavailable.
  • Match model to task: Use Claude for coding, GPT-4o for multimodal, Gemini for large context.
  • Monitor costs: Check usage regularly with /usage and your OpenRouter dashboard.
Task openrouter.model
Coding anthropic/claude-sonnet-5
Hardest reasoning anthropic/claude-opus-5
Let OpenRouter choose openrouter/auto

Troubleshooting

Common issues

Issue Solution
Invalid API key Verify key at openrouter.ai/keys
Model unavailable Pick another model with /model or --model
Rate limited Add delay between requests or upgrade plan
Context too long Use a model with a larger context window, or start a new session with /new
High costs Switch to a more cost-effective model

Check API status

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

# Check your credits (export the key in your shell first)
curl -H "Authorization: Bearer $YOUR_OPENROUTER_KEY" \
  https://openrouter.ai/api/v1/auth/key

Debug mode

# Enable debug logging
AUTOHAND_DEBUG=1 autohand --prompt "Test"

# Or use the debug flag
autohand --debug --prompt "Test"
How do I configure the Autohand OpenRouter integration?

Put your OpenRouter key in openrouter.apiKey in ~/.autohand/config.json (or run autohand config set openrouter.apiKey), set provider to openrouter, and choose a provider-qualified model ID available in OpenRouter. The CLI does not read an OPENROUTER_API_KEY environment variable.

What does the Autohand OpenRouter integration require?

An OpenRouter API key, account credit, and access to the selected routed model.

What limitations should I know about?

Availability, price, latency, privacy terms, and features vary by the upstream model provider and route.

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification