Skip to main content

OpenCode

OpenCode is an open-source AI coding agent for the terminal. Nebul's Inference API is OpenAI-compatible, so you can register it as a custom provider in OpenCode and use any model your project has access to.

Prerequisites

Installation

Install OpenCode using one of the methods below. For Windows, Docker, and other options, see the OpenCode install guide.

bash
1
curl -fsSL https://opencode.ai/install | bash

Configure Nebul

OpenCode stores provider credentials separately from provider configuration. Follow both steps below.

1. Add your API key

  1. Start OpenCode in your project directory:
bash
1
opencode
  1. Run /connect, scroll to Other, and enter a provider ID — for example nebul.
  2. Paste your Nebul API key when prompted.

The provider ID must match the key you use in opencode.json in the next step. Credentials are stored in ~/.local/share/opencode/auth.json.

2. Configure the provider

Create or update opencode.json in your project root (or ~/.config/opencode/opencode.json for a global default). Add Nebul as an OpenAI-compatible provider:

json
12345678910111213141516171819202122
{
"$schema": "https://opencode.ai/config.json",
"model": "nebul/zai-org/GLM-5.1-FP8",
"provider": {
"nebul": {
"npm": "@ai-sdk/openai-compatible",
"name": "Nebul Inference API",
"options": {
"baseURL": "https://api.inference.nebul.io/v1"
},
"models": {
"zai-org/GLM-5.1-FP8": {
"name": "GLM 5.1 FP8",
"limit": {
"context": 128000,
"output": 16384
}
}
}
}
}
}

Replace the model key under models with any model ID from your Model Catalog. Set limit.context and limit.output to match the model's actual capabilities when possible — OpenCode uses these values for context management.

If you used a different provider ID in /connect, replace nebul everywhere in this config with that same ID.

3. Select a model

Inside OpenCode, run:

1
/models

Your Nebul provider and configured models appear in the list. Select the model you want to use, then start coding.

For first-time project setup, run /init to generate an AGENTS.md file that helps OpenCode understand your codebase. See the OpenCode providers documentation for advanced options such as custom headers and environment-variable API keys.

Troubleshooting

  • Provider not listed — Confirm the provider ID in /connect matches the key under provider in opencode.json.
  • Model not found — The model key in config must exactly match the ID Nebul expects. Check the Model Catalog.
  • Connection errors — Verify the base URL is https://api.inference.nebul.io/v1 and that your API key is valid for the active AI Studio project.
info

Config changes may require restarting OpenCode. If a model still misbehaves after updating limits, restart the TUI and run /models again.


Tips

Optional Nebul-specific notes. Everything else — MCPs, plugins, multi-agent setups, config precedence — is covered in the OpenCode docs.

Context & sessions

Long sessions fill up fast. Make sure auto-compaction is enabled:

bash
1
unset OPENCODE_DISABLE_AUTOCOMPACT

Add that to your shell profile to persist it. Use /new and /session to manage separate conversation contexts. Switch models mid-session with /model.

Permissions

OpenCode allows most tool use by default. For daily work, prompt before destructive actions — at minimum set "bash", "edit", "write", and "webfetch" to "ask" in your permission block. See OpenCode config for the full list of keys.

json
12345678910111213141516
"permission": {
read: allow,
glob: allow,
grep: allow,
list: allow,
bash: ask,
edit: ask,
write: ask,
task: ask,
skill: ask,
webfetch: ask,
websearch: ask,
codesearch: ask,
external_directory: ask,
doom_loop: ask
}

Model stack

OpenCode works well with a primary + lightweight model pair. A common Nebul setup:

ModelRole
zai-org/GLM-5.1-FP8Primary — planning, refactoring, tool use
MiniMaxAI/MiniMax-M2.5Fast tasks — set as "small_model"

Add other models from your Model Catalog as needed. Store keys in env vars (NEBUL_API_KEY) and reference them in config with {env:NEBUL_API_KEY} — see custom providers.

Multi-agent workflows (optional)

Plugins like micode and oh-my-opencode split work into roles (planner, implementer, reviewer) and can route each role to a different Nebul model. Install via ~/.config/opencode/package.json, map agents in micode.json, and add the plugin name to "plugin" in opencode.json.

Web search via Nebul

For docs lookup and research, Firecrawl MCP is a good default. Point it at Nebul's endpoint:

json
123456789
"firecrawl": {
"type": "local",
"command": ["npx", "-y", "firecrawl-mcp"],
"enabled": true,
"environment": {
"FIRECRAWL_API_KEY": "{env:FIRECRAWL_API_KEY}",
"FIRECRAWL_API_URL": "https://firecrawl.inference.nebul.io"
}
}

Use Playwright MCP only when you need full browser interaction (logins, SPAs). See OpenCode MCP configuration for setup details.

Project instructions

Run /init to generate a starter AGENTS.md. OpenCode also reads CLAUDE.md automatically. Use these files for stack constraints, test commands, and coding conventions per repo.

Further reading