OpenCode
为 OpenCode 配置 CodeNodex provider 和模型访问。
准备 Key
公开教程中的 YOUR_API_KEY 仅为占位符。登录后可基于你已有的 API Key 生成真实配置。
使用我的 API Key 生成配置配置端点
该工具使用 OpenAI 兼容 协议。请将下方地址填入客户端的 Base URL 字段。
https://your-domain.example/v1
CLI 一键配置(推荐)
安装 CodeNodex CLI 后,可登录账号、校验 API Key,并准备匹配的本机配置。
安装 CodeNodex CLI
macOS / Linux
curl -fsSL https://token.codenodex.com/cli/install.sh | bashWindows PowerShell
iex "& { $(irm https://token.codenodex.com/cli/install.ps1) }"登录并配置 OpenCode
登录后选择 API Key。CLI 会校验可用性,并生成可复制到 OpenCode 的配置。
Terminal
codenodex login -o "https://token.codenodex.com"
codenodex setup --client opencode手动复制配置
如不使用 CLI,请将 YOUR_API_KEY 替换为你自己的 API Key。实际使用时,优先使用登录后的专属配置生成器。
手动配置示例
opencode.json
{
"provider": {
"openai": {
"options": {
"baseURL": "https://your-domain.example/v1",
"apiKey": "YOUR_API_KEY"
},
"models": {
"gpt-5.2": {
"name": "GPT-5.2",
"limit": {
"context": 400000,
"output": 128000
},
"options": {
"store": false
},
"variants": {
"low": {},
"medium": {},
"high": {},
"xhigh": {}
}
},
"gpt-5.4": {
"name": "GPT-5.4",
"limit": {
"context": 1050000,
"output": 128000
},
"options": {
"store": false
},
"variants": {
"low": {},
"medium": {},
"high": {},
"xhigh": {}
}
},
"gpt-5.5": {
"name": "GPT-5.5",
"limit": {
"context": 1050000,
"output": 128000
},
"options": {
"store": false
},
"variants": {
"low": {},
"medium": {},
"high": {},
"xhigh": {}
}
},
"gpt-5.4-mini": {
"name": "GPT-5.4 Mini",
"limit": {
"context": 400000,
"output": 128000
},
"options": {
"store": false
},
"variants": {
"low": {},
"medium": {},
"high": {},
"xhigh": {}
}
},
"gpt-5.3-codex": {
"name": "GPT-5.3 Codex",
"limit": {
"context": 400000,
"output": 128000
},
"options": {
"store": false
},
"variants": {
"low": {},
"medium": {},
"high": {},
"xhigh": {}
}
},
"gpt-5.3-codex-spark": {
"name": "GPT-5.3 Codex Spark",
"limit": {
"context": 128000,
"output": 32000
},
"options": {
"store": false
},
"variants": {
"low": {},
"medium": {},
"high": {},
"xhigh": {}
}
}
}
}
},
"agent": {
"build": {
"options": {
"store": false
}
},
"plan": {
"options": {
"store": false
}
}
},
"$schema": "https://opencode.ai/config.json"
}验证连通性
执行以下命令,成功返回模型列表即表示 API Key 和端点配置可用。
Terminal
curl "https://your-domain.example/v1/models" -H "Authorization: Bearer YOUR_API_KEY"