Skip to main content
Claude Code is Anthropic’s coding agent for the terminal, IDEs, and desktop. It talks to the Anthropic Messages API, which NEAR AI Cloud serves at https://cloud-api.near.ai/v1/messages for its Anthropic models. Point Claude Code at NEAR AI Cloud and it runs on your NEAR AI Cloud API key and credits instead of an Anthropic account.
The Messages endpoint serves Anthropic models only, such as anthropic/claude-sonnet-5-5. Claude models on NEAR AI Cloud are in the Incognito privacy tier; see Available Models. To use open models such as GLM or Qwen in a coding agent, use Codex CLI, OpenCode, or another OpenAI-compatible tool.

Prerequisites

  • Claude Code installed (checked with 2.1.325).
  • A NEAR AI Cloud account with credits. Usage is billed per token from your NEAR AI Cloud credits; a Claude subscription is not used.
  • A NEAR AI Cloud API key. In the NEAR AI Cloud Dashboard, open API Keys and create a key.

Configure

Claude Code needs two settings: Use the base URL without /v1. Claude Code appends /v1/messages itself, so https://cloud-api.near.ai/v1 would produce /v1/v1/messages.

Try it in one terminal

These variables last until you close the terminal.

Make it permanent

Add the same values to the env block of your user settings file, ~/.claude/settings.json:
~/.claude/settings.json
If the file already exists, add the env entries to it rather than replacing it.
Use your user settings file, not a project’s .claude/settings.json. Project settings are often committed to source control, which would publish your key.
Run /status inside Claude Code to confirm. It shows the Anthropic base URL and that an auth token is in use.

If you already sign in with a Claude account

You do not need to sign out. When ANTHROPIC_AUTH_TOKEN is set, Claude Code sends that key instead of your Claude login, and the login stays saved on your machine. Claude Code may show a startup warning that both are present; that is expected. To switch back to your Claude subscription, unset the two variables or remove them from settings.json, then restart Claude Code.
Setting only ANTHROPIC_BASE_URL is not enough. Without ANTHROPIC_AUTH_TOKEN, Claude Code keeps using your Claude login, which NEAR AI Cloud rejects with 401.
ANTHROPIC_API_KEY also works with NEAR AI Cloud. In interactive mode, Claude Code asks once whether to use a key set that way. ANTHROPIC_AUTH_TOKEN avoids the prompt.

Choose a model

Claude Code’s default model IDs, such as claude-opus-5-5, work as they are. NEAR AI Cloud resolves a Claude model ID without a prefix to the matching anthropic/ model. To pick a different model, use /model inside Claude Code, or set ANTHROPIC_MODEL:
List the Claude models available on NEAR AI Cloud:

Quick test

If Claude Code fails, test the key and model directly against the Messages endpoint first:
A successful response confirms that your key works with this model. If Claude Code still fails, check its error against the troubleshooting table below.

Troubleshooting

Sources Checked

Sources checked on 2026-11-16, against Claude Code 2.1.325. A Claude Code session that writes a file and runs a shell command was run against NEAR AI Cloud with the default model, and a short prompt with ANTHROPIC_MODEL=claude-sonnet-5-5.