Docs menu

Docs / Integrations

Use Cent AI with OpenCode

Add Cent AI as an OpenAI-compatible provider in opencode.json and pick a model by name.

Last updated

Tested with OpenCode v2.3.0 on 2026-11-14


Your setup

Fills in YOUR_API_KEY in the code on this page. The key stays in this tab: it is never sent and never saved.

OpenCode connects to Cent AI as an OpenAI-compatible provider at https://api.cent-ai.dev/v1 and adds /chat/completions itself.

Prerequisites

  • A Cent AI account with balance. See Quickstart.
  • An API key from Keys. It looks like cai_<secret> and is shown once.
  • OpenCode installed. The version we tested is at the end of this page.

Configure OpenCode

Add a provider to your global config ~/.config/opencode/opencode.json, or to opencode.json in the project root:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "centai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Cent AI",
      "options": {
        "baseURL": "https://api.cent-ai.dev/v1",
        "apiKey": "{env:CENT_AI_KEY}"
      },
      "models": {
        "glm-5.3": { "name": "glm-5.3" }
      }
    }
  },
  "model": "centai/glm-5.3",
  "small_model": "centai/glm-5.3"
}
FieldWhat it does
npm@ai-sdk/openai-compatible, OpenCode's adapter for OpenAI-compatible APIs.
options.baseURLCent AI's OpenAI base URL, with /v1.
options.apiKeyReads your key from the CENT_AI_KEY environment variable, so the key stays out of the file.
modelsThe models you want in OpenCode's model list. Each key is a name exactly as listed by GET /v1/models.
model, small_modelThe default model and the model for light tasks such as titles, as provider/model.

OpenCode's own documentation now also shows a newer provider shape, with providers, package, settings and env in place of provider, npm and options. In our test with OpenCode 2.3.0 both shapes worked against Cent AI; this page keeps the shape above.

Set the key in the environment, replacing YOUR_API_KEY with your key:

export CENT_AI_KEY="YOUR_API_KEY"

If CENT_AI_KEY is not set, OpenCode sends an empty key and every request returns 401.

Test it

Check the key and base URL with one Chat Completions request:

curl https://api.cent-ai.dev/v1/chat/completions \
  -H "Authorization: Bearer $CENT_AI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"glm-5.3","messages":[{"role":"user","content":"Hello"}]}'

The response has usage.cost, the amount charged for this request in USD. Then start opencode in the same terminal, check that the model shows centai/glm-5.3, and send a prompt. Each turn appears on the Requests page of the dashboard with its tokens per rate and its cost. See Request cost.

Cache continuity

Cent AI keeps the turns of a conversation on the same route without any setting on your side. It uses the session signal OpenCode sends when there is one; without it, Cent AI uses the stable start of the prompt, which OpenCode resends on every turn. You do not add anything to your configuration for this.

Cent AI does not promise a cache hit rate. Cache tokens are charged only when the model reports them. See Prompt caching.

Troubleshooting

To look up a failed request, find the x-request-id of the response on the Requests page. All codes are in 4xx errors and 5xx errors.

401 invalid_api_key

The key is wrong, cut off, revoked, or a management key (cai_mgmt_…). Check that CENT_AI_KEY is set in the terminal where you start OpenCode.

402 insufficient_balance

The balance available for this model is empty, or the model is not in your budget pack. Top up or buy a pack. See Balance.

403 ip_not_allowed or model_not_allowed

The key has an IP allowlist without your address, or a model allowlist without the model OpenCode asked for. Remember small_model: it must be on the allowlist too.

404 model_not_found

The model name is not one Cent AI serves. Copy the exact name from Models or GET /v1/models; names from other providers, such as gpt-4o-mini, are not aliases. A :free name works only for today's event model (see Free tokens daily); on any other model, including a previous day's event model, it returns 404.

429 rate_limited, key_limit_exceeded or project_budget_exceeded

  • rate_limited: more than 600 requests per minute on this key. Wait for Retry-After, or spread parallel sessions over several keys.
  • rate_limited on a :free name: today's free pool is used up, or the event is off. Retry-After runs to 00:00 UTC; the model's own name stays available at its normal price.
  • key_limit_exceeded: the daily or monthly limit you set on the key was reached.
  • project_budget_exceeded: the budget of the key's project was reached.

501 not_available_yet

The endpoint is not open yet. OpenCode only needs /v1/chat/completions, which is available, so this usually means a wrong baseURL.

Stream timeout

Long turns stream with : keepalive every 15 seconds. If a turn stops with upstream_timeout or upstream_unavailable in the stream, see Stream timeout.