# OpenCode

Connect OpenCode to Felo through the OpenAI-compatible endpoint.

Use this guide to install the Felo Skill for OpenCode. This setup does not change how OpenCode chooses its model: continue using the model you already have unless you also configure a Felo-compatible provider manually.

## Before you start

- A Felo API key: [create one](https://openapi.felo.ai/console/api-keys).
- [Node.js 22 or newer](https://nodejs.org/en/download) if you use the FeloAPI CLI.
- OpenCode installed.

## What this guide configures

| Item | Value |
| --- | --- |
| Model provider | unchanged for Skill installation; configure Felo models separately below |
| Felo Skill location | `~/.config/opencode/skills` |
| Protocol for optional Felo models | OpenAI-compatible |

## Install the Felo Skill (Optional)

```bash
npm install -g feloapi-cli@latest
feloapi setup --agent opencode --skills-only --yes
```

This installs the Skill only; it does not modify OpenCode's model provider. Start a new OpenCode session, then ask it to use the `feloapi` Skill, for example: “Use the feloapi skill to search the web for today's AI news and summarize it.”

## Option 1: Felo Models via Environment Variables (Recommended)

Store the key and base URL in environment variables and reference them from a custom Felo provider.

### 1. Set Variables for the Current Terminal

macOS / Linux (zsh or bash):

```bash
export FELO_API_KEY="YOUR_API_KEY"
export FELO_BASE_URL="https://openapi.felo.ai/api/v1"
```

Windows (PowerShell):

```powershell
$env:FELO_API_KEY = "YOUR_API_KEY"
$env:FELO_BASE_URL = "https://openapi.felo.ai/api/v1"
```

Replace `YOUR_API_KEY` with your complete Felo key. These settings apply to this terminal and its child processes.

### 2. Configure the Felo Provider Once

Create or edit `opencode.json` in your project root. Merge `provider.felo` and `model` into existing settings instead of replacing the whole file. Use `~/.config/opencode/opencode.json` for settings shared across projects.

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "felo/claude-sonnet-4-6",
  "provider": {
    "felo": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Felo API Platform",
      "options": {
        "baseURL": "{env:FELO_BASE_URL}",
        "apiKey": "{env:FELO_API_KEY}"
      },
      "models": {
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6"
        }
      }
    }
  }
}
```

OpenCode resolves the `{env:...}` references from its process environment. This example uses the V1 configuration format, which V2 also supports; see the [official migration guide](https://opencode.ai/docs/migrate-v1/#providers). If you already have a native V2 `providers.felo` entry, set its `settings.apiKey` and `settings.baseURL` instead of defining Felo in both formats.

Setting `OPENAI_API_KEY`, `OPENAI_BASE_URL`, or `OPENAI_API_BASE` alone does not replace the custom provider configuration above. The provider explicitly selects the Chat Completions adapter, Felo endpoint, and model.

### 3. Persist the Variables

macOS / Linux (zsh): add these lines to `~/.zshrc`, then run `source ~/.zshrc`. For bash, use `~/.bashrc` and `source ~/.bashrc`; macOS login bash can use `~/.bash_profile` instead.

```bash
export FELO_API_KEY="YOUR_API_KEY"
export FELO_BASE_URL="https://openapi.felo.ai/api/v1"
```

Windows (PowerShell): save user-level environment variables.

```powershell
[Environment]::SetEnvironmentVariable("FELO_API_KEY", "YOUR_API_KEY", "User")
[Environment]::SetEnvironmentVariable("FELO_BASE_URL", "https://openapi.felo.ai/api/v1", "User")
```

Open a new terminal on Windows and restart OpenCode. Desktop apps and IDEs must also inherit these variables; restart the launching app when needed.

::: warning Protect Your Key
Persistence stores the key in a local shell file or user environment. Keep it out of Git, screenshots, shared terminals, and logs.
:::

## Option 2: Set Felo Model Connection Details in a File

To use the configuration without environment variables, replace only `provider.felo.options` with:

```json
{
  "baseURL": "https://openapi.felo.ai/api/v1",
  "apiKey": "YOUR_API_KEY"
}
```

This is an `options` fragment, not a complete configuration file. It stores the key in plain text; keep it in a local user-level file and out of source control.

## Launch and Verify

Run this in the terminal where you set the variables:

```bash
opencode --model felo/claude-sonnet-4-6
```

Send a short test message. Run `/models` inside OpenCode to confirm the selected model belongs to **Felo API Platform**.

To switch models, update both the ID in `provider.felo.models` and the `model` field (or `--model` flag). Use the exact Felo model ID.

## Verify the Felo Skill

```bash
feloapi doctor --agent opencode
```

The Skill is healthy when the report lists `opencode` with `ok: true`.

## Remove the Felo Skill

If you installed the Skill through the CLI above, you can remove it separately:

```bash
feloapi disconnect opencode --yes
```

Removing the Skill does not undo the manual model provider configuration above. To switch back, select your previous provider in OpenCode. To delete the manual Felo configuration, remove only `provider.felo` and its default `model` setting, keeping other configuration intact.

## Troubleshooting

| Issue | What to check |
|-------|---------------|
| Authentication fails | Check that `FELO_API_KEY` is set, the key is active, and OpenCode was launched from that terminal |
| Empty environment values | Reload your shell configuration or reopen the terminal, then restart OpenCode; IDEs must also inherit the variables |
| Requests use another provider | Select `felo/model-id` and check for project or user settings overriding the provider |
| Endpoint error | Use `https://openapi.felo.ai/api/v1` without `/chat/completions`; this adapter does not use the Anthropic `/api` base URL |
| Model not found | Declare the model in `provider.felo.models` and match its ID to the [model catalog](https://openapi.felo.ai/models) |
| Chat works but coding fails | Choose a model with tool support; verify a short task before adding more context |
| `feloapi: command not found` | Reopen the terminal and retry; install with `npm install -g feloapi-cli@latest`. |
| Skill is not used | Start a new OpenCode session; Skills are discovered at startup. |
| Authentication fails when the Skill calls Felo | Create a key and run `feloapi auth login` (or export `FELO_API_KEY`). |

## Next Steps

- [AI Tool Setup Overview](https://openapi.felo.ai/docs/agent-clients.md)
- [Authentication](https://openapi.felo.ai/docs/authentication.md)
- [Protocols and SDKs](https://openapi.felo.ai/docs/guides/protocols.md)
- [OpenCode configuration documentation](https://opencode.ai/docs/config/#variables)
- [FeloAPI CLI guide](https://openapi.felo.ai/docs/cli.md)
- [Models and pricing](https://openapi.felo.ai/docs/guides/models-and-pricing.md)
