智能助手网
标签聚合 api

/tag/api

linux.do · 2026-04-18 22:47:42+08:00 · tech

CPA + Codex 配置避坑指南 前言 本文记录了配置 CLI Proxy API (CPA) 与 Codex 集成时遇到的各种坑,希望能帮助后来者少走弯路。 环境信息 系统 : macOS (Apple Silicon) CPA 版本 : v6.9.29 Codex 版本 : 0.121.0 代理工具 : ClashX / Clash Verge 核心问题:502 Bad Gateway 症状 Codex 启动后尝试连接 API 时,反复出现: Unexpected status 502 Bad Gateway: Unknown error, url: http://localhost:8321/v1/responses 根本原因 系统代理拦截了 localhost 请求! ClashX/Clash Verge 等代理工具默认会拦截所有 HTTP 请求,包括 localhost 和 127.0.0.1 。当 Codex 尝试访问本地 CPA 服务时,请求被代理转发,导致: 请求无法直接到达本地服务 代理返回 502 错误 日志中看不到任何请求记录(因为请求根本没到达目标服务) 解决方案 方法 1:设置 NO_PROXY 环境变量(推荐) # 添加到 ~/.zshrc 或 ~/.bashrc export NO_PROXY="localhost,127.0.0.1" # 应用配置 source ~/.zshrc 重要: 必须在新终端中启动 Codex,才能加载新的环境变量。 方法 2:配置代理绕过规则 在 ClashX/Clash Verge 中添加绕过规则,让 localhost 不走代理。 其他常见问题 1. API Key 不匹配 (401 Unauthorized) 症状: Unexpected status 401 Unauthorized: {"error":"Invalid API key"} 原因: Codex 使用了自己的 API key(格式如 sk-sub-Pack6n6X... ),而不是配置文件中的 api_key 。 解决方案: 将 Codex 使用的 key 添加到 CPA 配置中: # ~/cpa-config.yaml api-keys: - "your-custom-key" - "sk-sub-Pack6n6X_yKXdwEwPB2mT0iGkcQyE4IMMHe-kCN7TIy4L-gf" # Codex 的 key 重启 CPA: pkill -f "cpa.*config" ~/.local/bin/cpa -config ~/cpa-config.yaml > /tmp/cpa.log 2>&1 & 2. 端口被占用 症状: Error: listen EADDRINUSE: address already in use 127.0.0.1:8321 原因: 旧的 shim 进程还在运行 LaunchAgent 自动重启服务 解决方案: # 查找占用端口的进程 lsof -nP -iTCP:8321 -sTCP:LISTEN # 停止进程 kill -9 <PID> # 禁用自动启动 launchctl unload ~/Library/LaunchAgents/com.linkunkun.codex.cliproxy-shim.plist 3. 旧版本冲突 症状: Homebrew 安装的旧版本 cliproxyapi 自动重启。 解决方案: # 停止 Homebrew 服务 brew services stop cliproxyapi # 卸载旧版本 brew uninstall cliproxyapi # 清理配置 rm -rf /opt/homebrew/etc/cliproxyapi* rm -f ~/Library/LaunchAgents/homebrew.mxcl.cliproxyapi.plist 4. Shim 是否必需? 答案:不需要! 早期以为需要 shim 来转换请求格式,但实际上: CPA 原生支持 /v1/responses 端点 直接连接 CPA 更简洁高效 推荐配置: # ~/.codex/config.toml [model_providers.custom] name = "custom" wire_api = "responses" base_url = "http://localhost:8317/v1" # 直接连 CPA api_key = "your-api-key" 完整安装步骤 1. 安装 CPA # 下载最新版本 curl -L -o /tmp/cpa.tar.gz https://github.com/router-for-me/CLIProxyAPI/releases/download/v6.9.29/CLIProxyAPI_6.9.29_darwin_arm64.tar.gz # 解压并安装 cd /tmp tar -xzf cpa.tar.gz mkdir -p ~/.local/bin mv cli-proxy-api ~/.local/bin/cpa chmod +x ~/.local/bin/cpa # 添加到 PATH echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc source ~/.zshrc 2. 配置 CPA # 复制示例配置 cp /tmp/config.example.yaml ~/cpa-config.yaml # 编辑配置 vim ~/cpa-config.yaml 关键配置项: port: 8317 # 管理密钥 remote-management: secret-key: "your-admin-password" # API keys api-keys: - "your-api-key" 3. 启动 CPA nohup ~/.local/bin/cpa -config ~/cpa-config.yaml > /tmp/cpa.log 2>&1 & 4. 配置 Codex # ~/.codex/config.toml model_provider = "custom" model = "gpt-5.4" [model_providers.custom] name = "custom" wire_api = "responses" base_url = "http://localhost:8317/v1" api_key = "your-api-key" 5. 配置代理绕过(关键!) # 添加到 ~/.zshrc echo 'export NO_PROXY="localhost,127.0.0.1"' >> ~/.zshrc source ~/.zshrc 6. 测试 # 测试 CPA curl http://localhost:8317/v1/models -H "Authorization: Bearer your-api-key" # 在新终端启动 Codex codex 调试技巧 1. 查看 CPA 日志 tail -f /tmp/cpa.log 2. 查看 Codex 日志 tail -f ~/.codex/log/codex-tui.log 3. 检查端口占用 lsof -nP -iTCP:8317 -sTCP:LISTEN 4. 测试 API 连接 curl -v http://localhost:8317/v1/responses \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-5.4","input":[{"role":"user","content":[{"type":"input_text","text":"test"}]}]}' 5. 检查代理设置 # 查看环境变量 env | grep -i proxy # 查看活动连接 lsof -nP -iTCP | grep codex | grep ESTABLISHED 常见错误排查流程 502 Bad Gateway ↓ 检查是否有代理 (lsof -nP -iTCP | grep codex) ↓ 有代理 → 设置 NO_PROXY ↓ 无代理 → 检查服务是否运行 ↓ 401 Unauthorized ↓ 检查 Codex 使用的 API key (查看日志) ↓ 将 key 添加到 CPA 配置 ↓ 重启 CPA 总结 配置 CPA + Codex 的最大坑就是 系统代理 。记住: 设置 NO_PROXY 环境变量 在新终端启动 Codex 直接连接 CPA,不需要 shim 将 Codex 的 API key 添加到 CPA 配置 遵循这些原则,可以避免 90% 的问题。 参考资源 CPA GitHub CPA 文档 管理界面 最后更新 : 2026-04-18 作者 : 基于实际踩坑经历整理 1 个帖子 - 1 位参与者 阅读完整话题

