Skip to main content

Overview

OpenCode is a Go-based TUI (Terminal User Interface) coding assistant that works with multiple LLM providers. It provides an interactive terminal interface for chatting with AI about your code, generating changes, and running commands. By configuring OpenCode with FoxAPI, you can access a variety of AI models through a single API endpoint.
OpenCode supports custom providers via its JSON configuration, making FoxAPI integration straightforward.

Prerequisites

FoxAPI API Key

An active FoxAPI API key.

OpenCode

OpenCode installed on your system.

Installation & Configuration

1

Install OpenCode

curl -fsSL https://opencode.ai/install | bash
Verify the installation:
opencode --version
2

Register the Custom Provider

Before editing the configuration file, you must first register a custom provider using the OpenCode CLI:
opencode auth login
When prompted:
  1. Select “other” as the provider type.
  2. Enter foxapi as the provider ID.
  3. Enter any placeholder value for the token (it will be overridden in the config file).
This step is required. OpenCode will not recognize the foxapi provider in the configuration file unless it has been registered first via opencode auth login.
3

Configure FoxAPI

Edit the OpenCode configuration file:
~/.config/opencode/opencode.json
Set the contents to the following:
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "foxapi": {
      "npm": "@ai-sdk/anthropic",
      "name": "FoxAPI",
      "options": {
        "baseURL": "https://api.foxapi.cc/v1",
        "apiKey": "sk-your-foxapi-api-key"
      },
      "models": {
        "claude-sonnet-4-20250514": { "name": "Claude Sonnet 4" },
        "claude-opus-4-20250514": { "name": "Claude Opus 4" },
        "gpt-4o": { "name": "GPT-4o" }
      }
    }
  }
}
Replace sk-your-foxapi-api-key with your actual FoxAPI API key.
4

Start Using OpenCode

Launch OpenCode in your project directory:
cd /path/to/your/project
opencode
This opens the interactive TUI where you can chat with the AI about your codebase.

Verify the Connection

After launching OpenCode, use the /models command inside the TUI to verify that the configured models are available:
/models
You should see the FoxAPI models listed (e.g., Claude Sonnet 4, Claude Opus 4, GPT-4o). Then type a test message to confirm the connection:
Hello, please confirm you are working correctly.
A successful response confirms the FoxAPI connection is active.
Use CaseModelDescription
Complex Tasksclaude-opus-4-20250514Best for complex reasoning and architecture
Balancedclaude-sonnet-4-20250514Great balance of quality and speed
Fast & Efficientgpt-4oQuick responses for everyday tasks

Troubleshooting

  • Make sure you have run opencode auth login and registered the foxapi provider before editing the config file.
  • Ensure the provider ID in the config matches exactly what you entered during registration.
  • Check that the configuration file syntax is valid JSON.
  • Verify your FoxAPI API key is correct in the options.apiKey field.
  • Ensure the key has sufficient balance and model access.
  • On macOS/Linux, the config file should be at ~/.config/opencode/opencode.json.
  • On Windows, the config file should be at C:\Users\{username}\.config\opencode\opencode.json.
  • Use the /models command inside OpenCode to check available models.
  • Verify that the models section in your config lists the correct model IDs.
  • Ensure the baseURL is set to https://api.foxapi.cc/v1.