FIM Gate 文档
应用集成

OpenCode

为 OpenCode 配置 FIM Gate 的 OpenAI、Anthropic 与第三方模型来源。

OpenCode 是开源的终端 AI 编程助手。接入 FIM Gate 时建议同时配置三组 provider:内置的 openai、anthropic,以及一个承载其余第三方模型的自定义 provider。安装细节可参考 OpenCode 官方文档。

安装

任选一种方式:

# 官方安装脚本
curl -fsSL https://opencode.ai/install | bash

# npm
npm install -g opencode-ai

# Yarn
yarn global add opencode-ai

# Bun
bun install -g opencode-ai

# Homebrew
brew install anomalyco/tap/opencode

编写配置文件

  1. 打开(或新建)配置文件:

    • macOS / Linux:~/.config/opencode/opencode.json
    • Windows:Users\<用户名>\.config\opencode\opencode.json
  2. 写入以下内容(JSON 不支持注释,复制后请勿保留任何注释):

    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "anthropic": {
          "name": "Anthropic",
          "options": {
            "baseURL": "https://api.gate.fim.ai"
          }
        },
        "openai": {
          "options": {
            "baseURL": "https://api.gate.fim.ai/v1"
          },
          "models": {
            "gpt-5.2": {
              "options": {
                "include": ["reasoning.encrypted_content"],
                "store": false,
                "reasoningEffort": "high",
                "textVerbosity": "high",
                "reasoningSummary": "auto"
              }
            },
            "gpt-5.2-codex": {
              "options": {
                "include": ["reasoning.encrypted_content"],
                "store": false
              }
            }
          }
        },
        "fimgate": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "FIM Gate",
          "options": {
            "baseURL": "https://api.gate.fim.ai/v1"
          },
          "models": {
            "deepseek-v3.2": {
              "name": "DeepSeek V3.2"
            }
          }
        }
      }
    }

几点说明:

  • 为什么拆三个 provider? OpenCode 对内置的 OpenAI、Anthropic provider 做了专门优化,如果把所有模型都塞进一个通用 provider,部分能力可能用不上或体验变差。OpenAI / Claude 系列走内置 provider,其余模型放进 fimgate 这个自定义 provider。
  • GPT 系列模型的 include: ["reasoning.encrypted_content"] 与 store: false 请按示例保留,否则可能无法正常调用。
  • anthropic 走 Claude 原生协议,baseURL 填 https://api.gate.fim.ai(不带 /v1);openai 与自定义 provider 走 OpenAI 兼容协议,baseURL 填 https://api.gate.fim.ai/v1。
  • fimgate.models 下的键是模型 ID,可按需增删,可用模型以价格页为准。

录入 API Key

三组 provider 需要分别录入同一个 FIM Gate Key(在控制台创建):

  1. 终端执行 opencode auth login,选择 OpenAI → Manually enter API Key,粘贴你的 Key。
  2. 再次执行 opencode auth login,选择 Anthropic → Manually enter API Key,粘贴同一个 Key。
  3. 第三次执行 opencode auth login,选择列表最底部的 Other,在 Provider ID 处输入 fimgate(必须与配置文件中的 provider 键名一致),再粘贴 Key。

开始使用

opencode
  • 首次在某个项目中使用时,先在会话里执行 /init 初始化。
  • 用 /models 命令切换模型。
  • 按 TAB 在 plan / build 模式间切换:建议先用 plan 生成计划,确认后再用 build 写代码。

可选增强:Oh My OpenCode

Oh My OpenCode 为 OpenCode 提供预设 agent 与插件。

安装

启动 opencode 后,在会话中粘贴并发送:

Install and configure oh-my-opencode by following the instructions here:
https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/refs/heads/master/docs/guide/installation.md

安装过程中会被问到三个问题:

  1. 是否有 Claude Pro / Max 订阅——有封号风险,一般不建议接入订阅;
  2. 是否有 ChatGPT Plus / Pro 订阅——按实际情况选择;
  3. 是否集成 Google Gemini——有 Gemini 订阅可选 Yes,否则选 No。

回答后它会自动安装对应插件,把你的订阅接入 OpenCode。

安装后的配置

安装完成后,opencode.json 中会多出 plugin 字段(如 ["oh-my-opencode", "opencode-antigravity-auth@1.3.0"]),若选择了集成 Gemini,还会出现一个 google provider,内含 antigravity-gemini-3-pro-high、antigravity-gemini-3-pro-low、antigravity-gemini-3-flash 等模型条目。完整的模型映射见 opencode-antigravity-auth 文档。

同时会生成 ~/.config/opencode/oh-my-opencode.json,常用配置项:

  • google_auth:使用 antigravity 插件时需设为 false;

  • claude_code 下的 mcp / commands / skills / agents / hooks:设为 false 可阻止 OpenCode 自动读取 Claude Code 的本地配置;

  • agents:为内置的各个 agent 指定模型,例如:

    {
      "agents": {
        "Sisyphus": { "model": "openai/gpt-5.2" },
        "oracle": { "model": "openai/gpt-5.2" },
        "librarian": { "model": "anthropic/claude-sonnet-4-5-20250929" },
        "explore": { "model": "anthropic/claude-sonnet-4-5-20250929" },
        "frontend-ui-ux-engineer": { "model": "google/antigravity-gemini-3-pro-high" },
        "document-writer": { "model": "google/antigravity-gemini-3-flash" },
        "multimodal-looker": { "model": "google/antigravity-gemini-3-flash" }
      }
    }

    各 agent 分工:Sisyphus 负责协调与简单任务,oracle 处理疑难问题与调试,librarian 查找库资料,explore 探索代码仓库,其余分别面向前端设计、文档编写与多模态识别。

注意:若集成了 Google Gemini,需要先执行 opencode auth login 并选择 Google 完成授权登录,相关模型才可用。