# OpenCode

OpenCode, from SST. See the [OpenCode documentation](https://opencode.ai/docs) for its current Node and dependency requirements before installing, since those change independently of this page.

## Install OpenCode

```
npm install -g opencode-ai   # or: curl -fsSL https://opencode.ai/install | bash
```

## Configure the provider

In `~/.config/opencode/opencode.json`, set `"interleaved": "reasoning_content"` on the model so reasoning is carried through multi-step turns.

```
# ~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ifm": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "IFM",
      "options": {
        "baseURL": "{env:IFM_BASE_URL}",
        "apiKey": "{env:IFM_API_KEY}"
      },
      "models": {
        "{env:IFM_MODEL}": { "interleaved": "reasoning_content" }
      }
    }
  },
  "model": "ifm/{env:IFM_MODEL}"
}
```

`interleaved` is only valid inside a model entry. At provider level OpenCode ignores it, and conversations break as soon as the model returns an empty reasoning trace.

Export the variables. Point `IFM_BASE_URL` at the hosted endpoint (see [Quickstart](https://docs.ifm.ai/docs/quickstart.md)) or at a model running in your own environment. Then start OpenCode and start building:

```
export IFM_BASE_URL="https://api.ifm.ai/v1"
export IFM_API_KEY="sk-ifm-..."
export IFM_MODEL="IFM/K2-Horizon-375B-A23B"

opencode
```

`opencode` opens the interactive session. For a scripted conversation, use `opencode run "your prompt"`, then `opencode run --continue "next prompt"` to continue it.

## Self-hosting

Serve the model with vLLM 0.30.0 or later. Take the GPU and parallelism flags for your hardware from the [vLLM recipe](https://recipes.vllm.ai/IFM/K2-Horizon-375B-A23B), and keep the flags below:

```
vllm serve IFM/K2-Horizon-MoVA-36B-A4B \
  --trust-remote-code \
  --reasoning-parser k2_horizon \
  --enable-auto-tool-choice --tool-call-parser k2_horizon \
  --chat-template-content-format string
```

Then point `IFM_BASE_URL` at your server and leave the rest of the config unchanged:

```
export IFM_BASE_URL="http://<host>:8000/v1"
export IFM_API_KEY="placeholder"
export IFM_MODEL="IFM/K2-Horizon-375B-A23B"
```

`IFM_MODEL` must match the name vLLM serves, which is the model id it was started with. If you start it from a local path, add `--served-model-name IFM/K2-Horizon-375B-A23B`. A server started without `--api-key` accepts any value for `IFM_API_KEY`.

`--chat-template-content-format string` is required. Without it, vLLM misreads the K2 Horizon chat template and sends user messages to the model empty.

_Last updated: October 15, 2026_
