Skip to content

Command-line agents

OpenCode

Add NoviaHub to OpenCode as a custom provider and write code with NoviaHub models.

OpenCode is an open source AI coding agent, available as a terminal interface, a desktop app and an IDE extension. Its config file can add “custom providers”, which it calls over an OpenAI-compatible API, so it can use models on NoviaHub.

  • A NoviaHub API key. If you don’t have one yet, see API keys.
  • Funds in your account. Calls are charged to your balance by usage.

Use any of the official install methods:

终端窗口
curl -fsSL https://opencode.ai/install | bash
  1. Store the API key in the environment variable NOVIAHUB_API_KEY. The config file only names the variable; it never holds the key itself.

    终端窗口
    # Add this line to the end of ~/.zshrc or ~/.bashrc, then open a new terminal
    export NOVIAHUB_API_KEY="sk-..."
  2. Edit the config file ~/.config/opencode/opencode.json (create it if needed) and add:

    ~/.config/opencode/opencode.json
    {
    "$schema": "https://opencode.ai/config.json",
    "provider": {
    "noviahub": {
    "npm": "@ai-sdk/openai-compatible",
    "name": "NoviaHub",
    "options": {
    "baseURL": "https://noviahub.com/v1",
    "apiKey": "{env:NOVIAHUB_API_KEY}"
    },
    "models": {
    "deepseek-v4-flash": {
    "name": "deepseek-v4-flash",
    "limit": { "context": 1000000, "output": 384000 }
    },
    "claude-sonnet-5": {
    "name": "claude-sonnet-5",
    "limit": { "context": 1000000, "output": 64000 }
    }
    }
    }
    },
    "model": "noviahub/deepseek-v4-flash"
    }

    What each field means:

    Field Meaning
    noviahub The provider ID. Any name works; you refer to models as noviahub/<model ID>.
    npm @ai-sdk/openai-compatible calls /v1/chat/completions.
    options.baseURL Must include /v1: https://noviahub.com/v1.
    options.apiKey {env:NOVIAHUB_API_KEY} reads the key from the environment variable.
    models The models to use. Each key is a model ID on NoviaHub and must match exactly.
    limit.context / limit.output Per OpenCode’s docs, limit.context is the most input tokens the model accepts and limit.output the most tokens it can generate; OpenCode uses them to work out how much context is left. The example values are the Context and Max output shown on Models & Pricing on 2026-09-28; the page is authoritative.
    model The default model, as <provider ID>/<model ID>.

    To apply the settings to one project only, put the same content in opencode.json at the project root instead.

  3. Run opencode in your project directory.

终端窗口
# List the models configured under the noviahub provider
opencode models noviahub
# Send one message without opening the interface
opencode run -m noviahub/deepseek-v4-flash "Introduce yourself in one sentence."

If you get a reply and the call shows up under Usage Logs in NoviaHub, the setup works.

  • In OpenCode, type /models and pick one.
  • At launch: opencode --model noviahub/claude-sonnet-5 (or -m).
  • Change model in the config file to set the default.

Add a model to models in the config file before using it. This config uses the OpenAI Chat API, so it only works with models that carry the Chat endpoint label under Models & Pricing (every text model had it on 2026-09-28).

  • If a model supports only the Responses API (its page shows Response but not Chat), change that provider’s npm to @ai-sdk/openai.
  • It works without limit, but then OpenCode can’t tell accurately how much context is left.
  • Instead of the config file, you can also run /connect → Other in OpenCode and enter a provider ID and key; the key is saved in ~/.local/share/opencode/auth.json. opencode auth list shows saved keys.

Checked on 2026-09-28: