# OpenCode

> Use Inferit as an OpenAI-compatible provider in OpenCode, with model auto or a named model.

OpenCode supports any OpenAI-compatible provider through the AI SDK's openai-compatible package, so Inferit works as a custom provider.

## 1. Get a key

Create one in the [Buy workspace](https://inferit.app/buy) ([Quickstart](https://inferit.cc/docs/quickstart.md), steps 1 to 6) and export it. OpenCode reads it from the environment through `{env:…}`.

```bash
export INFERIT_API_KEY='ik_...'
```

## 2. Add the provider

Put this in `opencode.json` in your project (or the global config). It lists two models: `auto`, where Inferit picks the model, and one catalog model by name. Add one entry under `models` per catalog id you want to use; ids are listed on [Models](https://inferit.app/models). Optionally, give a model a `limit` (`{"context": …, "output": …}`) so OpenCode knows how much it can send: use the largest `context_length` a healthy seller serves, from `GET /v1/models/{id}/endpoints`. The catalog's window in `GET /v1/models` can be longer than any seller serves.

_opencode.json_

```
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "inferit": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Inferit",
      "options": {
        "baseURL": "https://api-production-c74b9.up.railway.app/v1",
        "apiKey": "{env:INFERIT_API_KEY}"
      },
      "models": {
        "auto": {
          "name": "Inferit auto (Inferit picks the model)",
          "limit": {
            "context": 131072,
            "output": 4096
          }
        },
        "qwen/qwen-2.5-14b-instruct": {
          "name": "qwen/qwen-2.5-14b-instruct (Inferit)"
        }
      }
    }
  },
  "model": "inferit/qwen/qwen-2.5-14b-instruct"
}
```

## 3. Check it

One request from the command line, without the interface:

```bash
opencode run --model inferit/qwen/qwen-2.5-14b-instruct "Say hello in five words."
```

## Model auto, or a named model

With `"auto"` as the model, Inferit picks the model: the best value on a published quality ranking for this request, at that model's cheapest healthy seller ([Automatic routing](https://inferit.cc/docs/routing.md)). The response names the model that answered, in its `model` field and the `x-inferit-model` header.

Auto needs a ranked model with a live seller. `GET /v1/routing` lists the models it can choose from now in `candidates_now`; while that list is empty, a request with auto answers `503 no_eligible_model`. Then name a catalog model with a live seller instead, such as `qwen/qwen-2.5-14b-instruct`, and Inferit picks the seller. The samples on this page send auto while it has a candidate, and that model otherwise.

## Optional: a discount floor

To only accept offers at least 30% below list, use `https://api-production-c74b9.up.railway.app/min30/v1` as the `baseURL`. Requests with no qualifying offer fail at once with `503 no_available_offers` instead of routing to a pricier seller.

## Notes

-   Streaming, tool calls and other Chat Completions fields are passed through to the seller's OpenAI-compatible server unchanged.
-   What a model supports (tool calling, context length) depends on how the seller serves it. Each seller's context length is on the model's market page and in `GET /v1/models/{id}/endpoints`.
-   OpenCode needs a seller that serves a long context: its system prompt and tool definitions come to about 10,000 tokens per request, plus room for the answer. When no healthy seller of the model serves that much, Inferit answers `503` and names the largest context on offer.
-   OpenCode sends its own system prompt and tool definitions with every request, so even a short question carries a long input. Each request is charged at the serving seller's price; your usage log in the Buy workspace lists them.

## Checked

On 2026-10-13, no live seller of `qwen/qwen-2.5-14b-instruct` served more than 8,192 tokens of context, and `opencode run` with this config was refused with `503` (no seller serves the context it asks for). It needs a seller serving a longer context (see Notes); the model's catalog window is 32,768.

---

Canonical page: https://inferit.cc/docs/guides/opencode
All pages as markdown: https://inferit.cc/llms.txt
