0
70
近 7 天 3
31.2
生态多维模型
10 天前
2026-08-10
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@aiand/opencode-plugin@0.1.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@aiand/opencode-plugin@0.1.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @aiand/opencode-pluginopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
Add ai& as a provider in OpenCode with a single plugin.
What you get
An ai& provider in OpenCode that:
- Routes to the ai& gateway —
https://api.aiand.com/v1(OpenAI-compatible). - Logs in cleanly —
opencode auth login→ ai& → paste yoursk-...key. - Lists the live catalog — the model picker is populated straight from ai&'s public
/v1/api.json, so new models show up without touching the plugin.
Requires OpenCode (curl -fsSL https://opencode.ai/install | bash).
Install
One line (installs OpenCode if missing, wires up the plugin, and offers to enable web search):
curl -fsSL https://opencode.aiand.com/install.sh | bash
Or do it by hand — reference the npm package in your opencode.json (per-project) or
~/.config/opencode/opencode.jsonc (global) — OpenCode installs it automatically on first run:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@aiand/opencode-plugin"],
"model": "aiand/zai-org/glm-5.2"
}
Then log in and run:
opencode auth login # choose ai& → paste your sk-... key
opencode # TUI
opencode run "say hi in one word" # one-shot
(Non-interactive alternative: export AIAND_API_KEY=sk-... instead of auth login.)
Version pinning: a bare
"@aiand/opencode-plugin"installs the latest version on first run and keeps using that cached copy afterwards. To pin (or force an upgrade), use an explicit version —"@aiand/opencode-plugin@0.1.0"— which OpenCode caches separately per version.
Auth
- Main path:
opencode auth login→ choose ai& → paste yoursk-...key. The key is stored by OpenCode and used for every project. - Alternative (non-interactive / CI):
export AIAND_API_KEY=sk-....
The model picker and catalog populate without a key (/v1/api.json is public); a key is
only needed to actually send a message. Get one at aiand.com.
Web search
OpenCode ships a built-in web search tool (via Exa — free, no API key), but for third-party providers like ai& it's gated behind an environment variable:
export OPENCODE_ENABLE_EXA=1
The installer offers to add this line to your shell profile (~/.zshrc / ~/.bashrc)
for you — it's the "Enable web search?" question. To set it up by hand, add the export line to
your shell profile and open a new terminal (fish: set -Ux OPENCODE_ENABLE_EXA 1).
OpenCode Desktop (GUI): no extra steps — the app sources your login shell's environment at startup, so the same profile line applies. Restart the app after adding it. If your setup somehow doesn't pick it up, launching the app from a terminal where the variable is exported also works.
How it works
The plugin uses two OpenCode hooks:
| Hook | What it does |
|---|---|
config |
fetches ai&'s public /v1/api.json and registers the aiand provider (@ai-sdk/openai-compatible, baseURL) with the live model list injected inline |
auth |
adds the "ai& API Key" login method; injects the stored key as Bearer |
Why inline models (not the
provider.models()hook)? OpenCode only runsprovider.models()for providers already known to models.dev; a brand-new provider's models must be declared in config. Theconfighook runs before OpenCode readscfg.provider, so fetching the catalog there and settingprovider.aiand.modelsis what makes the picker show ai&'s live models.
Configuration
| Env var | Default | Purpose |
|---|---|---|
AIAND_API_KEY |
— | Your ai& API key (alternative to opencode auth login). |
AIAND_BASE_URL |
https://api.aiand.com/v1 |
Override the gateway base URL. |
OPENCODE_ENABLE_EXA |
— | Set to 1 to enable OpenCode's built-in web search (read by OpenCode itself, not the plugin). |
Contributing / local development
The plugin is a single module, src/index.ts. The repo's own opencode.json loads it as a
file plugin, so you can test changes without building or publishing:
git clone git@github.com:aiandlabs/aiand-opencode-plugin.git
cd aiand-opencode-plugin
opencode run "say hi in one word" # loads ./src/index.ts directly
To use your checkout from other projects, reference it by absolute path in your global config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["/absolute/path/to/aiand-opencode-plugin/src/index.ts"]
}
Build and check the published artifact shape (also run in CI):
npm install
npm run build # tsc → dist/
npm run check:dist # asserts the compiled entry satisfies OpenCode's plugin loader
Releasing
Releases are automatic: bump version in package.json and merge to main. The Publish
workflow runs on every push to main; when it sees a version that isn't on npm yet, it
builds, checks the artifact, runs npm publish with provenance, and creates the matching
v<version> GitHub Release. Pushes without a version bump publish nothing.
Next steps
- Add an OAuth login method as an alternative to API keys.