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

# Connect with OpenCode

> Set up OpenCode to use Modular Cloud models

This page explains how to run models from Modular Cloud on
[OpenCode](https://opencode.ai/).

## Before you begin

Make sure you have:

* A [Modular Cloud account](https://console.modular.com/signup).
* [OpenCode](https://opencode.ai/) installed.

## Add authentication

First, connect Modular Cloud to OpenCode.

1. Create a [Modular Cloud API key](/administration/api-keys#create-an-api-key)
   and copy its value.

2. Start OpenCode:

   ```bash theme={null}
   opencode
   ```

3. Run the `/connect` command in OpenCode.

4. At the end of the provider list, select **Other**.

5. Set the **Provider id** to `modular` and submit your API key.

## Update the OpenCode config

Next, configure Modular Cloud as a provider in the OpenCode config.

1. Open the `opencode.json` config file in your project directory.
2. Choose the model that you want from our list of
   [shared endpoints](/models) or use a dedicated endpoint if applicable.
3. Add Modular Cloud as a provider:

   ```json opencode.json highlight={4-15} theme={null}
   {
     "$schema": "https://opencode.ai/config.json",
     "provider": {
       "modular": {
         "npm": "@ai-sdk/openai-compatible",
         "name": "Modular Cloud",
         "options": {
           "baseURL": "https://api.modular.com/v1"
         },
         "models": {
           "minimax/minimax-m3": {
             "name": "MiniMax M3"
           }
         }
       }
     }
   }
   ```

The `npm` value depends on the API you're using:

* For the [chat completions API](/api/inference/create-chat-completion), use
  `@ai-sdk/openai-compatible`.
* For the [responses API](/api/inference/create-response), use `@ai-sdk/openai`.

You can also set a default model for OpenCode in the config:

```json opencode.json highlight={3} theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "model": "modular/minimax/minimax-m3"
}
```

To enable the config changes, restart OpenCode. Then, you can select any
configured models when you run the `/models` command.

<Note>
  The example above demonstrates a basic provider configuration. To see the
  complete list of configuration options, see the OpenCode documentation on
  [custom providers](https://opencode.ai/docs/providers#custom-provider).
</Note>