linux.do · 2026-04-18 22:25:04+08:00 · tech

虽是V0.3版本,但实际上对体验进行了大量完善优化,力求降低AI接入的门槛,为更多人人群带来专注AI体验; 1.独立导入模式支持:支持直接从当前浏览器打开的中转站自动化导入了 插件/备份导入依旧支持,可通过此最佳实践路径补充完善; 2.批量检测模型进一步优化:余额查看、快速对话、模型性能统计(TTFT、TPS、Latency)能力、站点管理 引入站点管理,简化每次导入逻辑,批量检测更加方便 3.高级代理网关,支持优先级自定义、自动切换、故障转移、多渠道队列、整流修正功能; 支持claude客户端使用openai等模型、自行排序队列、RPM限定等高级设置 mini侧栏可实时观看哪些节点被调度中、实时检测调用性能 4.优化体验:自定义key、标签备注、侧栏实时队列监控、全平台适配已完成 如有疏漏不佳体验、欢迎继续发掘指正问题 开源地址在初始发布贴: https://linux.do/t/topic/1828809 1 个帖子 - 1 位参与者 阅读完整话题

linux.do · 2026-04-18 21:09:24+08:00 · tech

new_api_panic: Panic detected, error: runtime error: invalid memory address or nil pointer dereference. Please submit a issue here: GitHub - QuantumNous/new-api: A unified AI model hub for aggregation & distribution. It supports cross-converting various LLMs into OpenAI-compatible, Claude-compatible, or Gemini-compatible formats. A centralized gateway for personal and enterprise model management. 🍥 · GitHub | Upstream: {“error”:{“message”:“Panic detected, error: runtime error: invalid memory address or nil pointer dereference. Please submit a issue here: https://github.com/Calcium-Ion/new-api",“type”:"new_api_panic ”}} 2 个帖子 - 2 位参与者 阅读完整话题

linux.do · 2026-04-18 21:09:14+08:00 · tech

抽奖主题: newapi 爽登密钥 奖品详情: [newapi 密钥一份*2]: 几个闲置的Plus号上到newapi里 可用5.4。不限额度(号限流就限流) 抽2个名额爽登 ,日常应该是够了,啥时候封就无了 活动时间: 开始时间:2026年4月18日 21:00 截止时间:2026年4月19日 00:00 参与方式: 在本帖下回复任意内容即可参与喵~ 抽奖规则: 每位用户仅允许参与一次。 使用 官方抽奖工具 随机抽取 1 名中奖者。 注意事项: 本活动将在活动截止时间后手动/自动关闭回帖。 中奖者将在活动结束后由机器人或手动公布,我会通过 论坛私信 发送卡密及兑换教程。 120 个帖子 - 118 位参与者 阅读完整话题

hnrss.org · 2026-04-18 18:11:09+08:00 · tech

I got tired of maintaining two files that describe the same thing: an OpenAPI spec for documentation and a Postman collection for testing. They always drift. Someone updates the spec, forgets the collection. A new engineer joins and runs outdated tests against an endpoint that was changed two months ago. VolcAPI lets you define test scenarios directly inside your OpenAPI spec using a custom extension (v-functional-test), then run them from the CLI. Single source of truth. It's a Go binary no runtime, no node_modules. The goal is for it to drop into GitHub Actions with zero friction once JUnit XML output lands (in progress). Repo: https://github.com/aliamerj/volcapi This is early alpha. GET/POST/PUT/DELETE work, response validation works, environment configs work. CI output formats are the next thing I'm building. Honest question for the HN crowd: is the "spec as test suite" concept something you'd actually use, or do you prefer keeping tests separate from the spec? I've gone back and forth on this and would genuinely like to hear from people who've felt this pain. Comments URL: https://news.ycombinator.com/item?id=47814655 Points: 1 # Comments: 1