# OpenCode

> 全部文档的索引见 [llms.txt](https://ark.volcengine.com/llms.txt)；在任一文档页面地址后追加 `.md` 可获取该页的 Markdown 版本。

OpenCode 是一款开源的 AI 编程代理工具，提供终端界面、桌面应用和 IDE 扩展等多种使用方式。本文介绍如何在 OpenCode 中使用方舟 Coding Plan 企业版。

<span id="d450d315"></span>
# 核心配置

需要获取 Coding Plan 企业版支持的模型、Base URL和专属的 API Key，才能正常使用并抵扣套餐额度。
<span id="2e9b1559"></span>
## **模型配置**

支持以下两种方式配置模型：

**选项：配置 Model Name (配置文件指定)**

在工具配置文件中指定 Model Name，可实时切换模型。支持配置的 Model Name：

> **注意**
>
> 配置 Model Name 时，支持使用全小写格式，同时也支持直接复制 [Coding Plan 企业版页面](https://ark.volcengine.com/region:cn-beijing/openManagement?LLM=%7B%7D&OpenModelVisible=false&advancedActiveKey=enterprise) 中的模型名称。

* `doubao-seed-evolving`
* `doubao-seed-2.1-pro`
* `doubao-seed-2.1-lite`
* `doubao-seed-2.0-mini`
* `glm-5.3` (`glm-latest`)
* `glm-5.3-flash`
* `deepseek-v4.1-flash`
* `deepseek-v4.1-flash-economy`
* `deepseek-v4-flash`
* `deepseek-v4-pro`
* `kimi-k2.8-preview`
* `kimi-k3.1-pro`

> **说明**
>
> Model Name 不支持配置为 `Auto`，如需使用，请通过控制台切换该模式。

**选项：配置 ark-code-latest (控制台管理)**

1. 在配置文件中指定模型为`ark-code-latest`。
2. 通过 [Coding Plan 企业版页面](https://ark.volcengine.com/region:cn-beijing/openManagement?LLM=%7B%7D&OpenModelVisible=false&advancedActiveKey=enterprise) 选择或切换目标模型，切换模型后 3-5 分钟即可生效。
     支持 Auto 模式，通过「效果 + 速度」双维度智能算法自动选择模型。

<span id="d9073615"></span>
## **专属 Base URL**

不同的工具配置的 Base URL 根据兼容的协议会有不同：
* 兼容 Anthropic 接口协议工具：`https://ark.cn-beijing.volces.com/api/coding`
* 兼容 OpenAI 接口协议工具：`https://ark.cn-beijing.volces.com/api/coding/v3`

> **注意**
>
> 请勿使用 `https://ark.cn-beijing.volces.com/api/v3` ，接入会产生额外费用。

<span id="0c1c1bc6"></span>
## **专属 API Key**

[获取专属 API Key](https://ark.volcengine.com/region:cn-beijing/subscription/coding-plan-enterprise/mine)

> **注意**
>
> Coding Plan 企业版专属 API Key 与火山方舟平台的 API Key 不同，请勿混用。

![coding-plan-enterprise-api-key.png](https://arkdocs.tos-cn-beijing.volces.com/images/agent-plan/coding-plan-enterprise-api-key.png)

<span id="2ed8ee84"></span>
# 一、前置操作

需由管理员账号完成以下前置操作后，子账号方可配置并使用编程工具：
1. 购买方舟 Coding Plan 企业版套餐：[一、购买 Coding Plan 企业版](/docs/coding-plan-enterprise-get-started#d061dee7)。
2. 为子账号分配席位：[二、分配席位](/docs/coding-plan-enterprise-get-started#163f6c67)。

<span id="b9f58bb1"></span>
# 二、安装 OpenCode

前提条件：安装 [Node.js 18 或更新版本](https://nodejs.org/en/download/)。
在命令行界面，执行以下命令安装 OpenCode。

```Bash
npm install -g opencode-ai
```

安装结束后，执行以下命令查看安装结果，若显示版本号则安装成功。

```Bash
opencode --version
```

<span id="c807cb71"></span>
# 三、配置 OpenCode

1. 创建并打开 OpenCode 的配置文件。文件路径因系统而异，具体操作如下：

    **选项：macOS/Linux**

    macOS/Linux 系统 OpenCode 配置文件路径：`~/.config/opencode/opencode.json`。
    1. 如果在主目录下没有`.config/opencode`目录，执行以下命令创建目录。

        ```Bash
        mkdir -p ~/.config/opencode
        ```

    2. 创建并打开配置文件。

        ```Bash
        nano ~/.config/opencode/opencode.json
        ```

    **选项：Windows**

    Windows 系统 OpenCode 配置文件路径：`%USERPROFILE%\.config\opencode\opencode.json`。以 CMD 命令行方式为例，操作如下。
    1. 如果当前用户目录下没有`.config\opencode`目录，执行以下命令创建目录。

        ```Bash
        if not exist "%USERPROFILE%\.config\opencode" mkdir "%USERPROFILE%\.config\opencode"
        ```

    2. 创建并打开配置文件。

        ```Bash
        notepad "%USERPROFILE%\.config\opencode\opencode.json"
        ```

2. 编辑 `opencode.json`，需关注的配置信息如下：

    * `<ARK_API_KEY>`：替换为您自己的 [专属 API Key](https://ark.volcengine.com/region:cn-beijing/subscription/coding-plan-enterprise/mine)。
    * `model`：更新为需要使用的模型信息。支持的模型信息参见 [模型配置](/docs/coding-plan-enterprise-ai-opencode#2e9b1559)。

    Coding Plan 兼容 OpenAI 接口协议，支持 Responses API、Chat API。推荐使用 Responses API 的配置，推理效果更好。

    支持的两类 API 仅在 npm 配置上不同：
    * Responses API 配置：`"npm": "@ai-sdk/openai"`
    * Chat API 配置：`"npm": "@ai-sdk/openai-compatible"`

    以配置`ark-code-latest`为例，具体信息如下。

> **注意**
>
> * `glm-5.3`、`glm-5.3-flash`、`deepseek-v4.1-flash`、`deepseek-v4.1-flash-economy`、`deepseek-v4-flash`、`deepseek-v4-pro`、`kimi-k3.1-pro` 支持 1M 上下文窗口用于包含大型代码库的长会话，可以通过 `limit.context` 字段显式指定窗口大小。
> * `provider.volcengine-plan.models`节点下有**两处**（对象键、`name`字段）需**替换为同一 Model Name**，切勿遗漏。
> * 若需开启模型图片理解能力，需在模型配置节点下新增如下配置项：
>
> `"modalities": {"input": ["text", "image"], "output": ["text"]}`

**选项：Responses API**

> **说明**
>
> npm 必须使用 `@ai-sdk/openai`，模型才会使用 Responses API，在 `baseURL` 的基础上自动拼接 `/responses`。

```JSON
{
  "$schema": "https://opencode.ai/config.json",
  "model": "volcengine-plan/ark-code-latest",
  "provider": {
    "volcengine-plan": {
      "npm": "@ai-sdk/openai",
      "name": "Volcano Engine（Responses API）",
      "options": {
        "baseURL": "https://ark.cn-beijing.volces.com/api/coding/v3",
        "apiKey": "<ARK_API_KEY>"
      },
      "models": {
        "ark-code-latest": {
          "name": "ark-code-latest",
          "limit": {
            "context": 256000,
            "output": 32000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-pro": {
          "name": "doubao-seed-2.1-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-evolving": {
          "name": "doubao-seed-evolving",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3": {
          "name": "glm-5.3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3-flash": {
          "name": "glm-5.3-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-latest": {
          "name": "glm-latest",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4-flash": {
          "name": "deepseek-v4-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          }
        },
        "deepseek-v4-pro": {
          "name": "deepseek-v4-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          }
        },
        "deepseek-v4.1-flash": {
          "name": "deepseek-v4.1-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4.1-flash-economy": {
          "name": "deepseek-v4.1-flash-economy",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-lite": {
          "name": "doubao-seed-2.1-lite",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.0-mini": {
          "name": "doubao-seed-2.0-mini",
          "limit": {
            "context": 256000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k2.8-preview": {
          "name": "kimi-k2.8-preview",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k3.1-pro": {
          "name": "kimi-k3.1-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        }
      }
    }
  }
}
```

**选项：Chat API**

> **说明**
>
> npm 必须使用 `@ai-sdk/openai-compatible`，模型才会使用 Chat API，在 `baseURL` 的基础上自动拼接 `/chat/completions`。

```JSON
{
  "$schema": "https://opencode.ai/config.json",
  "model": "volcengine-plan/ark-code-latest",
  "provider": {
    "volcengine-plan": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Volcano Engine（Chat API）",
      "options": {
        "baseURL": "https://ark.cn-beijing.volces.com/api/coding/v3",
        "apiKey": "<ARK_API_KEY>"
      },
      "models": {
        "ark-code-latest": {
          "name": "ark-code-latest",
          "limit": {
            "context": 256000,
            "output": 32000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-pro": {
          "name": "doubao-seed-2.1-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-evolving": {
          "name": "doubao-seed-evolving",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3": {
          "name": "glm-5.3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3-flash": {
          "name": "glm-5.3-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-latest": {
          "name": "glm-latest",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4-flash": {
          "name": "deepseek-v4-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          }
        },
        "deepseek-v4-pro": {
          "name": "deepseek-v4-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          }
        },
        "deepseek-v4.1-flash": {
          "name": "deepseek-v4.1-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4.1-flash-economy": {
          "name": "deepseek-v4.1-flash-economy",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-lite": {
          "name": "doubao-seed-2.1-lite",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.0-mini": {
          "name": "doubao-seed-2.0-mini",
          "limit": {
            "context": 256000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k2.8-preview": {
          "name": "kimi-k2.8-preview",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k3.1-pro": {
          "name": "kimi-k3.1-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        }
      }
    }
  }
}
```

<span id="30a7ef0d"></span>
# 四、启动并使用 OpenCode

1. 启动 OpenCode：

    ```Bash
    opencode
    ```

2. 输入`/models`，选择配置的模型并在 OpenCode 中使用。
