文章

为 opencode 配置 NVIDIA API key

为 opencode 配置 NVIDIA API key

记录下为 opencode 配置 NVIDIA API key的全过程:

申请账号

申请NVIDIA 账号: http://build.nvidia.com ,先注册,然后点击右上角头像图标,在菜单中选择API keys 进入管理页面,点击 create API key 之后提示需要绑定手机号,+86的国内手机号也可绑定,只不过需要2-3次的重试才能成功。

配置

将下面的内容配置到 ~/.config/opencode/opencode.json 文件,在 ~/.zshrc 里增加 NVIDIA_API_KEY 环境变量即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[matt@matt markIt (main)]$ cat ~/.config/opencode/opencode.json | python3 -m json.tool
{
    "$schema": "https://opencode.ai/config.json",
    "provider": {
        "nvidia": {
            "npm": "@ai-sdk/openai-compatible",
            "name": "NVIDIA NIM",
            "options": {
                "baseURL": "https://integrate.api.nvidia.com/v1",
                "apiKey": "{env:NVIDIA_API_KEY}"
            },
            "models": {
                "z-ai/glm5": {
                    "name": "GLM-5",
                    "limit": {
                        "context": 128000,
                        "output": 16384
                    }
                }
            }
        }
    }
}
本文由作者按照 CC BY 4.0 进行授权