Using OpenRouter With Kilo Code

OpenRouter is an AI platform that provides access to a wide variety of language models from different providers, all through a single API. This can simplify setup and allow you to easily experiment with different models.

Website: https://openrouter.ai/

Getting an API Key

  1. Sign Up/Sign In: Go to the OpenRouter website. Sign in with your Google or GitHub account.
  2. Get an API Key: Go to the keys page. You should see an API key listed. If not, create a new key.
  3. Copy the Key: Copy the API key.

Configuration in Kilo Code

Open Settings (gear icon) and go to the Providers tab to add OpenRouter and enter your API key.

The extension stores this in your kilo.json config file. You can also edit the config file directly — see the CLI tab for the file format.

Supported Transforms

OpenRouter provides an optional "middle-out" message transform to help with prompts that exceed the maximum context size of a model.

The middle-out transform is not exposed as a dedicated UI control in the VS Code extension. To enable it, set transforms on the model's options in your kilo.json config file. Anything under options is forwarded verbatim to the OpenRouter AI SDK as providerOptions.openrouter:

{
  "provider": {
    "openrouter": {
      "models": {
        "anthropic/claude-sonnet-4-20250514": {
          "options": {
            "transforms": ["middle-out"],
          },
        },
      },
    },
  },
}

Provider Routing

OpenRouter can route to many different inference providers. This can be controlled directly via OpenRouter's provider routing parameter.

Provider routing is not exposed as dedicated UI controls in the VS Code extension. To configure it, set OpenRouter's provider routing fields under the model's options in your kilo.json config file. Everything under options is forwarded to the OpenRouter AI SDK as providerOptions.openrouter, so any field from the OpenRouter provider routing docs can be used.

{
  "provider": {
    "openrouter": {
      "models": {
        "anthropic/claude-sonnet-4-20250514": {
          "options": {
            "provider": {
              "sort": "price", // "price" | "throughput" | "latency"
              "order": ["Anthropic", "Google"], // specific provider preference
              "only": ["Anthropic"], // restrict to listed providers
              "data_collection": "deny", // "allow" | "deny"
              "zdr": true, // zero data retention
            },
          },
        },
      },
    },
  },
}

Omit any field to fall back to your OpenRouter account's default. Fields are passed through without validation — see OpenRouter's docs for the full list of supported values.

Tips and Notes

  • Model Selection: OpenRouter offers a wide range of models. Experiment to find the best one for your needs.
  • Pricing: OpenRouter charges based on the underlying model's pricing. See the OpenRouter Models page for details.
  • Prompt Caching: Some providers support prompt caching. See the OpenRouter documentation for supported models.