Home›Developer Center›OpenCode macOS

OpenCode macOS

API DocumentationOpenAI 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 MCP CLIMYAI168 MCP Web & App
No matching questions on this page.Search the whole site
OpenCode Setup Overview (macOS)

OpenCode Install & Setup Guide — macOS

This guide explains how to install OpenCode on macOS 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.

1. Install OpenCode and launch it once

If OpenCode is not installed yet, open 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 (recommended tap, most up to date)
brew install anomalyco/tap/opencode

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

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.

2. Fully quit OpenCode first

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

Press Cmd + Q to close the window, and make sure there is no OpenCode icon in the menu bar at the top-right (if there is, click it and choose Quit).

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 "Terminal" (in Applications → Utilities).
  2. Paste this line and press Enter:
open ~/.config/opencode/

Finder 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 Finder search box.

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 "TextEdit".

* Important: always use a plain text editor. Do not open it with word processors like Word or 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-5.6-sol": { "name": "GPT-5.6 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-4-8": { "name": "Claude Opus 4.8" }
      }
    }
  }
}

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 Cmd + S to save. If TextEdit asks about the format, choose "Use Plain Text".

* 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 the app, you will see two models in the model selection menu:

  • MyAI168 → GPT-5.6 Sol
  • MyAI168 Claude → Claude Opus 4.8

Choose either one to start using it.

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).
  • This guide uses the simplified "API key directly in the config file" approach. The official standard flow is to store your key first with the /connect command inside OpenCode (credentials are saved to ~/.local/share/opencode/auth.json, not in the config file), then configure the provider in the config. Either approach works; if you use /connect, you can omit the apiKey field from options in the config.
‹ Previous page: cc-switch LinuxNext page: OpenCode Windows ›
↑
Question link copied.

Other FAQ pages

API Documentation

  • 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 Windows
  • OpenCode Linux
  • 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 MCP CLI
  • MYAI168 MCP Web & App