@aiand/opencode-plugin
v0.1.0
Published
ai& provider plugin for OpenCode — live model catalog + API-key auth via the ai& gateway
Maintainers
Readme
ai& for OpenCode
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
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/[email protected]"— 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.
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. |
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 [email protected]:aiandlabs/aiand-opencode-plugin.git
cd aiand-opencode-plugin
opencode run "say hi in one word" # loads ./src/index.ts directlyTo 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 loaderReleasing
Bump version in package.json, then publish a GitHub Release tagged v<version> — the
Publish workflow builds, smoke-tests, verifies the tag matches package.json, and runs
npm publish with provenance.
Next steps
- Add an OAuth login method as an alternative to API keys.
