macbook 配置claude code 通过copilot api调用 claude模型及gpt模型

张开发
2026/5/30 6:49:17 15 分钟阅读
macbook 配置claude code 通过copilot api调用 claude模型及gpt模型
Mac 配置 Claude Code CLI 调用 GitHub Copilot 踩坑实录最终完美版背景公司配备 GitHub Copilot国内大模型效果不理想又没有 Claude 账号因此希望通过Claude Code CLI界面直接调用 GitHub Copilot 背后的GPT / Gemini 系列模型。一、环境准备1. 安装 Homebrew国内镜像使用国内镜像安装速度更快避免官方源超时问题/bin/zsh-c$(curl-fsSLhttps://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)2. 安装 Node.jsbrewinstallnode3. 安装 Claude Code CLInpminstall-ganthropic-ai/claude-code二、macOS 钥匙串证书问题关键大坑macOS 证书存储在钥匙串KeychainNode.js 默认不读取系统证书会导致 HTTPS 请求报错unable to get local issuer certificate。1. 清理污染的 TLS 环境变量unsetNODE_EXTRA_CA_CERTS SSL_CERT_FILE SSL_CERT_DIR OPENSSL_CONF NODE_OPTIONS2. 测试 GitHub 连通性node-erequire(https).get(https://github.com,rconsole.log(github,r.statusCode)).on(error,econsole.error(e.message))3. 导出系统钥匙串证书为 pem 格式mkdir-p$HOME/.certssecurity find-certificate-a-p/System/Library/Keychains/SystemRootCertificates.keychain$HOME/.certs/macos-ca-bundle.pemsecurity find-certificate-a-p/Library/Keychains/System.keychain$HOME/.certs/macos-ca-bundle.pemsecurity find-certificate-a-p$HOME/Library/Keychains/login.keychain-db$HOME/.certs/macos-ca-bundle.pem4. 让 Node 加载系统证书exportNODE_EXTRA_CA_CERTS$HOME/.certs/macos-ca-bundle.pem5. 再次测试连通性node-erequire(https).get(https://github.com,rconsole.log(github,r.statusCode)).on(error,econsole.error(e.message))6. 永久写入环境变量echoexport NODE_EXTRA_CA_CERTS$HOME/.certs/macos-ca-bundle.pem$HOME/.zshrcsource$HOME/.zshrc三、安装并启动 copilot-api1. 安装 copilot-api直接安装大概率报证书不受信任先配置 npm 证书npmconfigsetcafile /etc/ssl/cert.pem再安装npminstall-gcopilot-api2. 启动 copilot-api关键开启 Claude Code 兼容copilot-api start --claude-code默认启动在http://localhost:4141--claude-code核心作用自动开启Anthropic/v1/messages协议兼容内置格式转换无需任何第三方路由工具直接支持 Gemini / GPT 全系列模型3. 查看支持的模型列表浏览器访问http://localhost:4141/v1/models四、配置 Claude Code CLI你指定的模型1. 创建配置文件mkdir-p~/.claudecat~/.claude/settings.jsonEOF { env: { ANTHROPIC_BASE_URL: http://localhost:4141, ANTHROPIC_AUTH_TOKEN: dummy, ANTHROPIC_MODEL: gemini-3.1-pro-preview, ANTHROPIC_SMALL_FAST_MODEL: gpt-5.4, DISABLE_NON_ESSENTIAL_MODEL_CALLS: 1, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 1 } } EOF或mkdir-p~/.claudecat~/.claude/settings.jsonEOF { env: { ANTHROPIC_BASE_URL: http://localhost:4141, ANTHROPIC_AUTH_TOKEN: dummy, ANTHROPIC_MODEL: claude-opus-4.6, ANTHROPIC_SMALL_FAST_MODEL: claude-sonnet-4.6, DISABLE_NON_ESSENTIAL_MODEL_CALLS: 1, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 1 } } EOF2. 启动 Claude Codeclaude五、为什么之前会报错 4001. 报错信息-- POST /v1/messages?betatrue ERROR Failed to create chat completions Response { status: 400 ... }2. 根本原因未加--claude-code时copilot-api 只提供OpenAI 格式Claude Code 发送的是Anthropic 格式协议不兼容 → 直接 4003. 真正解决方案copilot-api start --claude-code该参数已内置协议转换不需要任何第三方路由工具。六、最终可用流程最简版启动 copilot-api开启 Claude 兼容copilot-api start --claude-code配置 Claude Code 指向本地 4141直接运行claude七、总结macOS Node.js 证书问题必须处理否则安装/联网失败copilot-api --claude-code是核心关键原生支持 Anthropic 协议无需额外格式转换工具无需 Claude 账号模型名称必须与http://localhost:4141/v1/models严格一致可直接使用gemini-3.1-pro-preview gpt-5.4等高端模型你当前使用的模型配置主模型gemini-3.1-pro-preview快速模型gpt-5.4

更多文章