---
title: "OpenCode 中转配置：opencode.json 自定义提供方"
canonical: https://relayswitch.io/zh/guides/opencode
generated: 2026-11-02T11:22:28.624Z
source: https://api.relayswitch.io/v1/catalog
base_url: https://api.relayswitch.io/v1
---

配置教程 · 核对于 2026-10-30

# OpenCode 中转配置

一个 opencode.json 的 provider 块：Base URL、环境变量里的密钥、带 limit 的模型列表，OpenCode 的每一轮从预付余额扣费。

## 配置步骤

1.  把下面的块写入 `~/.config/opencode/opencode.json`（所有项目）或项目根目录的 `opencode.json`（单个项目，冲突时项目文件优先）。
2.  `options.baseURL` 填 `https://api.relayswitch.io/v1`，带 `/v1`；`@ai-sdk/openai-compatible` 在后面拼 `/chat/completions`。
3.  `options.apiKey` 写 `{env:RELAYSWITCH_API_KEY}`，密钥只在环境变量里：`export RELAYSWITCH_API_KEY="sk-relay-你的密钥"`，然后运行 `opencode`。
4.  `models` 的键是模型页上的 id，`limit.context` 和 `limit.output` 是目录里的上下文和最大输出；下面的块已从目录填好。`model` 写成 `provider/模型id`。

json

1`{`

2 `"$schema": "https://opencode.ai/config.json",`

3 `"provider": {`

4 `"relayswitch": {`

5 `"npm": "@ai-sdk/openai-compatible",`

6 `"name": "RelaySwitch",`

7 `"options": {`

8 `"baseURL": "https://api.relayswitch.io/v1",`

9 `"apiKey": "{env:RELAYSWITCH_API_KEY}"`

10 `},`

11 `"models": {`

12 `"claude-sonnet-5-5": {`

13 `"name": "Claude Sonnet 5.5",`

14 `"limit": {`

15 `"context": 1000000,`

16 `"output": 128000`

17 `}`

18 `},`

19 `"claude-opus-5-5": {`

20 `"name": "Claude Opus 5.5",`

21 `"limit": {`

22 `"context": 1000000,`

23 `"output": 128000`

24 `}`

25 `},`

26 `"gpt-5.5": {`

27 `"name": "GPT-5.5",`

28 `"limit": {`

29 `"context": 1050000,`

30 `"output": 128000`

31 `}`

32 `},`

33 `"deepseek-v4-pro": {`

34 `"name": "DeepSeek V4 Pro 0423",`

35 `"limit": {`

36 `"context": 1048576,`

37 `"output": 393216`

38 `}`

39 `},`

40 `"kimi-k2.7-code": {`

41 `"name": "Kimi K2.7 Code",`

42 `"limit": {`

43 `"context": 262144,`

44 `"output": 262144`

45 `}`

46 `}`

47 `}`

48 `}`

49 `},`

50 `"model": "relayswitch/claude-sonnet-5-5"`

51`}`

资料来源：OpenCode 的 [Providers](https://opencode.ai/docs/providers) 与 [Config](https://opencode.ai/docs/config) 文档（读取于 2026-10-30）。

## 推荐模型

id 照抄到模型字段。价格渲染时读取自目录；人民币为参考价，计费以美元为准。

| 模型 | 开发商 | 输入 / 百万 | 输出 / 百万 |
| --- | --- | --- | --- |
| [Claude Sonnet 5.5](https://relayswitch.io/zh/models/claude-sonnet-5-5)claude-sonnet-5-5 | Anthropic | $1.20≈ ¥8.14 | $3.00≈ ¥20.36 |
| [Claude Opus 5.5](https://relayswitch.io/zh/models/claude-opus-5-5)claude-opus-5-5 | Anthropic | $2.80≈ ¥19.00 | $10.00≈ ¥67.86 |
| [GPT-5.5](https://relayswitch.io/zh/models/gpt-5.5)gpt-5.5 | OpenAI | $1.80≈ ¥12.21 | $9.00≈ ¥61.07 |
| [DeepSeek V4 Pro 0423](https://relayswitch.io/zh/models/deepseek-v4-pro)deepseek-v4-pro | DeepSeek | $0.792≈ ¥5.37 | $2.376≈ ¥16.12 |
| [Kimi K2.7 Code](https://relayswitch.io/zh/models/kimi-k2.7-code)kimi-k2.7-code | Moonshot AI | $0.426≈ ¥2.89 | $1.7936≈ ¥12.17 |

美元 / 百万 tokens，人民币参考价按 ECB 2026-10-30 汇率

## 一次会话多少钱

一次 40 轮的 OpenCode 任务：每轮发送 80,000 tokens 的缓存上下文、2,000 新输入 tokens，返回 1,500 输出 tokens。这个大小是假设；控制台的用量页显示每次请求的真实 tokens 和费用。

| 模型 | 一次会话 |
| --- | --- |
| DeepSeek V4 Pro 0423deepseek-v4-pro | $0.2904≈ ¥1.97 |
| Kimi K2.7 Codekimi-k2.7-code | $0.4143≈ ¥2.81 |
| Claude Sonnet 5.5claude-sonnet-5-5 | $0.516≈ ¥3.50 |
| GPT-5.5gpt-5.5 | $1.20≈ ¥8.12 |
| Claude Opus 5.5claude-opus-5-5 | $1.30≈ ¥8.85 |

按目录实时价计算；人民币参考价按 ECB 2026-10-30 汇率。

## 验证是否接通

先用 curl 列出密钥能调用的模型 id，再在工具里发第一条消息。

bash

1`curl https://api.relayswitch.io/v1/models \`

2 `-H "Authorization: Bearer sk-relay-你的密钥"`

再按工具发请求的方式发一条：

bash

1`export RELAYSWITCH_API_KEY="sk-relay-你的密钥"`

2`curl -i https://api.relayswitch.io/v1/chat/completions \`

3 `-H "Authorization: Bearer $RELAYSWITCH_API_KEY" \`

4 `-H "Content-Type: application/json" \`

5 `-d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "回复 ok"}]}'`

两条都通，剩下的问题就在工具的字段里。请求几秒内出现在控制台的用量页。

常见问题

## 常见问题

OpenCode 接入时最常见的五个问题。

打开控制台

一分钟内拿到密钥

[获取密钥](https://app.relayswitch.io/console)

或发邮件至 [hello@relayswitch.io](mailto:hello@relayswitch.io)

### 

### 

### 

### 

### 

相关页面

-   [全部配置教程](https://relayswitch.io/zh/guides)
-   [文档](https://relayswitch.io/zh/docs)
-   [充值](https://relayswitch.io/zh/pay)
-   [每日真实模型检测](https://relayswitch.io/zh/proof)
-   [模型与价格](https://relayswitch.io/zh/models)
-   [English guide](https://relayswitch.io/guides/opencode)

## 在 OpenCode 里用一个密钥调用全部模型

USDT 充值，按 token 预付，无订阅。Base URL https://api.relayswitch.io/v1。

[模型与价格](https://relayswitch.io/zh/models)[获取密钥](https://app.relayswitch.io/console)

