# codex-glm-proxy **Repository Path**: jidzhang/codex-glm-proxy ## Basic Information - **Project Name**: codex-glm-proxy - **Description**: 智谱AI GLM模型API适配CodexCLI,可以畅快地在国内使用Codex了 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-30 - **Last Updated**: 2026-05-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: glm, codex, Proxy ## README # Codex GLM 代理 [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) [English](README.md) | **中文** > **声明:** 本项目基于 [JichinX/codex-glm-proxy](https://github.com/JichinX/codex-glm-proxy/) 复制,并在此基础上进行了调试和优化,以提升稳定性和兼容性。 本地代理,将 OpenAI Codex CLI 的 Responses API 格式转换为 Chat Completions 格式,使 Codex 能够使用 **GLM(智谱 AI)** 模型。 ## 特性 - 流式响应 — 实时 SSE 流式输出 - 工具调用 — 支持 `apply_patch`、`exec` 等所有 Codex 工具 - 多轮对话 — 完整保持对话上下文 - 单文件,无外部依赖 ## 快速开始 ### 前置要求 - Python 3.8+ - [GLM API 密钥](https://open.bigmodel.cn/) - 已安装 [OpenAI Codex CLI](https://github.com/openai/codex) ### 1. 启动代理 ```bash git clone https://gitee.com/jidzhang/codex-glm-proxy.git cd codex-glm-proxy export GLM_API_KEY="你的_GLM_API_密钥" python3 proxy.py # 代理运行在 http://localhost:18765 ``` 或使用后台脚本: ```bash ./scripts/start.sh # 后台启动 ./scripts/stop.sh # 停止 ``` ### 2. 配置 Codex CLI 创建 `~/.codex/config.toml`: ```toml model_provider = "glm" model = "glm-5.1" model_catalog_json = "/Users/<你的用户名>/.codex/models.json" [model_providers.glm] name = "GLM via Proxy" base_url = "http://localhost:18765" wire_api = "responses" ``` ### 3. 设置模型目录 将 `models.json` 复制到 `~/.codex/models.json`。 ### 4. 测试 ```bash mkdir test-codex && cd test-codex && git init codex exec "创建一个 Python hello world 程序" --full-auto ``` ## 架构 ``` Codex CLI ──Responses API──▶ 代理 (localhost:18765) ──Chat Completions──▶ GLM API ``` 代理进行双向格式转换: - **请求:** Responses API → Chat Completions(模型名映射、工具格式转换) - **响应:** Chat Completions SSE → Responses API SSE ## 配置说明 ### 环境变量 | 变量 | 默认值 | 说明 | |------|--------|------| | `GLM_API_KEY` | *(无)* | GLM API 密钥(必填) | | `GLM_API_BASE` | `https://open.bigmodel.cn/api/coding/paas/v4` | GLM API 端点 | | `PROXY_PORT` | `18765` | 代理监听端口 | ### 支持的 GLM 模型 `glm-5.1` · `glm-5-turbo` · `glm-5` · `glm-4.7` GLM 模型名直接透传,无需映射。 ### OpenAI 模型映射 当 Codex CLI 请求以下 OpenAI 模型时,自动替换为对应 GLM 模型: | Codex 请求 | 替换为 | |------------|--------| | `gpt-5.5` | `glm-5.1` | | `gpt-5.4` | `glm-5.1` | | `gpt-5.4-mini` | `glm-4.7` | | `gpt-4o` | `glm-5.1` | | `gpt-4o-mini` | `glm-4.7` | 未识别的模型名默认回退到 `glm-5.1`。 ## 管理命令 ```bash ./scripts/start.sh # 后台启动 curl http://localhost:18765/health # 健康检查 tail -f /tmp/codex-glm-proxy.log # 查看日志 ./scripts/stop.sh # 停止 ``` ## 故障排除 **"Streaming complete, sent 0 chunks"** 模型名未识别。在配置中使用已知模型名(如 `glm-5.1`)。 **Codex 循环/重复操作** 工具调用历史处理问题。更新到最新版本的代理。 **Connection refused** 代理未运行。使用 `python3 proxy.py` 或 `./scripts/start.sh` 启动。 **macOS 上 SSL 证书错误** 安装 certifi:`pip install certifi`。 ## 许可证 [MIT](LICENSE) ## Reasoning Effort(推理深度) Codex CLI 支持 reasoning effort 级别(`low` / `medium` / `high` / `xhigh`),用于控制模型回答前的推理深度。 GLM API **不会对任何 effort 值报错**,但测试表明只有 `low`、`medium`、`high` 有实际效果。`xhigh` 被静默视为无效值,推理深度不如 `high`。 **推荐:** 使用 `high` 以获得 GLM 模型的最大推理质量。提供的 `models.json` 中已默认设为 `high`。 详细的测试结果和分析见 [docs/reasoning-effort.md](docs/reasoning-effort.md)。 自行验证: ```bash python3 tests/test_reasoning_effort.py # 默认只测 glm-5.1 python3 tests/test_reasoning_effort.py --all-models # 测试所有 GLM 模型 ```