Blog / OpenRouter

Best AI Coding Agents That Work With OpenRouter (2026)

Autopilot, OpenCode, Kilo Code, Cline, Aider, OpenHands, Codex CLI, Claude Code and Cursor with your own OpenRouter key: setup, sandboxing and where the key ends up.

Best AI coding agents that work with OpenRouter

If you want a coding agent that works with OpenRouter and lets you bring your own models, the strongest options are Autopilot, which uses OpenRouter as its default provider, and the open-source agents with a native OpenRouter provider: OpenCode, Kilo Code, Cline and Aider. OpenHands supports it through its LLM settings, and Codex CLI through a custom provider in its config. Claude Code and Cursor can be pointed at OpenRouter too, with caveats. The choice comes down to where the agent runs commands and where your OpenRouter key ends up.

This guide covers how to connect each one, checked against each tool's docs and OpenRouter's own guides. Last reviewed October 2026.

At a glance

Agent Licence How it connects to OpenRouter Built-in sandbox
Autopilot MIT Native: sign in with OpenRouter, live model catalog Subagents run in Hotcell sandboxes; the main agent asks before mutating commands
OpenCode MIT Native provider via /connect No; allow/ask/deny permissions
Kilo Code MIT Native provider in settings, or OPENROUTER_API_KEY Yes, OS sandbox, off by default
Cline Apache-2.0 Native provider in settings No; approval for every edit and command
Aider Apache-2.0 --model openrouter/... with OPENROUTER_API_KEY No
OpenHands MIT OpenRouter provider in LLM settings Yes, Docker sandbox recommended
Codex CLI Apache-2.0 Custom provider in ~/.codex/config.toml Yes, OS sandbox on by default
Claude Code Proprietary OpenRouter's Anthropic-compatible endpoint Yes, OS sandbox, off by default
Cursor Proprietary OpenAI key override plus custom base URL (beta) Sandboxed terminal commands in some modes

Autopilot

Autopilot is our terminal coding agent, and OpenRouter is its default model provider. It supports about 25 other providers too, from Anthropic and OpenAI to local Ollama, but OpenRouter is where it does the most: billed cost per turn and sandboxed subagents only work there. On first run you choose Sign in with OpenRouter, approve it in the browser, and a key is created and saved for you; you can also paste an existing key or set OPENROUTER_API_KEY.

npm install -g autopilot-ai
autopilot

The model picker is OpenRouter's live catalog, so any model OpenRouter lists is available, including free ones, and /model switches mid-session. Two things set it apart for OpenRouter users. First, it shows what OpenRouter actually billed for each turn, with /cost totals by session, day and month. Second, it only routes to upstream providers that support everything it sends, tool calls above all, and pins each session to one provider so prompt caching keeps working. If you'd rather not use OpenRouter, KIMIFLARE_BASE_URL and KIMIFLARE_API_KEY point it at any OpenAI-compatible endpoint, including a local llama.cpp or Ollama server.

For larger tasks, Autopilot hands research to read-only subagents, each in its own Hotcell sandbox. Those subagents never see your OpenRouter key: Hotcell keeps it on the host and gives each sandbox a short-lived, spend-capped token. The main agent runs on your machine and asks before each mutating command in its default mode.

OpenCode

OpenRouter is a built-in provider. Create a key in the OpenRouter dashboard, run /connect in OpenCode, search for OpenRouter and paste the key, then pick a model with /models. The key is stored in ~/.local/share/opencode/auth.json. You can add models or set per-model provider routing in opencode.json. OpenCode has no OS-level sandbox; it relies on permissions, and most default to allow. See OpenCode's provider docs.

Kilo Code

In the VS Code extension, open Settings, go to the Providers tab, add OpenRouter and enter your key; the extension saves it to kilo.json. In the Kilo CLI, export OPENROUTER_API_KEY=... works, or reference the variable in kilo.json. Provider routing options go in the config file rather than the UI. The Kilo CLI is a fork of OpenCode. Kilo has an optional OS sandbox (Seatbelt on macOS, bubblewrap on Linux) that you turn on in settings or with /sandbox. See Kilo's OpenRouter docs.

Cline

Click the settings icon in the Cline panel, choose OpenRouter as the API provider, paste your key and pick a model. Every file edit and terminal command asks for your approval unless you enable auto-approve, and checkpoints let you roll back. There's no sandbox for commands in the VS Code extension. See Cline's OpenRouter docs.

Aider

Aider reaches OpenRouter through LiteLLM:

export OPENROUTER_API_KEY=<key>
aider --model openrouter/<provider>/<model>
aider --list-models openrouter/      # see what's available

You can also put the key in .env or .aider.conf.yml, and set OpenRouter provider routing in .aider.model.settings.yml. If requests fail, Aider's docs suggest checking your OpenRouter privacy settings. There's no sandbox: commands run on your machine after you confirm them. See Aider's OpenRouter docs.

