Goal of this guide: install the Claude Code CLI on macOS, connect it to your own MYAI168 API, and use Claude Opus 5.5.
Claude Code speaks the Anthropic Messages protocol and connects to MYAI168's native Anthropic endpoint — no proxy needed. The key is supplied via an apiKeyHelper script — this is NOT a required setting (Claude Code officially supports setting the ANTHROPIC_API_KEY environment variable directly; apiKeyHelper is officially intended for dynamic / rotating credentials). This guide uses it so the key stays out of your shell environment variables and is easy to replace in one place.
https://www.myai168.com/en/api/anthropic (do not append /v1 at the end)claude-opus-5-5The base_url must end with .../anthropic — "never add /v1". Claude Code appends /v1/messages by itself; if the URL already contains /v1 the path becomes wrong, and you get a misleading "model does not exist" error. (This is the most common pitfall.)
System requirements (per the official docs): macOS 13.0 or later and 4 GB+ RAM, on Apple Silicon or Intel.
The official native installer (recommended) does not need Node.js; Node.js 22 or later is only required if you install with npm instead.
First check whether it is already installed:
claude --version
If you see a version number, skip to "2. Create the apiKeyHelper". If it shows command not found, install with the official native installer (recommended; it then updates itself in the background):
curl -fsSL https://claude.ai/install.sh | bash
You can also use Homebrew (brew install --cask claude-code tracks the stable channel, typically about a week behind; install claude-code@latest for the newest release; Homebrew installs never auto-update) or npm (requires Node.js 22 or later: npm install -g @anthropic-ai/claude-code).
After installing, open a new terminal window and confirm:
claude --version
(If it is still command not found, the install directory ~/.local/bin is not on your PATH yet: run echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc, then source ~/.zshrc and try again; you can also run claude doctor to check the installation.)
This guide supplies the key via an apiKeyHelper whether you use cc-switch or configure manually (it is not an official requirement — Claude Code also supports setting the ANTHROPIC_API_KEY environment variable directly; to follow this guide's flow, create it first):
mkdir -p ~/.claude
Create the key script (copy the whole block, paste it into the terminal, and press Enter once; replace the key with your real MYAI168 key):
cat > ~/.claude/api-key-helper.sh << 'EOF'
#!/bin/bash
echo "your-MYAI168-key"
EOF
chmod +x ~/.claude/api-key-helper.sh
Verify it outputs the key (it should print your key string):
~/.claude/api-key-helper.sh
Note: the script must print nothing but the key — no banners, prompts or log lines. From Claude Code 2.1.227, any extra output makes the helper fail. Claude Code caches the script output for 5 minutes, so a replaced key takes effect within 5 minutes, or immediately after you restart Claude Code.
For installing cc-switch and a tour of its interface, see the cc-switch macOS page.
myai168-claudehttps://www.myai168.com/en/api/anthropic (without /v1)claude-opus-5-5, Sonnet claude-sonnet-5-5, Haiku claude-haiku-4-5, Fable claude-fable-5-1 (the same mapping as settings.json in "3-B"); Default fallback model claude-opus-5-5. To always use Opus, you may set all four to claude-opus-5-5 instead. Third-party endpoints need this mapping — otherwise background tasks use Claude Code's built-in model names and fail."apiKeyHelper" line by hand (pointing to the script from "2. Create the apiKeyHelper"), and make sure there is no ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN line (delete it if present, otherwise you get an Auth conflict warning). It must contain at least the following (keep the ANTHROPIC_DEFAULT_*_MODEL and other lines cc-switch writes from the model mapping):
{
"apiKeyHelper": "~/.claude/api-key-helper.sh",
"env": {
"ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
"ANTHROPIC_MODEL": "claude-opus-5-5"
}
}
Verify the config file written by cc-switch (key points: the base URL does not contain /v1, apiKeyHelper is present, and there is no ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN):
cat ~/.claude/settings.json
If you do not use cc-switch, create settings.json directly from the terminal (paste the whole block and press Enter). The four ANTHROPIC_DEFAULT_*_MODEL lines map Claude Code's built-in Opus / Sonnet / Haiku / Fable aliases to model IDs this site supports, so background tasks (such as generating conversation titles) do not fail on an unsupported model ID:
cat > ~/.claude/settings.json << 'EOF'
{
"apiKeyHelper": "~/.claude/api-key-helper.sh",
"env": {
"ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
"ANTHROPIC_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5",
"ANTHROPIC_DEFAULT_FABLE_MODEL": "claude-fable-5-1"
}
}
EOF
Important: once you use apiKeyHelper, do NOT also export ANTHROPIC_API_KEY, otherwise Claude Code shows an Auth conflict warning. If ~/.zshrc has old Claude Code functions / exports, remove them.
(Reminder again: the base URL ends with .../anthropic, without /v1.)
(Optional) Before launching, confirm that the endpoint and key work. This request bypasses Claude Code, so a failure tells you whether the problem is the key / endpoint or the Claude Code configuration (a successful call costs a tiny number of credits):
curl -sS https://www.myai168.com/en/api/anthropic/v1/messages \
-H "x-api-key: $(~/.claude/api-key-helper.sh)" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"claude-haiku-4-5","max_tokens":16,"messages":[{"role":"user","content":"Hi"}]}'
A response that starts with {"id":"msg_ and has a "content" field means everything works; 401 means the key is wrong, and for 404 check the URL (the test URL includes /v1/messages, while the base URL in the Claude Code settings does not include /v1).
Open a "brand-new" terminal window (to avoid leftover environment variables interfering) and just type:
claude
(Do not pass any environment variables; apiKeyHelper provides the key automatically.)
First-run screens: color theme → pick one; Security notes → Enter; Terminal setup → 1. Yes; Trust this folder? → 1. Yes. You should go straight to the "Welcome back" main screen, without a login menu.
Verify: type /status and confirm the base URL is MYAI168 and the Model is claude-opus-5-5. Then ask a question; getting a reply means success (the bottom-left corner shows Opus 5.5 · API Usage Billing, meaning API-key billing rather than an official subscription).
Most common cause: /v1 was appended to the base_url. Change it to .../anthropic (without /v1). Then run /status to confirm the endpoint and the model ID (it must be an ID this site accepts, such as claude-opus-5-5).
The apiKeyHelper is missing, or the helper does not output the key. Confirm the script exists, is executable (chmod +x), and settings.json has the apiKeyHelper field. The login menu only accepts official accounts — do not use it; skip it via apiKeyHelper.
Both apiKeyHelper and ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) are set. Remove those variables from the env block of settings.json, from the cc-switch Config JSON and from your shell profile, so the key lives only in the apiKeyHelper script.
The request carried a tool that runs on Anthropic's servers; apart from web search, this site's endpoint does not support such tools. The usual cause is the advisor feature: turn it off, or add "CLAUDE_CODE_DISABLE_ADVISOR_TOOL": "1" to the env block of settings.json. Also run claude update to get the latest version (from 2.1.276, Claude Code no longer attaches the advisor on custom endpoints unless you turn it on).
Wrong key. Check that the key inside the helper script is correct and has no extra spaces.
This key has reached its credit limit. Raise the limit on the Developer API Key page, or use another key.
Claude Code runs background tasks with built-in aliases such as Haiku. Add the four lines ANTHROPIC_DEFAULT_OPUS_MODEL / ANTHROPIC_DEFAULT_SONNET_MODEL / ANTHROPIC_DEFAULT_HAIKU_MODEL / ANTHROPIC_DEFAULT_FABLE_MODEL to the env block of settings.json as shown in "3-B"; with cc-switch, set all four aliases in Model Mapping to a model ID this site supports.
(Only when you have confirmed /v1 was not added and you still get 404) try changing the base URL to .../anthropic/v1 and test again; normally keep it without /v1.
Run source ~/.zshrc or reopen the terminal; if it is still missing, add ~/.local/bin to PATH as described in "1. Install", then run claude doctor to check the installation.
Use /model to switch during a conversation; use /status to confirm the endpoint and model.
Update: the native-installer version updates itself in the background; to update right away, run:
claude update
for the Homebrew version use brew upgrade claude-code; for the npm version use npm install -g @anthropic-ai/claude-code@latest (avoid npm update -g — it respects the semver range from the original install and may not move you to the newest release). If something looks wrong with the installation or settings, run claude doctor.
~/.claude/api-key-helper.sh.~/.claude/settings.json: endpoint and apiKeyHelper settings.~/.claude/api-key-helper.sh: the script that provides the key.Everything below is optional. Put environment variables in the env block of ~/.claude/settings.json (next to ANTHROPIC_BASE_URL; values are always strings). If you manage Claude Code with cc-switch, put them in the card's Config JSON instead, otherwise switching providers overwrites them.
With -p, Claude Code prints the result and exits, which suits scripts and scheduled jobs:
claude -p "Check this project for unused functions"
claude -p "List the TODOs in this project" --output-format json
claude -p "Summarise the recent changes" --model sonnet --effort low --max-turns 5
claude -p "Add installation steps to the README" --permission-mode acceptEdits
--output-format json prints one JSON object: the reply text is in result and is_error tells whether the run failed. total_cost_usd is Claude Code's own estimate, not the credits this site deducts; check the Developer Keys page for real usage.--model picks the model (an alias — opus, sonnet, haiku, fable — or a full model ID); --effort sets the effort level; --max-turns limits the number of turns so a run cannot go on too long.--permission-mode acceptEdits (auto-approve file edits) or --allowedTools "Read,Edit".claude -c continues the most recent conversation in the current folder; claude -r lets you pick one from a list.Type /model in a conversation to open the model picker; the Opus / Sonnet / Haiku / Fable aliases resolve to this site's model IDs through the ANTHROPIC_DEFAULT_*_MODEL variables set in step 3-B. You can also name a model directly, for example /model claude-sonnet-5-5. /effort adjusts the effort level (low / medium / high / xhigh / max; the available levels depend on the model) — higher effort gives more careful answers at the cost of more output and usage.
Add the line below to the env block and Claude Code queries this site's model list at startup (GET https://www.myai168.com/en/api/anthropic/v1/models, free of charge) and adds the Claude models it returns to the /model picker:
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
The query waits at most 3 seconds; on a timeout or failure the previously fetched list is reused and conversations are not affected.
Small background tasks such as generating conversation titles use the model set in ANTHROPIC_DEFAULT_HAIKU_MODEL (step 3-B sets it to claude-haiku-4-5). Subagents inherit the main model by default; to run them on a cheaper model, add this to the env block:
"CLAUDE_CODE_SUBAGENT_MODEL": "claude-haiku-4-5"
| Variable | Description |
|---|---|
API_TIMEOUT_MS | Timeout of one request in milliseconds; the default is 600000 (10 minutes). |
CLAUDE_CODE_MAX_OUTPUT_TOKENS | Maximum output tokens of one reply. A lower value caps the usage of a single reply, but too low a value truncates long answers. |
CLAUDE_CODE_EFFORT_LEVEL | Pins the effort level (low / medium / high / xhigh / max, or auto for the model default); it takes precedence over --effort and /effort. |
CLAUDE_CODE_SUBAGENT_MODEL | Model for subagents that are not assigned a model another way; accepts an alias such as haiku or a full model ID. |
CLAUDE_CODE_API_KEY_HELPER_TTL_MS | How long the apiKeyHelper output is cached, in milliseconds; the default is 5 minutes, and 900000 means 15 minutes. |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC | Set to 1 to turn off traffic unrelated to model calls, such as version checks and telemetry. It also disables auto-updates, so update manually afterwards. |
DISABLE_TELEMETRY | Set to 1 to turn off telemetry only. |
CLAUDE_CODE_DISABLE_ADVISOR_TOOL | Set to 1 to disable the advisor feature, which this endpoint does not support. |
Example (add the lines inside the existing env block and keep the commas between lines):
"env": {
"ANTHROPIC_BASE_URL": "https://www.myai168.com/en/api/anthropic",
"ANTHROPIC_MODEL": "claude-opus-5-5",
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1",
"CLAUDE_CODE_SUBAGENT_MODEL": "claude-haiku-4-5",
"API_TIMEOUT_MS": "600000"
}
Press Shift+Tab in a conversation to cycle through the modes: the default mode (asks before every action) → acceptEdits (auto-approves file edits) → plan (plans only, changes nothing). You can also start in a mode, for example claude --permission-mode plan; /permissions manages individual allow and deny rules.
With a custom endpoint, Claude Code may print a notice at startup that begins with We're changing auto mode to no longer charge for classifier requests. It only says that auto mode's classifier requests keep counting toward usage; nothing breaks and you can ignore it.
CLAUDE.md: a guide in the project root that holds the project conventions, common commands and caveats; Claude Code reads it every time. Run /init in the project folder to generate it and /memory to edit it.~/.claude/settings.json: your personal settings for every project. The endpoint and key settings of this guide live here..claude/settings.json inside a project: committed and shared with the team. Never put a key in this file..claude/settings.local.json inside a project: applies only to you and only in this project, and is not committed.| Command | Purpose |
|---|---|
/status | Shows the version, endpoint, current model and credential source. |
/model | Switches the model (use the left/right arrows to adjust the effort level). |
/effort | Adjusts the effort level. |
/usage | Shows usage statistics of the session (/cost is an alias). The amount shown is Claude Code's own estimate, not the credits this site actually deducts. |
/context | Shows how much of the context window is in use. |
/compact | Summarises the conversation so far to free up context. |
/clear | Starts a new conversation with empty context. |
/resume | Resumes an earlier conversation. |
/permissions | Manages the allow and deny rules for tools. |
/init | Creates a CLAUDE.md guide for the project. |
/mcp | Shows and manages MCP server connections. |
To let Claude Code use this site's AI modules as tools, see the "Claude Code" section of the MYAI168 MCP CLI page.