> ## Documentation Index
> Fetch the complete documentation index at: https://docs.llmeasy.ru/llms.txt
> Use this file to discover all available pages before exploring further.

# VS Code Codex 插件自定义模型接入 LLMEasy 指南

> 在 VS Code 的 Codex 插件中使用自定义 Base URL 和 API Key。

VS Code 中的 Codex 插件本身不需要单独填写一套 `Base URL` 和 API Key。它会读取本机 Codex 配置，因此你需要在 Codex 的 `config.toml` 中配置 LLMEasy provider。

<Info>
  如果你在 VS Code 设置里没有看到 `Base URL` 或 API Key 输入框，这是正常的。VS Code Codex 插件的模型请求配置应通过 Codex 本地配置完成。
</Info>

## 前置条件

* 已安装 VS Code
* 已安装 **Codex - OpenAI's coding agent** 插件
* 已获取 LLMEasy API Key（<a href={"https://www.llmeasy.ru/register"}>注册并获取</a>）
* 已从<a href={"https://www.llmeasy.ru/pricing"}>模型广场</a>复制 **GPT 分组**下可用的模型 ID

<Warning>
  不要把 API Key 写进项目文件、`AGENTS.md`、`.env` 示例文件或公开仓库。下面的配置只应保存在你本机的 Codex 配置目录中。
</Warning>

## 配置方式

<Tabs>
  <Tab title="推荐：使用 Setup 弹窗">
    创建 API Key 后，控制台会弹出 **Setup** 弹窗。你可以在弹窗中复制 **API Key** 和 **Base URL**，并选择 Codex 相关配置方式。

    <Steps>
      <Step title="选择 Codex">
        在 **Available tools** 中选择 **Codex**。
      </Step>

      <Step title="选择配置方式">
        你可以选择：

        * **One-click Bash Configuration**：复制命令到本机终端执行，适合快速配置。
        * **CC Switch Integration**：导入到 CC Switch，适合统一管理多个工具。
        * **Manual Configuration**：复制 API Key 和 Base URL，手动写入 `config.toml`。
      </Step>

      <Step title="重启 VS Code">
        配置写入后，重启 VS Code，或执行 **Developer: Reload Window**，让 Codex 插件重新读取本机配置。
      </Step>
    </Steps>
  </Tab>

  <Tab title="手动配置">
    <Steps>
      <Step title="找到 config.toml">
        Codex 的配置文件通常位于：

        | 系统            | 配置文件                                    |
        | ------------- | --------------------------------------- |
        | macOS / Linux | `~/.codex/config.toml`                  |
        | Windows       | `C:\Users\YOUR_USER\.codex\config.toml` |
        | Windows + WSL | WSL 内的 `~/.codex/config.toml`           |

        如果文件不存在，可以手动新建。
      </Step>

      <Step title="写入 LLMEasy provider">
        将下面配置添加到 `config.toml`。如果文件中已经有同名字段，请合并配置，不要重复写多个 `model_provider`。

        ```toml theme={null}
        model_provider = "custom"
        model = "gpt-5.5"
        review_model = "gpt-5.4"
        model_reasoning_effort = "high"
        model_context_window = 1000000
        model_auto_compact_token_limit = 900000
        windows_wsl_setup_acknowledged = true

        [model_providers]
        [model_providers.custom]
        name = "LLM Easy"
        base_url = "https://www.llmeasy.ru/v1"
        wire_api = "responses"
        requires_openai_auth = true
        experimental_bearer_token = "YOUR_API_KEY"
        request_max_retries = 4
        stream_max_retries = 8
        stream_idle_timeout_ms = 300000
        supports_websockets = false
        ```

        将 `YOUR_API_KEY` 替换为你的 LLMEasy API Key。
      </Step>

      <Step title="确认关键字段">
        重点检查这几项：

        | 字段                          | 应填写                         |
        | --------------------------- | --------------------------- |
        | `base_url`                  | `https://www.llmeasy.ru/v1` |
        | `wire_api`                  | `responses`                 |
        | `model`                     | 从 **GPT 分组**复制的模型 ID        |
        | `experimental_bearer_token` | 你的 LLMEasy API Key          |

        <Warning>
          VS Code Codex 插件场景下，不建议把 `auth.json` 改成 API Key 结构。`auth.json` 用于保留 Codex 官方登录态；第三方 API Key 应放在 `experimental_bearer_token` 中。
        </Warning>
      </Step>

      <Step title="重启 VS Code">
        修改完成后，关闭当前 Codex 会话，并重启 VS Code。

        也可以在命令面板执行：

        ```text theme={null}
        Developer: Reload Window
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## 为什么这里要保留官方登录态？

VS Code Codex 插件依赖 Codex 的应用侧能力，例如插件界面、会话管理和 VS Code 集成。因此推荐保留官方登录态，同时让模型请求走 LLMEasy。

这组配置中：

| 配置                                           | 作用                                                      |
| -------------------------------------------- | ------------------------------------------------------- |
| `requires_openai_auth = true`                | 保留 Codex 官方登录态                                          |
| `experimental_bearer_token = "YOUR_API_KEY"` | 使用 LLMEasy API Key 发起模型请求                               |
| `base_url = "https://www.llmeasy.ru/v1"`     | 将模型请求发送到 LLMEasy 的 OpenAI-compatible / Responses API 入口 |

## 验证配置

完成配置后，在 VS Code 中打开 Codex 插件，发送一条简单测试消息。

如果能正常回复，说明配置已生效。

如果请求失败，按顺序检查：

1. `base_url` 是否为 `https://www.llmeasy.ru/v1`
2. `wire_api` 是否为 `responses`
3. `experimental_bearer_token` 是否已替换为你的真实 API Key
4. `model` 是否来自<a href={"https://www.llmeasy.ru/pricing"}>模型广场</a>的 **GPT 分组**
5. 是否存在旧的 `OPENAI_API_KEY` 或 `OPENAI_BASE_URL` 环境变量覆盖了配置
6. VS Code 是否已重启或 Reload Window

## 相关文档

* [Codex 接入 LLMEasy 指南](/zh/ai-tools/codex)
* [如何在使用第三方 API 的同时保留 Codex 登录态？](/zh/faq/codex/official-login-third-party-api)
* [如何配置 Codex CLI 的 config.toml？](/zh/faq/codex/config-toml)
* [Codex CLI 中 model\_provider、base\_url 和 wire\_api 是什么？](/zh/faq/codex/model-provider-base-url-wire-api)
