Tools & IDE

OpenCode Configuration

OpenCode is an AI coding agent that runs in the terminal, supporting multiple model providers through a provider mechanism. This guide covers configuring OpenCode to use ShopAIKey's OpenAI-compatible API.

Endpoint

code
https://api.shopaikey.com/v1

1. Install OpenCode

Install via npm:

code
npm install -g opencode

Or via Homebrew on macOS/Linux:

code
brew install opencode-ai/tap/opencode

Verify after installation:

code
opencode --version

2. Add API Key to OpenCode

Run:

code
opencode auth login

Select Other, then enter the provider id:

code
shopaikey

Then enter your ShopAIKey API key.

The provider id shopaikey must match the key in the opencode.json file in the next step.

3. Create opencode.json

In the project directory where you want to use OpenCode, create or update the file:

code
opencode.json

Sample content:

code
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "shopaikey": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ShopAIKey",
      "options": {
        "baseURL": "https://api.shopaikey.com/v1"
      },
      "models": {
        "gpt-5.2": {
          "name": "GPT-5.2"
        },
        "gpt-5.3-codex": {
          "name": "GPT-5.3 Codex"
        },
        "claude-sonnet-4-5": {
          "name": "Claude Sonnet 4.5"
        },
        "claude-opus-4-5": {
          "name": "Claude Opus 4.5"
        }
      }
    }
  }
}

4. Select a Model

Launch OpenCode:

code
opencode

In the OpenCode interface, run:

code
/models

Select the ShopAIKey provider and the model you want to use.

5. Configure API Key Directly in the File

If you prefer not to use opencode auth login, you can set the key via an environment variable.

macOS / Linux

code
export SHOPAIKEY_API_KEY="sk-your-api-key"

Windows PowerShell

code
$env:SHOPAIKEY_API_KEY = "sk-your-api-key"

Then edit opencode.json:

code
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "shopaikey": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ShopAIKey",
      "options": {
        "baseURL": "https://api.shopaikey.com/v1",
        "apiKey": "{env:SHOPAIKEY_API_KEY}"
      },
      "models": {
        "gpt-5.2": {
          "name": "GPT-5.2"
        }
      }
    }
  }
}

6. Notes

  • Use @ai-sdk/openai-compatible for endpoint https://api.shopaikey.com/v1.
  • If you change opencode.json, restart OpenCode to ensure the new configuration is loaded.
  • Model IDs must match the models currently supported by ShopAIKey.
  • If you encounter an Invalid API Key error, check that the key has credit and hasn't been revoked.
  • If you encounter a Model Not Found error, try switching to another model from the Models page.

7. Quick Test

In your project directory, run:

code
opencode

Send a test request:

code
Explain this project's structure and suggest areas for improvement.

If the response comes back normally, the configuration is working.