---
url: https://docs.freetheai.org/guides/opencode.md
description: >-
  Use free models in OpenCode with FreeTheAI. Store the key with /connect and
  add the provider to opencode.json with context limits.
---

# OpenCode

OpenCode adds FreeTheAI as a custom provider: the key goes in with /connect, the provider and models go in `opencode.json`.

Category: [Coding tools](/guides/#coding-tools). Before you start, you need a FreeTheAI account, an API key, and today's [check-in](/getting-started/check-in).

## Settings

| Setting | Value |
| --- | --- |
| npm | `@ai-sdk/openai-compatible` |
| baseURL | `https://api.freetheai.org/v1` |
| Provider ID | `freetheai` |

## Steps

### Store your key

In OpenCode run /connect, scroll to Other, enter freetheai as the provider ID, then paste your key.

### Add the provider

Add this to `~/.config/opencode/opencode.json` (or `opencode.json` in your project).

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "freetheai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "FreeTheAI",
      "options": { "baseURL": "https://api.freetheai.org/v1" },
      "models": {
        "fta/zai/glm-5.3": { "name": "GLM 5.3", "limit": { "context": 200000, "output": 32000 } },
        "fta/kimi/k3": { "name": "Kimi K3", "limit": { "context": 200000, "output": 32000 } }
      }
    }
  }
}
```

### Pick the model

Run /models and choose a FreeTheAI model.

## Tips

* The limit values let OpenCode track how much context is left. Keep them at or below the model's real limits on [freetheai.org/models](https://freetheai.org/models).

## Common questions

### Where does OpenCode keep the FreeTheAI key?

/connect stores it in OpenCode's credential store. You can also set options.apiKey to "{env:`FTAI_KEY`}".

## More help

* [Every API error and its fix](/errors)
* [Limits and the daily reset](/concepts/limits)
* [OpenCode website](https://opencode.ai) and [source code](https://github.com/anomalyco/opencode)

::: info How this guide was checked
Checked against OpenCode's provider docs (custom provider) on 2026-09-29.
:::
