# OpenCode
URL: https://docs.munito.ai/agents/opencode

For a remote workspace, use [OpenCode as a cloud agent](https://docs.munito.ai/sandboxes/cloud-agents/opencode).

Munito AI is in the provider list of OpenCode, which comes from [models.dev](https://models.dev). OpenCode runs open models through the OpenAI-compatible [Chat Completions API](https://docs.munito.ai/api/createChatCompletion).
This guide needs [OpenCode 2](https://opencode.ai/docs/#cli).

## Connect [#connect]

1. Create an [API key](https://console.munito.ai/keys).
2. In OpenCode, run `/connect`, search for Munito AI, and paste the key. To keep processing in the EU, pick Munito AI (EU).
3. Run `/models` and pick a model below Munito AI or Munito AI (EU), such as GLM-5.3-Flash.

- The line below the prompt shows the model and its provider, such as `GLM-5.3-Flash Munito AI (EU)`.
- OpenCode keeps the key in its database, `~/.local/share/opencode/opencode.db`.
- The list holds the chat models that models.dev lists for each host. [Models](https://docs.munito.ai/models) lists every model and its regions.

## Run one task [#run-one-task]

```bash
opencode run -m munito-eu/zai-org/glm-5.3-flash "<task>"
```

- OpenCode names a model by the provider ID and the model ID.
- The provider ID is `munito` for Munito AI and `munito-eu` for Munito AI (EU). Use the provider that you connected.
- `opencode run` runs one task without the terminal UI.

## Allow only Munito AI [#allow-only-munito-ai]

OpenCode has other providers too. When Munito AI is not available, OpenCode takes a model of another provider, with no error.
To prevent that, and to set the default model, add this to `~/.config/opencode/opencode.json`:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "munito-eu/zai-org/glm-5.3-flash",
  "policies": [
    { "action": "provider.use", "resource": "*", "effect": "deny" },
    { "action": "provider.use", "resource": "munito*", "effect": "allow" }
  ]
}
```

- OpenCode then offers only Munito AI and Munito AI (EU).
- When neither is available, OpenCode stops with `No model is available`.

## Use a variable in place of `/connect` [#use-a-variable-in-place-of-connect]

For a script or a CI job, export the key as `MUNITO_API_KEY`:

```bash
export MUNITO_API_KEY=munitoai_...
```

OpenCode then offers Munito AI and Munito AI (EU) with no `/connect`.

OpenCode keeps a background server, and that server reads the variable when it starts.
If OpenCode answers `Model unavailable`, `No model is available` or `Missing API key`, restart the server from a shell that has the variable:

```bash
opencode service restart
```

## Add a model [#add-a-model]

The provider list does not hold every chat model of Munito AI.
To add one, put it below its provider in `~/.config/opencode/opencode.json`:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "munito-eu": {
      "models": {
        "google/gemma-4-12b": {
          "name": "Gemma 4 12B",
          "limit": { "context": 32768, "output": 29491 }
        }
      }
    }
  }
}
```

- The page of each chat model in the [model catalog](https://docs.munito.ai/models) gives its model ID, its context and its maximum output.
- The `limit` tells OpenCode the context window of the model, so that it compacts the conversation before the window is full.
- For another [regional host](https://docs.munito.ai/regions), set `settings.baseURL` of the provider, such as `"settings": { "baseURL": "https://api.us.munito.ai/inference/v1" }` below `munito`.

## Reasoning effort [#reasoning-effort]

GLM-5.3-Flash always reasons, and its effort levels are `low`, `high` and `max`.
Without a level, the model reasons at its default effort.

- In the terminal UI, `/models` asks for the level after the model, and `ctrl+t` changes it.
- For one task, put the level after the model ID:

```bash
opencode run -m munito-eu/zai-org/glm-5.3-flash#high "<task>"
```

Another model can have other levels. See [Reasoning models](https://docs.munito.ai/features/reasoning) and the OpenCode docs for [variants](https://opencode.ai/docs/models/#variants).