> For the complete documentation index, see [llms.txt](https://docs.obitmc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.obitmc.com/inference-api/use-with/opencode.md). Agents can also search and read this documentation through its [MCP server](https://docs.obitmc.com/~gitbook/mcp).

# opencode

Use Obit's models from opencode by declaring a custom OpenAI-compatible provider.

opencode takes its provider list from [models.dev](https://models.dev), where an Obit listing is still pending, so declare Obit as a custom provider in `opencode.json` (your project root) or `~/.config/opencode/opencode.json` (everywhere):

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "obit": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Obit",
      "options": {
        "baseURL": "https://relay.obitmc.com/v1",
        "apiKey": "{env:OBIT_API_KEY}"
      },
      "models": {
        "unsloth/Qwen3.8-27B-GGUF": {
          "name": "Qwen3.8 27B",
          "limit": { "context": 262144, "input": 262144, "output": 32768 }
        }
      }
    }
  },
  "compaction": { "reserved": 49152 }
}
```

Then `export OBIT_API_KEY=sk-live-…` and pick the model as `obit/unsloth/Qwen3.8-27B-GGUF`.

**Note.** A model you do not list does not exist to opencode, and `limit.context` is what it plans against, so write the model's real context window. Keep `@ai-sdk/openai-compatible`: `@ai-sdk/openai` drives the provider through `/v1/responses`, which Obit also serves.

## Long sessions

opencode keeps a session inside the context window by **compacting** it: when the last response's token total reaches a threshold it summarises the history and continues from the summary. The threshold is where the three numbers above matter.

* `limit.context` turns compaction on. Leave it out and opencode never compacts: the session grows until Obit refuses the prompt, and opencode then reports `Session too large to compact`, because the summary request carries the same oversized history. A session in that state cannot be rescued with `/compact`. Start a new one.
* `limit.output` is sent as `max_tokens` on every request. opencode caps it at 32,000 whatever you write, so `32768` and the model's context window mean the same thing here.
* The headroom between the threshold and the window is what the next turn's tool results must fit into. With only `context` and `output` set it equals `max_tokens`, so at most 32,000 tokens, and one large file read can overshoot it. `limit.input` together with `compaction.reserved` sets it directly: compaction then runs at `input − reserved`, 212,992 tokens with the values above. `reserved` is ignored unless `input` is set.

The error a request past the window gets back is `400 context_length_exceeded`, described on the [errors page](https://docs.obitmc.com/inference-api/errors-and-streaming.md).

*Verified against* [*opencode.ai/docs/providers*](https://opencode.ai/docs/providers/)*,* [*opencode.ai/docs/config*](https://opencode.ai/docs/config/) *and opencode v1.18.35 on 2026-10-06.*

***

[Prices](https://obitmc.com/pricing) · [Status](https://status.obitmc.com) · [API reference](https://docs.obitmc.com/inference-api/inference-api.md)
