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

# OpenCode

> Add DreamTo as a custom provider in opencode.json and use GPT, Claude, DeepSeek and other models in OpenCode.

[OpenCode](https://opencode.ai) is an open-source terminal AI coding assistant that supports custom providers in its config file. DreamTo can be connected either as OpenAI compatible (Chat Completions / Responses) or as Anthropic compatible (Messages).

## Prerequisites

* OpenCode is installed (`opencode --version`).
* You have created an API Key on the **API Keys** page of the [DreamTo console](https://www.dreamto.ai/console) and set it as an environment variable:

  ```bash theme={null}
  export DREAMTO_API_KEY="sk-xxxx"
  ```

## Config file location

| Scope | Path |
| - | - |
| Global (all projects) | `~/.config/opencode/opencode.json` (or `.jsonc`) |
| Current project | `opencode.json` in the project root, or `.opencode/opencode.json` |

If the file already exists, merge only the provider-related fields and keep your other settings.

## Setup

OpenCode's config format changed in V2. Choose the tab for your version:

> [tab] OpenCode V2 (new)
>
> The new format uses a top-level `providers`, with `package` selecting the protocol, `settings.baseURL` the address, and `env` the environment variable holding the key:
>
> ```jsonc opencode.jsonc theme={null}
> {
>   "$schema": "https://opencode.ai/config.json",
>   "model": "dreamto/deepseek-v4.1-flash-1017",
>   "providers": {
>     // OpenAI Chat Completions: GPT, DeepSeek, Kimi, GLM, Grok, etc.
>     "dreamto": {
>       "name": "DreamTo",
>       "env": ["DREAMTO_API_KEY"],
>       "package": "@opencode/ai/providers/openai-compatible",
>       "settings": { "baseURL": "https://api.dreamto.ai/v1" },
>       "models": {
>         "deepseek-v4.1-flash-1017": { "name": "DeepSeek V4.1 Flash" },
>         "gpt-6.2-sol": { "name": "GPT-6.1 Sol" }
>       }
>     },
>     // Anthropic Messages: Claude family
>     "dreamto-claude": {
>       "name": "DreamTo Claude",
>       "env": ["DREAMTO_API_KEY"],
>       "package": "@opencode/ai/providers/anthropic-compatible",
>       "settings": { "baseURL": "https://api.dreamto.ai/v1" },
>       "models": {
>         "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" }
>       }
>     }
>   }
> }
> ```
>
> To call GPT over the Responses protocol, change `package` to `@opencode/ai/providers/openai-compatible/responses`.

> [tab] Legacy (provider + npm)
>
> The legacy format uses a top-level `provider`, with `npm` selecting the AI SDK package and `options` holding the address and key:
>
> ```json opencode.json theme={null}
> {
>   "$schema": "https://opencode.ai/config.json",
>   "model": "dreamto/deepseek-v4.1-flash-1017",
>   "provider": {
>     "dreamto": {
>       "npm": "@ai-sdk/openai-compatible",
>       "name": "DreamTo",
>       "options": {
>         "baseURL": "https://api.dreamto.ai/v1",
>         "apiKey": "{env:DREAMTO_API_KEY}"
>       },
>       "models": {
>         "deepseek-v4.1-flash-1017": { "name": "DeepSeek V4.1 Flash" },
>         "gpt-6.2-sol": { "name": "GPT-6.1 Sol" }
>       }
>     },
>     "dreamto-claude": {
>       "npm": "@ai-sdk/anthropic",
>       "name": "DreamTo Claude",
>       "options": {
>         "baseURL": "https://api.dreamto.ai/v1",
>         "apiKey": "{env:DREAMTO_API_KEY}"
>       },
>       "models": {
>         "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" }
>       }
>     }
>   }
> }
> ```
>
> For the Responses protocol, use the `@ai-sdk/openai` package.

The keys under `models` are the model IDs sent to DreamTo and must match the [Model Marketplace](https://www.dreamto.ai/models); `name` is only the display name in the UI. You can add a `limit` to a model (such as `{"context": 200000, "output": 64000}`) to help OpenCode manage context.

## Verify

Run `opencode` in your project directory, type `/models`, choose a model under `dreamto/...` or `dreamto-claude/...`, and send a message to test.

## FAQ

> [accordion] 401
>
> Make sure the terminal that starts OpenCode can read `DREAMTO_API_KEY` (`echo $DREAMTO_API_KEY`). If you previously saved other credentials for a provider of the same name with `/connect`, they may take precedence.

> [accordion] 404 / model not found
>
> * Set `baseURL` to `https://api.dreamto.ai/v1` for both providers: the OpenAI compatible package appends `/chat/completions` and the Anthropic package appends `/messages`.
> * Models are referenced as `provider/model ID`, for example `dreamto-claude/claude-sonnet-5-5`.

> [accordion] Protocol and model mismatch
>
> `package` (`npm` in the legacy format) determines the protocol. Put Claude models under the Anthropic compatible provider and GPT / DeepSeek and similar models under the OpenAI compatible provider.


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