# Connect OpenCode

https://modelportal.ai/docs/integrations/opencode

> Open-source terminal coding agent; add one OpenAI-compatible provider to its config.

## Use cases

Good for an open-source agent that reads your project, edits files and runs tests from the terminal. OpenCode reaches OpenAI-compatible endpoints through `@ai-sdk/openai-compatible`, configured globally or per project.

## Tips

A coding agent sends many long requests per task, so pick a long-context model with tool calling and set a daily spend limit on the key.

## Reasoning effort

Whether a reasoning level is sent depends on the reasoning setting you give the model (`reasoning_effort` on the Chat API). The platform follows the levels the serving line accepts: a level the upstream rejects becomes the next higher accepted level, or its highest one. If the model cannot turn reasoning off, asking for it returns 400 `unsupported_parameter`. Each model's table is under Reasoning effort on its page in the [catalog](/catalog?lang=en); rewritten calls show the rewrite in usage records.

## If it cannot connect

1. Use `https://modelportal.ai/v1` as the API host, without `/chat/completions`.
2. The key starts with `mp-` (older keys: `key_`) and is not paused or revoked; `invalid_api_key` means the key cannot be used.
3. The model ID matches the [catalog](/catalog) and is in the key's allowed models.
4. `insufficient_balance` means the balance is too low; see [common errors](/docs/errors?lang=en) for more.

## Setup

1. Install: npm install -g opencode-ai.
2. Put the block below in ~/.config/opencode/opencode.json, or in opencode.json at a project root to scope it to that project.
3. Run opencode in your project and confirm the ModelPortal.AI model with /models.

## Settings

- API host：`https://modelportal.ai/v1`
- API key：`YOUR_API_KEY`
- Model：`MODEL_ID`

> This setup follows the OpenCode docs and has not been tested by the platform yet; if something breaks, open a ticket with the request ID.

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "modelportal": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ModelPortal.AI",
      "options": {
        "baseURL": "https://modelportal.ai/v1",
        "apiKey": "YOUR_API_KEY"
      },
      "models": {
        "MODEL_ID": {}
      }
    }
  },
  "model": "modelportal/MODEL_ID"
}
```

## FAQ

### Will the key end up in my repository?

A project-level opencode.json may be committed. Write apiKey as {env:MODELPORTAL_API_KEY} and export that variable in your shell instead.

### How do I use more than one model?

Add more model IDs under models and switch with /models.

