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

# OpenCode

> Add derestricted.ai as an OpenAI-compatible provider in OpenCode.

Use `derestricted-llm` in OpenCode through the Chat Completions API.

## Before you start

Install [OpenCode V1](https://opencode.ai/docs/) or [OpenCode V2](https://opencode.ai/v2/docs/), and create a key in the [console](https://derestricted.ai/console/). New verified accounts receive \$5 in starting credit.

In the terminal that will launch OpenCode:

```bash theme={"system"}
export DERESTRICTED_API_KEY="glmk_YOUR_API_KEY"
opencode --version
```

## Add your provider

Choose the configuration for your installed major version. Merge it into `~/.config/opencode/opencode.json` to apply it to your projects. Existing project settings may override global settings.

<Tabs>
  <Tab title="OpenCode V1">
    V1 uses `provider`, `npm`, and `options`, as documented in its [custom provider guide](https://opencode.ai/docs/providers/#custom-provider).

    ```json theme={"system"}
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "derestricted/derestricted-llm",
      "provider": {
        "derestricted": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "derestricted.ai",
          "options": {
            "baseURL": "https://api.derestricted.ai/v1",
            "apiKey": "{env:DERESTRICTED_API_KEY}"
          },
          "models": {
            "derestricted-llm": {
              "name": "derestricted-llm"
            }
          }
        }
      }
    }
    ```
  </Tab>

  <Tab title="OpenCode V2">
    V2 uses `providers`, `package`, and `settings`, as documented in its [custom provider guide](https://opencode.ai/v2/docs/providers/#custom).

    ```json theme={"system"}
    {
      "$schema": "https://opencode.ai/config.json",
      "model": "derestricted/derestricted-llm",
      "providers": {
        "derestricted": {
          "name": "derestricted.ai",
          "env": ["DERESTRICTED_API_KEY"],
          "package": "@opencode/ai/providers/openai-compatible",
          "settings": {
            "baseURL": "https://api.derestricted.ai/v1"
          },
          "models": {
            "derestricted-llm": {
              "name": "derestricted-llm",
              "capabilities": {
                "tools": true,
                "input": ["text"],
                "output": ["text"]
              }
            }
          }
        }
      }
    }
    ```
  </Tab>
</Tabs>

The configuration contains an environment-variable reference, so the API key stays out of the JSON file. Global configuration locations are documented for [V1](https://opencode.ai/docs/config/#global) and [V2](https://opencode.ai/v2/docs/config/#locations).

The V2 configuration explicitly limits input to text because custom models otherwise inherit image support. Client context estimates are not a guarantee of gateway capacity; see [model capabilities](https://opencode.ai/v2/docs/models/#aliases) and our [request limits](/api/introduction).

## Start a session

From your project directory:

```bash theme={"system"}
opencode
```

Open `/models` and select `derestricted/derestricted-llm` if it is not already selected. Try “Explain the project structure.”

## If something fails

* **Unknown configuration field:** use the tab matching `opencode --version`; the V1 and V2 provider formats differ.
* **Missing provider or key:** restart OpenCode from the terminal with the exported key. A separately running OpenCode server also needs that environment variable.
* **Model missing from discovery:** keep the explicit model entry shown above; model discovery may display compatibility aliases.
* **Unsupported requests:** use text and ordinary function tools. See [API compatibility](/api/introduction) and the [error guide](/api/errors).
