TLDR - You can use any OpenRouter model with Claude Code via y-router, either locally or with their hosted version. Set environment variables to override the API endpoint and youโ€™re good to go.

How to use any OpenRouter model with Claude Code

Claude Code is an Anthropic product that uses the Anthropic API format. OpenRouter uses the OpenAI API format, so we need a router to convert the requests. Hereโ€™s a straightforward guide on how to connect Claude Code with OpenRouter.

Step 1: Use a router

Because Claude Code is an Anthropic product - it uses the Anthropic API format. OpenRouter uses the OpenAI API format so we need a router to convert the requests. Thereโ€™s a couple different routers on Github but I prefer y-router for a couple reasons:

  1. Its extremely simple to run locally (just a docker compose up -d)
  2. It has a free hosted version that you can use for Github Actions
  3. Itโ€™s extremely easy to setup your own hosted version via Cloudflare

I run this locally using

git clone https://github.com/luohy15/y-router.git
cd y-router
docker compose up -d

Step 2: Set the required environment variables

You will need to set the following environment variables before you run the claude command. Iโ€™m using z-ai/glm-4.5-air for the small model since itโ€™s fast enough for most day-to-day tasks, and z-ai/glm-4.5 for when I need more reasoning power.

# this is the local port that y-router is running on
export ANTHROPIC_BASE_URL="http://localhost:8787"
# using auth token allows you to use CC without needing to login
# you can get this from OpenRouter
export ANTHROPIC_AUTH_TOKEN="sk-or-..."
# choose the "small" model
export ANTHROPIC_SMALL_FAST_MODEL=z-ai/glm-4.5-air
# chose the "large" model
export ANTHROPIC_MODEL=z-ai/glm-4.5

Step 3: Run Claude Code

When you run claude, you should see something like

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โœป Welcome to Claude Code!                         โ”‚
โ”‚                                                   โ”‚
โ”‚   /help for help, /status for your current setup  โ”‚
โ”‚                                                   โ”‚
โ”‚   cwd: /Users/ishandhanani/Desktop/vcs/inboxy     โ”‚
โ”‚                                                   โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚
โ”‚                                                   โ”‚
โ”‚   Overrides (via env):                            โ”‚
โ”‚                                                   โ”‚
โ”‚   โ€ข API Base URL: http://localhost:8787           โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

And when you run /model you should see your OpenRouter model selected.

Github Actions with OpenRouter

Claude Code has a really solid set of default github actions that you can setup in your repo using /install-github-actions. You can easily adapt it to use the OpenRouter models by adding in the env section. Hereโ€™s what Iโ€™m using in my projects:

---
- name: Run Claude Code Review
  id: claude-review
  uses: anthropics/claude-code-action@v1
  env:
    ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
    ANTHROPIC_MODEL: z-ai/glm-4.5
    ANTHROPIC_SMALL_FAST_MODEL: z-ai/glm-4.5-air
  with:
    anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
    prompt: |
      Insert good prompt here

In your github action secrets, you will need to set the following:

ANTHROPIC_API_KEY: "sk-or-..."
ANTHROPIC_BASE_URL: "https://cc.yovy.app" # this is the shared y-router instance
ANTHROPIC_CUSTOM_HEADERS: "x-api-key: sk-or-..."