# OpenCode

> Use Inferit as an OpenAI-compatible provider in OpenCode.

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). Add one entry under `models` per catalog id you want to use; ids are listed on [Models](https://inferit.app/models).

_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": {
        "qwen/qwen-2.5-14b-instruct": {
          "name": "qwen/qwen-2.5-14b-instruct (Inferit)"
        }
      }
    }
  },
  "model": "inferit/qwen/qwen-2.5-14b-instruct"
}
```

## 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. Context lengths are shown in the catalog.

---

Canonical page: https://inferit.cc/docs/guides/opencode
All pages as markdown: https://inferit.cc/llms.txt
Testnet demo: test tokens, no monetary value.