OpenHands

Open Settings > LLM, choose OpenRouter as the provider, select a model, enter your key and save the profile. For models not in the list, use the Advanced tab with an openrouter/ prefix. OpenHands recommends running the agent in its Docker sandbox; a process mode without container isolation also exists. Its main repository now ships as Agent Canvas. See OpenHands' OpenRouter docs.

Codex CLI

Codex supports custom model providers in the user-level ~/.codex/config.toml (not the per-project file). OpenRouter's guide recommends this shape:

model_provider = "openrouter"
model = "openai/<model>"

[model_providers.openrouter]
name = "openrouter"
base_url = "https://openrouter.ai/api/v1"

[model_providers.openrouter.auth]
command = "sh"
args = ["-c", "echo $OPENROUTER_API_KEY"]

Use full model slugs with the provider prefix. Codex's OS sandbox (Seatbelt on macOS, bubblewrap on Linux) is on by default, with network access off in workspace-write mode. Codex is built around OpenAI's models, so check that the non-OpenAI model you choose handles its tool calls well.

Claude Code

Claude Code can talk to OpenRouter through OpenRouter's Anthropic-compatible endpoint. Per OpenRouter's guide:

export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""   # must be explicitly empty

Run /logout first if you're signed in with an Anthropic account, then /status to confirm. Two caveats: OpenRouter says this is only guaranteed with Anthropic as the upstream provider, and Anthropic doesn't support routing Claude Code to non-Claude models through any gateway. In practice it's a way to pay for Claude through OpenRouter, not a way to run any model. Claude Code's sandbox exists but is off by default; turn it on with /sandbox.

Cursor

Cursor's own docs list API keys only for OpenAI, Anthropic, Google, Azure and Bedrock. OpenRouter's Cursor guide, marked beta, uses the OpenAI key slot: paste your OpenRouter key, turn on Override OpenAI Base URL, set it to https://openrouter.ai/api/v1/cursor, then add models by ID. The limits are significant. Tab completion always uses Cursor's own models, Auto and Composer may not use your key, and according to Cursor, every request still goes through Cursor's servers, where Zero Data Retention doesn't apply to your own keys.

Where your OpenRouter key ends up

An OpenRouter key can spend money on any model, so it's worth knowing who can read it.

In most of these tools, the key sits in an environment variable or a config file on your machine, and the agent runs shell commands as your user. A command the agent runs, including one triggered by a prompt injection in a file or web page, can usually read it. Claude Code's docs say this outright: subprocesses inherit its environment, including secrets, unless you set CLAUDE_CODE_SUBPROCESS_ENV_SCRUB or mask credentials in its sandbox settings. In Codex, check shell_environment_policy so the key isn't passed to commands. With Cursor, the key also passes through Cursor's servers on every request.

Three habits help with any tool. Use a separate OpenRouter key for agents, set a credit limit on it in the OpenRouter dashboard, and rotate it if anything looks off. For unattended or parallel runs, go further and keep the key out of the agent's reach: Hotcell holds it on the host and gives each sandbox a token with its own spend cap, which you can revoke on its own. Our guide on stopping coding agents from leaking API keys through subagents covers this in detail.

How to choose

If you want… Pick
OpenRouter as a first-class default, billed cost per turn, sandboxed subagents Autopilot
A popular open-source terminal agent with OpenRouter built in OpenCode
OpenRouter inside VS Code Cline or Kilo Code
A git-first pair programmer Aider
An autonomous agent in a Docker sandbox OpenHands
A strong OS sandbox by default Codex CLI
Claude, billed through OpenRouter Claude Code
Cursor's editor, with some chat models via OpenRouter Cursor (beta)

FAQs

Which coding agents support OpenRouter natively?

Autopilot, OpenCode, Kilo Code, Cline, Aider and OpenHands all have OpenRouter as a built-in provider or documented model prefix. Codex CLI supports it as a custom provider. Claude Code and Cursor connect through endpoint overrides with limitations.

Can I use free OpenRouter models for coding?

Yes, within OpenRouter's free-tier request limits. Autopilot's model picker has a Free section for keys with no credit. Free models vary a lot in tool-calling quality, so test one on a real task before relying on it.

Is bring-your-own-key cheaper than a subscription?

It depends on how much you use. With your own key you pay OpenRouter's per-token prices plus its fee on credit purchases, and you can pick cheaper models for routine work. Heavy users of one model family may find a flat subscription cheaper.

Can I use local models instead of OpenRouter?

Most of these agents also accept an OpenAI-compatible endpoint, so you can point them at a local server such as Ollama or llama.cpp. In Autopilot, pick Ollama or LM Studio as the provider (installed models are discovered automatically), or set KIMIFLARE_BASE_URL to any other server's /v1 URL.