How to integrate RouterLink in OpenCode

This documentation is provided for informational purposes only and demonstrates how to configure and use our API with third-party AI chat interfaces. Any third-party software, websites, or services mentioned are not operated, controlled, or endorsed by us.

Overview

This tutorial guides you through integrating RouterLinkβ€”WORLD3's decentralized AI model routing infrastructureβ€”with OpenCode, a personal AI assistant you run on your own devices.

Purpose

RouterLink provides a unified API endpoint that routes requests to multiple AI model providers through a decentralized network. By integrating RouterLink with OpenCode, you gain access to a diverse range of large language models (LLMs) without managing multiple API keys or provider-specific configurations.

What You Will Learn

By completing this tutorial, you will:

  • Configure OpenCode to connect with RouterLink's API endpoint

  • Authenticate using your RouterLink API credentials with custom headers

  • Add and manage AI models available through the RouterLink network

  • Execute inference requests through OpenCode's conversational interface

Prerequisites

Before proceeding, ensure you have:

  • A RouterLink API key (obtain one from the Quick Start Guide)

  • A web browser with internet access

  • Basic familiarity with API configuration concepts

Introduction to OpenCode

OpenCode is an open source AI coding agent. It’s available as a terminal-based interface, desktop app, or IDE extension.OpenCode Key Features:

  • Local-first, privacy-focused

  • Supports 75+ AI models

  • Terminal-based interactive UI

  • Code generation, debugging & refactoring

  • Plugin & tool integrations (MCP)

  • Agent modes for coding & planning

  • Multi-session support

  • LSP-powered code intelligence

  • Highly customizable & extensible

  • Automation with shell & file operations

Step 1: Install OpenCode

Install the newest LTS version of Node.jsAfter installation is complete, open the terminal (Windows users use PowerShell) and check the version number.

  • macOS, Linux, Windows:

Step 2: OpenCode CLI credential registration

Before modifying the configuration file, you need to register a provider alias (Provider ID) in the local key manager. This step ensures the secure hosting of the API Key, preventing it from being hardcoded in plain text within the configuration file.Execute the authentication command:

Select the type: Locate and select "other" at the bottom of the list (you can directly type to search).

Define the ID: Enter "local".

Enter the key: Input the token key API Key (sk-xxxx) that you have created on Quick Start Guide.

Step 3: Configure OpenCode

OpenCode uses the opencode.json file to parse provider parameters. Please locate and create/edit this file according to your operating system.

Edit or create opencode.json file

On macOS & Linux: ~/.config/opencode/opencode.json

On Windows: C:\Users\<USERNAME>\.config\opencode\opencode.json

Configuration file:

npm: Use @ai-sdk/openai-compatible to adapt to the OpenAI-compatible protocol.

baseURL: Enter the API endpoint of the RouterLink platform.

models: You need to manually declare the list of models supported by the RouterLink platform. The keys must correspond to the actual Model IDs.

Step 4: OpenCode Loading and Validation

Launch the main program:

Enter the following command in the interactive prompt to open the model menu: /models

If the configuration is correct, you will see the custom n1n platform and its models listed.

Last updated