AI ChatModelsPriceDocsGuides

How to use Claude Code with a custom API endpoint

Set three environment variables before starting Claude Code: ANTHROPIC_BASE_URL=https://api.macloudai.com (no /v1), ANTHROPIC_AUTH_TOKEN set to your sk- key, and ANTHROPIC_MODEL set to a model name from the models page. You can also put them in the env block of ~/.claude/settings.json so they apply every time you run claude.

Updated 2026-11-01 · MaCloud AI

What do I need first?

  • Claude Code installed on your machine (follow the official Anthropic install guide). Check with claude --version.
  • A MaCloud AI account with balance. Sign up, then top up at Top up; the page shows the payment methods currently available.
  • An API key from API Keys. Creating a dedicated key named "claude-code" makes it easy to see and revoke later.

How do I set it up?

  1. Create an API key in the console and copy it.
  2. Choose a Claude model on the models page and copy its exact name.
  3. Set ANTHROPIC_BASE_URL to https://api.macloudai.com. Do not add /v1: Claude Code adds its own path.
  4. Set ANTHROPIC_AUTH_TOKEN to your key and ANTHROPIC_MODEL to the model name.
  5. Open a new terminal (or reload your shell profile) and run claude in your project folder.
  6. Send a short message, then check Usage to confirm the call shows up with tokens and cost.

macOS and Linux

For the current terminal session:

export ANTHROPIC_BASE_URL=https://api.macloudai.com
export ANTHROPIC_AUTH_TOKEN=sk-...
export ANTHROPIC_MODEL=hk-5-5
claude

To keep it permanently, add the three export lines to ~/.zshrc (default shell on macOS) or ~/.bashrc (most Linux distributions), then run source ~/.zshrc or open a new terminal.

Windows

$env:ANTHROPIC_BASE_URL="https://api.macloudai.com"
$env:ANTHROPIC_AUTH_TOKEN="sk-..."
$env:ANTHROPIC_MODEL="hk-5-5"
claude

setx only affects terminals opened afterwards. Close every PowerShell, Command Prompt and VS Code window, then open a new one. You can also check or edit the values in Windows: Start menu, search Edit environment variables for your account.

Using settings.json instead of shell variables

Claude Code reads an env block from its settings file. This works the same on every operating system and does not depend on which shell or IDE launches Claude Code. Edit ~/.claude/settings.json (on Windows: %USERPROFILE%\.claude\settings.json):

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.macloudai.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-...",
    "ANTHROPIC_MODEL": "hk-5-5"
  }
}

If the file already has other settings, add the env key next to them instead of replacing the whole file. Keep the JSON valid: a missing comma or a trailing comma will make Claude Code ignore the file.

Do not commit this file, or a project-level .claude/settings.json with your key in it, to git. For a team, have each person keep the key in their own user settings or environment, and share only the base URL and model name.

How do I check that it is working?

  1. Start claude and type a short prompt such as "list the files in this folder".
  2. Inside Claude Code, run /status to see which API base URL and model it is using.
  3. Open Usage in the console. The last 50 calls are listed with model, input tokens, output tokens and cost. If your prompt is there, the setup is correct.

If you get an error instead, the most common causes are a base URL ending in /v1, a model name that is not on the models page, or variables that were set in a different terminal. See Claude Code API errors and fixes.

How do I keep the cost down?

Claude Code is an agent: it reads files, runs commands and sends the whole conversation, including file contents, back to the model on every turn. A long session can use far more input tokens than a chat. A few habits make a big difference:

  • Start a fresh session (/clear) when you switch to an unrelated task, so old context is not resent.
  • Use /compact in long sessions to summarize the history into a shorter context.
  • Point it at specific files or folders instead of asking it to "look at the whole repo".
  • Use a smaller, cheaper model for simple edits and switch to a larger one only for hard problems (change ANTHROPIC_MODEL or use /model).
  • Check Usage after a session to see what a typical task costs you.

Current per-token prices for each model:

Real prices now

Estimated from the prices on the models page: 2,000 input tokens and 500 output tokens per chat. The console shows the actual charge.

ModelsPer chat1,000 chats
GEM 3.8 FlashRp 4Rp 4.434
TT-6 LunaRp 11Rp 10.642
TT-6.1 TerraRp 7Rp 7.263
HK-5.5Rp 3Rp 3.487
GEM 4 ArgonRp 85Rp 84.649
TT-6.1 SolRp 15Rp 14.526

FAQ

Q1Should ANTHROPIC_BASE_URL end with /v1?
No. Use https://api.macloudai.com exactly. Claude Code appends the API path itself, so adding /v1 produces wrong URLs and 404 errors.
Q2ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY?
Use ANTHROPIC_AUTH_TOKEN, which is sent as a Bearer token. The gateway also accepts the x-api-key header, but setting both variables at once can confuse Claude Code, so set only one.
Q3Can I use non-Claude models in Claude Code?
Claude Code is built and tested for Claude models, so use a Claude model name from the models page. For other models, use a tool that speaks the OpenAI format, such as Cursor or Cline.
Q4Do I need a Claude Pro or Max subscription?
No. With these variables set, Claude Code uses your MaCloud AI balance and is billed per token. Official subscriptions are a separate fixed monthly fee in US dollars; see the official pages for details.
Q5Does it work in VS Code or JetBrains?
Yes, as long as the integrated terminal or IDE extension sees the same environment variables. Using the env block in ~/.claude/settings.json is the most reliable way.

More guides