> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cerasai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use CerasAI with OpenCode

> Connect OpenCode directly to CerasAI through the OpenAI Chat Completions API.

## Before you begin

Install the OpenCode CLI with `npm i -g opencode-ai`, create a key on the
[API Keys](https://console.cerasai.cloud/keys) page, and choose a model on the
[Models](https://console.cerasai.cloud/models) page. These steps were tested with OpenCode 1.19.0.

**1. Set your API key**

Export your key in the shell that runs OpenCode:

```bash theme={"system"}
export CERASAI_API_KEY="your-key"
```

**2. Configure CerasAI**

Merge this configuration into `~/.config/opencode/opencode.json`, keeping your existing
providers, or create the file if it does not exist. The example includes DeepSeek-V4.1-Flash
and its fast and ultra tiers. Keep the top-level `model` line; without it, OpenCode picks its
own default.

> [accordion] OpenCode configuration
>
> ```json ~/.config/opencode/opencode.json theme={"system"}
> {
>   "$schema": "https://opencode.ai/config.json",
>   "model": "cerasai/deepseek-ai/DeepSeek-V4.1-Flash-1017",
>   "provider": {
>     "cerasai": {
>       "npm": "@ai-sdk/openai-compatible",
>       "name": "CerasAI",
>       "options": {
>         "baseURL": "https://api.cerasai.cloud/v1",
>         "apiKey": "{env:CERASAI_API_KEY}"
>       },
>       "models": {
>         "deepseek-ai/DeepSeek-V4.1-Flash-1017": {
>           "name": "deepseek-ai/DeepSeek-V4.1-Flash-1017",
>           "reasoning": true,
>           "limit": {
>             "context": 1048576,
>             "output": 393216
>           },
>           "options": { "reasoningEffort": "high" },
>           "variants": {
>             "low": { "reasoningEffort": "low" },
>             "high": { "reasoningEffort": "high" },
>             "max": { "reasoningEffort": "max" },
>             "minimal": { "disabled": true },
>             "medium": { "disabled": true },
>             "xhigh": { "disabled": true }
>           }
>         },
>         "deepseek-ai/DeepSeek-V4.1-Flash-1017": {
>           "name": "deepseek-ai/DeepSeek-V4.1-Flash-1017",
>           "reasoning": true,
>           "limit": {
>             "context": 1048576,
>             "output": 393216
>           },
>           "options": { "reasoningEffort": "high" },
>           "variants": {
>             "low": { "reasoningEffort": "low" },
>             "high": { "reasoningEffort": "high" },
>             "max": { "reasoningEffort": "max" },
>             "minimal": { "disabled": true },
>             "medium": { "disabled": true },
>             "xhigh": { "disabled": true }
>           }
>         },
>         "deepseek-ai/DeepSeek-V4.1-Flash-1017": {
>           "name": "deepseek-ai/DeepSeek-V4.1-Flash-1017",
>           "reasoning": true,
>           "limit": {
>             "context": 1048576,
>             "output": 393216
>           },
>           "options": { "reasoningEffort": "high" },
>           "variants": {
>             "low": { "reasoningEffort": "low" },
>             "high": { "reasoningEffort": "high" },
>             "max": { "reasoningEffort": "max" },
>             "minimal": { "disabled": true },
>             "medium": { "disabled": true },
>             "xhigh": { "disabled": true }
>           }
>         }
>       }
>     }
>   }
> }
> ```

For other models or tiers, copy an entry under `provider.cerasai.models` and update
its key and `name` using the [model catalog](https://console.cerasai.cloud/models).
Adjust the token limits and supported reasoning efforts for that model, then reopen OpenCode.

**3. Start a conversation**

Run `opencode` to start a conversation.

## Model and reasoning effort

* **Model and tier:** Use `/models` to switch in the current conversation.
* **Reasoning effort:** Use `/variants` to select **low**, **high**, or **max**. The default is
  **high**. With `opencode run`, pass `--variant` followed by **low**, **high**, or **max**.
  OpenCode ignores any other value and uses **high**.

## Troubleshooting

* If `opencode run` prints `UnknownError` with `Unexpected server error`, check that the
  selected model matches a model key in your configuration. With `-m`, include the provider
  prefix, for example `cerasai/deepseek-ai/DeepSeek-V4.1-Flash-1017`. Model IDs are case-sensitive.
  Run the command again with `--print-logs` to see the underlying error.
* Don't set `setCacheKey` in the provider options. If it is set, OpenCode sends `promptCacheKey`,
  which CerasAI rejects with `400 unknown_parameter`. CerasAI caches repeated prompts without it.

Issues common to every agent, with the errors CerasAI returns, are listed under
[Common issues](https://docs.cerasai.com/agent-integrations#common-issues).

## Resources

* [OpenCode documentation](https://opencode.ai/docs/)
* [CerasAI models](https://console.cerasai.cloud/models)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.