• Home
  • Search
  • AI Services
  • Models
  • Writing
  • Multimedia Creation
  • Translation & Others
Home›Developer Center›OpenCode Linux

OpenCode Linux

API DocumentationAPI Quick StartOpenAI ChatGPT APIAnthropic (Claude) APIGoogle Gemini APIGoogle Search APIGoogle News APIOpenRouter APIAPI Pricing
CLI & Agent Guidescc-switch macOScc-switch Windowscc-switch LinuxOpenCode macOSOpenCode WindowsOpenCode LinuxOpenClaw macOSOpenClaw WindowsOpenClaw LinuxHermes Agent macOSHermes Agent WindowsHermes Agent LinuxClaude Code CLI macOSClaude Code CLI WindowsClaude Code CLI LinuxCodex CLI macOSCodex CLI WindowsCodex CLI Linux
MYAI168 API & MCPMYAI168 Chat API GuideMYAI168 MCP CLIMYAI168 MCP Web & App
User GuidesGT Agent GuideAI Services Guide
No matching questions on this page.Search the whole site
OpenCode Setup Overview (Linux)

OpenCode Install & Setup Guide — Linux

This guide explains how to install OpenCode on Linux and edit the config file opencode.json so that the model service points to MyAI168.

Please follow steps 1 to 7 below in order. If you run into trouble, see "Common Notes" at the end.

This guide applies to the current OpenCode 1.x release; the newly released OpenCode 2 reads the same config file in the same locations and format, so the setup below works unchanged.

1. Install OpenCode and launch it once

If OpenCode is not installed yet, open a terminal and run one of the following (official docs: https://opencode.ai/docs/):

# Option 1: official install script (recommended)
curl -fsSL https://opencode.ai/install | bash

# Option 2: Homebrew (also available on Linux)
brew install anomalyco/tap/opencode

# Option 3: npm (requires Node.js)
npm install -g opencode-ai

# Arch Linux (official repository, or AUR: paru -S opencode-bin)
sudo pacman -S opencode

After installing, launch it once (type opencode in the terminal, or open the desktop app) so the config folder gets created, then fully quit it following "Step 2".

* The official docs do not guarantee that the first launch creates the config file opencode.json; if "Step 3" cannot find it, see the note at the end of that step to create it manually.

* If you have already installed and used OpenCode and the config file exists, you may skip this step.

* To switch to OpenCode 2: it uses the same opencode command and cannot be installed alongside 1.x, so remove 1.x first and follow the official docs at https://opencode.ai/v2/docs (for example curl -fsSL https://opencode.ai/v2/install | bash).

2. Fully quit OpenCode first

Always quit the app before editing, otherwise your changes may be overwritten by the old settings.

Close the window, and make sure there is no OpenCode icon in the system tray / top status bar (if there is, right-click it and choose Quit). If you are not sure whether it is fully closed, open a terminal and run the following command to force quit:

pkill -f opencode
3. Open the folder containing the config file

The config file is named opencode.json and lives in a hidden directory inside your user home folder.

  1. Open a "Terminal".
  2. Paste this line and press Enter (it opens the folder in your default file manager):
xdg-open ~/.config/opencode/

The file manager will open that folder, and opencode.json is inside it.

* OpenCode also accepts the JSONC format (opencode.jsonc); if the folder already contains opencode.jsonc, just edit that file instead — the remaining steps are the same.

* If you cannot find opencode.json in the folder, search for the file name opencode.json directly in the file manager search box.

* On Linux, hidden folders (those starting with a dot) are not shown by default; in the file manager you can press Ctrl + H to toggle showing hidden files.

If you still cannot find opencode.json (the folder is empty or does not exist): the app has not auto-generated the config file yet, so create it manually. Open a terminal, paste the following two lines and press Enter after each:

mkdir -p ~/.config/opencode
touch ~/.config/opencode/opencode.json

Then open the folder as described above and you will see the newly created empty opencode.json. The manually created file is empty; go straight to "Step 5" and paste the full content into it.

4. Open the file with a text editor

Right-click opencode.json → "Open With" → choose a plain text editor (e.g. gedit, Kate, Text Editor, depending on your desktop environment). Or open it directly with an editor in the terminal, for example:

nano ~/.config/opencode/opencode.json

* Important: always use a plain text editor. Do not open it with word processors like LibreOffice Writer, as they may break the format when saving.

5. Edit the content

If the file is new or empty: copy and paste the whole block below. If the file already has content: do NOT overwrite it wholesale — that would delete your existing agent / permission / plugin / theme settings (OpenCode merges its config files rather than replacing them); instead, merge the two providers inside the "provider" block below into the "provider" block of your existing config (if there is no "provider" block yet, add the whole block).

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "myai168": {
      "name": "MyAI168",
      "npm": "@ai-sdk/openai",
      "options": {
        "baseURL": "https://www.myai168.com/en/api/openai/v1",
        "apiKey": "YOUR_API_KEY"
      },
      "models": {
        "gpt-6.1-sol": { "name": "GPT-6.1 Sol" }
      }
    },
    "myai168_claude": {
      "name": "MyAI168 Claude",
      "npm": "@ai-sdk/anthropic",
      "options": {
        "baseURL": "https://www.myai168.com/en/api/anthropic/v1",
        "apiKey": "YOUR_API_KEY"
      },
      "models": {
        "claude-opus-5-5": { "name": "Claude Opus 5.5" }
      }
    }
  }
}

