ホーム 暮らし Using OpenRouter models with Codex CLI

Using OpenRouter models with Codex CLI

藤崎 健人 藤崎 健人 • 更新: • 公開: • 読了約 5 分
目次

I have summarized how to use OpenRouter models with "Codex CLI".

1. Introduction

n29e6b0929678

In this article, I will introduce how to use OpenRouter models from "Codex CLI".

OpenRouter is a service that allows you to use various AI models through a common API. The configuration is set up to basically use the standard GPT models of Codex CLI, and call open models via OpenRouter only when necessary.

The main use case is for evaluating the performance of open models.

2. Preparing the OpenRouter API Key

(1) Log in to OpenRouter.

(2) Add credits via "Top-left menu -> Credits".

(3) Obtain an API key via "Top-left menu -> API Keys".

(4) Add the API key to the OPENROUTER_API_KEY environment variable on your PC.
For Mac, add the following to ~/.zshrc.

export OPENROUTER_API_KEY="sk-or-..."


3. Editing the Codex CLI configuration file

(1) Add the following settings to "~/.codex/config.toml".

[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
env_key = "OPENROUTER_API_KEY"
wire_api = "responses"

The key point is not to specify model_provider = "openrouter".

If you specify this, Codex CLI will be configured to use OpenRouter even during normal startup. Since I want to operate with "usually GPT, OpenRouter only for verification," I am only registering OpenRouter as a provider.

4. Starting Codex CLI

(1) Start Codex CLI as usual.
OpenRouter will not be used, and the default (such as GPT-5.5) will be used.

codex

(2) Start Codex CLI with options.
Only for this startup, I will use z-ai/glm-5.2 from OpenRouter.

codex \
  -c 'model_provider="openrouter"' \
  -m 'z-ai/glm-5.2'

However, the Codex app is a subcommand for launching the desktop application, and -m / --model cannot be specified.



同じカテゴリの記事

藤崎 健人

芸能取材歴10年のデスク。所属事務所の公式リリース、番組公式サイト、配信サービスの告知を一次情報として採用し、裏付けの取れない内容は記事にしていません。

おすすめの関連記事