跳转到主要内容
OpenCode is a terminal-based AI coding assistant. It connects to AI providers through a provider configuration in opencode.json. This tutorial covers two methods: the interactive /connect command and direct opencode.json editing.

Prerequisites

  • Node.js and the OpenCode CLI installed
  • A Qhaigc API key — get one from the API Tokens page
  • Access to create or edit an opencode.json file

Method 1: Using the /connect Command

1

Start OpenCode

Open a terminal in your project directory and run:
opencode
2

Run /connect

Inside the OpenCode session, type /connect and follow the interactive prompts to add a new provider. Select an OpenAI-compatible option when prompted for the provider type.
3

Enter your Qhaigc details

When prompted, enter:
  • Base URL: https://api.qhaigc.net/v1
  • API Key: your Qhaigc API key (starts with sk-)
4

Verify the connection

After completing the /connect flow, send a test message to confirm OpenCode is using Qhaigc.

Method 2: Editing opencode.json Directly

1

Create or open opencode.json

Create or open opencode.json in your project root (for project-level config) or your home directory (for user-level config).
2

Add a Qhaigc provider entry

Add the following configuration, using the @ai-sdk/openai-compatible provider:
{
  "provider": {
    "name": "@ai-sdk/openai-compatible",
    "options": {
      "baseURL": "https://api.qhaigc.net/v1",
      "apiKey": "sk-your-api-key-here"
    }
  }
}
Replace sk-your-api-key-here with your actual Qhaigc API key.
3

Save and restart OpenCode

Save opencode.json, then restart your OpenCode session or refresh it so the new configuration takes effect.
4

Specify a model if needed

If OpenCode cannot automatically detect available models from the endpoint, specify the model explicitly in your configuration or select it through the OpenCode interface.

Verifying the Connection

Your setup is working when:
  • The /connect flow completes without errors, or opencode.json is read without warnings
  • You can start a coding session and OpenCode sends requests to Qhaigc
  • The model returns a response instead of an authentication or connection error

Frequently Asked Questions

Why not just use environment variables like OPENAI_API_KEY? OpenCode’s recommended approach is the provider configuration in opencode.json. Environment variable overrides may work in some versions, but the opencode.json method is the official main path and more predictable. OpenCode can’t fetch models from the endpoint — what do I do? Confirm that baseURL and apiKey are correct. Then check OpenCode’s UI or config documentation for how to manually specify a model name, since not all OpenAI-compatible endpoints support the models list endpoint.

References