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

# 在 Codex 中使用 LithosAI

> 通过 LiteLLM Responses API 兼容代理，把 Codex 接入 LithosAI。

## 开始之前

在 [API Key](https://console.lithosai.cloud/keys?lang=zh) 页面创建 key，在 [模型](https://console.lithosai.cloud/models?lang=zh) 页面确认模型 ID，然后在启动 Codex 或其本地代理的 shell 里把这个 key 设为环境变量。

```bash theme={null}
export LITHOSAI_API_KEY="your-key"
```

Codex 已经不再支持 Chat Completions。`wire_api = "chat"` 在启动时就会被拒绝，`responses` 是唯一可用的值，所以 Codex 需要通过一个接受 Responses API 请求的代理来访问 LithosAI。

<Warning>
  这是一条兼容路径，不是原生的 Responses API 支持。LiteLLM 能转换常见的文本请求和函数工具请求，但 Responses 独有的工具和元数据不一定能映射到 Chat Completions。如果你的工作流依赖某个特定的 Codex 工具，先验证它可用，再依赖这套配置。
</Warning>

<Steps>
  <Step title="安装 LiteLLM">
    [LiteLLM](https://docs.litellm.ai) 负责把 Responses API 桥接到 Chat Completions。

    ```bash theme={null}
    pip install 'litellm[proxy]'
    ```

    <Warning>
      请安装最新版本。2026 年 3 月，PyPI 上的 LiteLLM 1.82.7 和 1.82.8 曾短暂被替换成[凭据窃取程序](https://docs.litellm.ai/blog/security-update-march-2026)。
    </Warning>
  </Step>

  <Step title="配置代理">
    下面的模型只是示例，不是 LithosAI 的完整模型列表。要换其他模型或速度档位，把 `openai/` 后面的 ID 替换成 [模型](https://console.lithosai.cloud/models?lang=zh) 页面里的 ID。代理的 `model_name` 要和 Codex 的 `model` 设置保持一致。

    给模型加上 `openai/` 前缀，并设置 `use_chat_completions_api`。这样代理会把收到的 `/v1/responses` 请求桥接到 LithosAI 的 `/v1/chat/completions`。

    <Accordion title="LiteLLM 代理配置">
      ```yaml codex.litellm.yaml theme={null}
      model_list:
        - model_name: kimi-k3-fast
          litellm_params:
            model: openai/moonshotai/Kimi-K3-fast
            api_base: https://api.lithosai.cloud/v1
            api_key: os.environ/LITHOSAI_API_KEY
            use_chat_completions_api: true
            additional_drop_params: ["reasoning_effort", "client_metadata"]

      litellm_settings:
        drop_params: true

      general_settings:
        master_key: sk-codex-proxy
      ```
    </Accordion>

    `drop_params` 会丢弃模型不接受的参数，而不是让请求失败。`additional_drop_params` 会去掉 `reasoning_effort`：Codex 会请求推理摘要，LiteLLM 把这个请求放进该字段转发，但格式会被 LithosAI 拒绝；而不带这个字段，Codex 也能正常工作。它还会去掉 `client_metadata`，LithosAI 不接受这个 Chat Completions 参数。`master_key` 是 Codex 发给代理的 token，不是你的 LithosAI key。
  </Step>

  <Step title="启动代理">
    ```bash theme={null}
    litellm --config codex.litellm.yaml --host 127.0.0.1 --port 4000
    ```

    让它保持运行，并确认已经启动。代理持有你的 LithosAI key，所以只绑定在 `127.0.0.1` 上，不要暴露到网络中。

    ```bash theme={null}
    curl http://127.0.0.1:4000/health/liveliness
    ```
  </Step>

  <Step title="让 Codex 连接代理">
    <Accordion title="Codex 配置">
      ```toml ~/.codex/config.toml theme={null}
      model = "kimi-k3-fast"
      model_provider = "lithosai"

      [model_providers.lithosai]
      name = "LithosAI"
      base_url = "http://127.0.0.1:4000/v1"
      env_key = "LITELLM_API_KEY"
      wire_api = "responses"
      requires_openai_auth = false
      ```
    </Accordion>

    `env_key` 指定的是存放代理 `master_key` 的环境变量，所以这个环境变量也要设置。

    ```bash theme={null}
    export LITELLM_API_KEY="sk-codex-proxy"
    codex
    ```
  </Step>
</Steps>

## 问题排查

| 现象 | 原因 |
| - | - |
| `wire_api = "chat"` is no longer supported | `base_url` 直接指向了 LithosAI。改为指向代理。 |
| `/v1/responses` 返回 `404` | 模型条目用的是 `hosted_vllm/`。Codex 需要 `openai/` 加上 `use_chat_completions_api`。 |
| `400`，报错 `No connected db.` | `LITELLM_API_KEY` 和代理的 `master_key` 不一致。LiteLLM 报告的是查找失败，而不是认证错误。 |
| `400`，报错中提到 `reasoning_effort` 和 `Input should be 'none', 'minimal', ...` | 代理配置里缺少 `additional_drop_params: ["reasoning_effort", "client_metadata"]`。 |

所有 Agent 都会遇到的问题见[常见问题](/zh/agent-integrations#常见问题)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.