Skip to content

OpenCode ​

引言 ​

OpenCode 是一个开源代理,帮助您在终端、IDE 或桌面端编写代码,以下内容将介绍如何在Linux/Mac、Windows环境中如何接入飞算JavaAI 的coding Plan 。

支持的协议 ​

OpenAI协议:https://www.feisuanyz.com/v1/chat/completions
Anthropic Messages 协议:https://www.feisuanyz.com/v1/messages
OpenAI新一代对话协议:https://www.feisuanyz.com/v1/responses
查询可用模型列表:https://www.feisuanyz.com/v1/models

OpenCode 安装 ​

  1. 安装或更新 Node.js(v18.0 或更高版本)。
  2. 在终端中执行以下命令安装 OpenCode。
npm install -g opencode-ai

npm install -g opencode-ai

  1. 如果报错没有权限(Error: EACCES: permission denied, mkdir '/opt/homebrew/lib/node_modules/opencode-ai),可以加上sudo
sudo npm install -g opencode-ai
  1. 安装完成后执行命令查看版本号,有版本号输出则说明安装成功.
opencode -v

配置Token Plan ​

  1. 进入以下路径,创建配置文件opencode.json

进入以下路径 ​

macOS、Linux:

~/.config/opencode

Windows:

C:\Users\您的用户名\.config\opencode\
  1. 创建opencode.json文件#macOS、Linux
touch opencode.json
  1. 将以下配置文件更新apikey后复制保存到opencode.json文件中 填入具体配置如下:
name:feisuancodingplanconfig
apiKey:可在控制台api keys获取
baseURL:https://www.feisuanyz.com/v1/chat/completions
models:支持模型列表,可在 支持模型 模块查看

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "feisuancodingplanconfig": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "feisuancodingplanconfig",
      "options": {
        "baseURL": "https://www.feisuanyz.com/v1/chat/completions",
        "apiKey": "可在控制台api keys获取"
      },
      "models": {
        "glm-5.1": {
          "name": "GLM-5.1",
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 32000
            }
          },
          "limit": {
            "context": 198000,
            "output": 131072
          }
        }
      }
    }
  }
}

开始使用OpenCode ​

  1. 执行命令,运行opencode
opencode
  1. 输入/models,选择配置的模型进行使用

邮箱:chendw@feisuanyz.com 邮编:518000 地址:深圳市前海深港合作区前湾一路1号A栋201室