The only thing you need to fill in: replace both occurrences of YOUR_API_KEY with your actual API key (use the same key in both places). Do not change anything else.

6. Save the file

Press Ctrl + S to save. If you are using nano, press Ctrl + O then Enter to save, then Ctrl + X to exit.

* Note: after saving, make sure the file name is still opencode.json and the extension has not been changed to .txt.

7. Reopen OpenCode

After reopening OpenCode, type /models in the prompt box (or use the model menu in the desktop app) and you will see two models:

  • MyAI168 → GPT-6.1 Sol
  • MyAI168 Claude → Claude Opus 5.5

Pick one and verify with an arithmetic question: What is 123456 times 789? Reply with the number only. — if it answers 97406784 and the API usage on the Developer API Key page increases, the call went through MyAI168 (do not verify with "Who are you?"; a model's self-description is unreliable).

(Optional) To make OpenCode start with a MyAI168 model by default, add "model": "myai168/gpt-6.1-sol", at the top level of the config file (the same level as "provider"). The format is "provider ID/model ID"; for Claude use "myai168_claude/claude-opus-5-5".

Common Notes
  • Always fully quit the app before editing settings. This is the most common cause of errors.
  • It is normal that the two model URLs end differently: the OpenAI one ends with /openai/v1 and the Claude one ends with /anthropic/v1. Do not unify or change them.
  • To add a model later, add a line in the corresponding models block following the existing format (remember to add a comma at the end of the previous line).
  • MyAI168 does not appear in the model menu → the config file has a JSON error, most often a missing or extra comma or quotes turned into curly quotes. Compare it line by line with the example in "5. Edit the content", or run opencode in a terminal to see the error message.
  • 401 responses → the key is wrong, or the key has reached its credit limit (API key credit limit reached!); check the Developer API Key page.
  • No pricing info! Please use other models! → a model ID in the models block is not on this site's accepted list; use this site's model IDs (list them with GET https://www.myai168.com/en/api/openai/v1/models).
  • This guide uses the simplified "API key directly in the config file" approach. You can instead store the key with OpenCode's /connect command (choose Other at the bottom of the list and enter the provider ID myai168 or myai168_claude, which must match the config file) — OpenCode then keeps the key itself and you can omit apiKey from options. Another option is "apiKey": "{env:MYAI168_API_KEY}", which reads the key from an environment variable.
Advanced settings and useful commands

Everything below is optional and goes in ~/.config/opencode/opencode.json. OpenCode merges its config files, so the snippets show only what to add or change — merge them into your existing content instead of overwriting it.

Default model and small background model

model is the model used on start-up. small_model handles light jobs such as generating conversation titles; without it those jobs also go to the main model, which costs one extra main-model call per new conversation. The small model must be listed under models of its provider:

{
  "model": "myai168_claude/claude-opus-5-5",
  "small_model": "myai168/gpt-5.4-mini",
  "provider": {
    "myai168": {
      "models": {
        "gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
        "gpt-5.4-mini": { "name": "GPT-5.4 mini" }
      }
    }
  }
}

Models are always written as "provider/model"; the usable model IDs are those returned by GET https://www.myai168.com/en/api/openai/v1/models.

Using the command line

opencode models myai168
opencode run "Explain the layout of this project"
opencode run -m myai168/gpt-6.1-sol "Write unit tests for the utils module"
opencode run -c "Turn those changes into a commit message"

opencode models myai168 lists the models of that provider from your config — a quick way to confirm the file is being read; opencode run performs one task without opening the UI, -m selects a model and -c continues the previous conversation.

Project instructions: AGENTS.md

Type /init in a conversation inside your project; OpenCode analyses it and creates AGENTS.md. Keep build and test commands and coding style there, and every later conversation picks it up.

Response timeout

If long answers or long reasoning get cut off, add timeout (milliseconds) to that provider's options:

{
  "provider": {
    "myai168": {
      "options": {
        "timeout": 600000
      }
    }
  }
}

Connect MYAI168 MCP

To let OpenCode use this site's AI modules as tools, see the "OpenCode" section of the MYAI168 MCP CLI page.

‹ Previous page: OpenCode WindowsNext page: OpenClaw macOS ›
↑
Question link copied.

Other FAQ pages

API Documentation

  • API Quick Start
  • OpenAI ChatGPT API
  • Anthropic (Claude) API
  • Google Gemini API
  • Google Search API
  • Google News API
  • OpenRouter API
  • API Pricing

CLI & Agent Guides

  • cc-switch macOS
  • cc-switch Windows
  • cc-switch Linux
  • OpenCode macOS
  • OpenCode Windows
  • OpenClaw macOS
  • OpenClaw Windows
  • OpenClaw Linux
  • Hermes Agent macOS
  • Hermes Agent Windows
  • Hermes Agent Linux
  • Claude Code CLI macOS
  • Claude Code CLI Windows
  • Claude Code CLI Linux
  • Codex CLI macOS
  • Codex CLI Windows
  • Codex CLI Linux

MYAI168 API & MCP

  • MYAI168 Chat API Guide
  • MYAI168 MCP CLI
  • MYAI168 MCP Web & App

User Guides

  • GT Agent Guide
  • AI Services Guide