Routin AI

OpenCode Integration

OpenCode Integration Guide - Call AI Models via Routin API Platform

Introduction

This guide explains how to install and configure OpenCode to call AI models through the Routin API platform. OpenCode is a powerful AI programming assistant that supports multiple programming languages and development environments.

Install OpenCode

# Install via npm
npm install -g opencode

# Or via Homebrew (macOS)
brew install opencode

Configure OpenCode

Method 1: Add Custom Provider via /connect Command

OpenCode supports any OpenAI-compatible provider. Run the /connect command to add Routin API:

Step 1: Run the connect command

/connect

Step 2: Select provider type

Scroll down in the provider list and select "Other":

┌  Add credential

◆  Select provider
│  ...
│  ● Other

Step 3: Enter provider ID

Enter a unique provider ID, such as routin:

┌  Add credential

◇  Enter provider id
│  routin

Tip: Choose an easy-to-remember ID as you'll use it in the configuration file.

Step 4: Enter API Key

Enter the API Key you obtained from the Routin platform:

┌  Add credential

▲  This only stores a credential for routin - you will need to configure it in opencode.json, check the docs for examples.

◇  Enter your API key
│  sk-...

Method 2: Configure opencode.json File

Create or update the opencode.json file in your project directory, or create it at ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "routin": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Routin API",
      "options": {
        "baseURL": "https://api.routin.ai/v1"
      },
      "models": {
        "gpt-4o": {
          "name": "GPT-4o"
        },
        "claude-sonnet-4-20250514": {
          "name": "Claude Sonnet 4"
        },
        "deepseek-chat": {
          "name": "DeepSeek Chat"
        }
      }
    }
  }
}

Configuration Options:

OptionDescription
npmAI SDK package name, use @ai-sdk/openai-compatible for OpenAI-compatible providers
nameDisplay name in the interface
options.baseURLAPI endpoint URL
options.apiKeyOptional, set API Key directly if not using authentication
options.headersOptional, set custom request headers
modelsList of available models

Advanced Configuration Example

Here's a complete configuration example with apiKey, headers, and limit options:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "routin": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Routin API",
      "options": {
        "baseURL": "https://api.routin.ai/v1",
        "apiKey": "{env:ROUTIN_API_KEY}",
        "headers": {
          "X-Custom-Header": "custom-value"
        }
      },
      "models": {
        "gpt-4o": {
          "name": "GPT-4o",
          "limit": {
            "context": 128000,
            "output": 16384
          }
        },
        "claude-sonnet-4-20250514": {
          "name": "Claude Sonnet 4",
          "limit": {
            "context": 200000,
            "output": 65536
          }
        },
        "deepseek-chat": {
          "name": "DeepSeek Chat",
          "limit": {
            "context": 64000,
            "output": 8192
          }
        }
      }
    }
  }
}

Advanced Configuration Options:

OptionDescription
apiKeyRead from environment variable using {env:ENV_VAR_NAME} syntax
headersCustom headers sent with each request
limit.contextMaximum input tokens the model accepts
limit.outputMaximum tokens the model can generate

Tip: The limit field helps OpenCode understand your remaining context space. Standard providers automatically pull this information from models.dev.


Configure Native Anthropic Provider

If you want to use the Anthropic official API directly (or a third-party compatible service), you can configure it using the @ai-sdk/anthropic package:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "Routin Claude",
      "options": {
        "baseURL": "https://api.routin.ai/v1",
        "apiKey": "{env:ANTHROPIC_API_KEY}"
      },
      "models": {
        "claude-sonnet-4-5-20250929": {
          "name": "Claude Sonnet 4.5"
        },
        "claude-haiku-4-5-20251001": {
          "name": "Claude 4.5 Haiku"
        },
        "claude-opus-4-5-20251101": {
          "name": "Claude 4.5 Opus"
        }
      }
    }
  }
}

Anthropic Configuration Options:

OptionDescription
npmUse @ai-sdk/anthropic native SDK
options.baseURLRoutin API endpoint or other third-party compatible service URL
options.apiKeyRead API Key from environment variable

Configure Environment Variable:

Windows (PowerShell)

setx ANTHROPIC_API_KEY "sk-your-api-key-here"

macOS / Linux

export ANTHROPIC_API_KEY="sk-your-api-key-here"

Configure OpenAI Codex Provider

If you want to use OpenAI Codex models, you can configure it using the @ai-sdk/openai package:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "codex": {
      "name": "routin Codex",
      "npm": "@ai-sdk/openai",
      "models": {
        "gpt-5.2-codex": {
          "name": "gpt-5.2-codex",
          "variants": {
            "high": {
              "reasoningEffort": "high",
              "textVerbosity": "low"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "textVerbosity": "medium"
            }
          }
        }
      },
      "options": {
        "apiKey": "your-api-key",
        "baseURL": "https://api.routin.ai/v1"
      }
    }
  }
}

If you are using a subscription plan, use the following URL:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "codex": {
      "name": "routin Codex",
      "npm": "@ai-sdk/openai",
      "models": {
        "gpt-5.2-codex": {
          "name": "gpt-5.2-codex",
          "variants": {
            "high": {
              "reasoningEffort": "high",
              "textVerbosity": "low"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "textVerbosity": "medium"
            }
          }
        }
      },
      "options": {
        "apiKey": "your-api-key",
        "baseURL": "https://api.routin.ai/plan/v1"
      }
    }
  }
}

Codex Configuration Options:

OptionDescription
npmUse @ai-sdk/openai native SDK
variantsModel variant configuration, supports different reasoning intensities
reasoningEffortReasoning intensity, options: high or xhigh
textVerbosityOutput verbosity level, options: low or medium

Configure API Key

Store your API Key in system environment variables to avoid storing it in local files.

Windows (PowerShell)

setx ROUTIN_API_KEY "sk-your-api-key-here"

macOS / Linux

export ROUTIN_API_KEY="sk-your-api-key-here"

Replace sk-your-api-key-here with the API Key you obtained from the Routin platform. After updating, reopen your terminal or append the command to ~/.zshrc / ~/.bashrc for persistence.


Verify Configuration

After configuration, run the /models command to see your custom provider and models in the selection list:

/models

If configured correctly, you'll see Routin API and its configured models in the list.


FAQ

Configuration File Location

The opencode.json file should be placed in your project root directory. OpenCode will automatically detect and load the configuration.

How to Get API Key

Please refer to the "Get API Key" section in the Claude Code Integration Guide.

Models Not Showing

If models don't appear in the list, check:

  1. Is the opencode.json file format correct (JSON syntax)?
  2. Is baseURL correctly set to https://api.routin.ai/v1?
  3. Is the API Key configured correctly?

Get Help

On this page