> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apimart.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Using APIMart in Claude Code

> A detailed guide on configuring and using APIMart API services in Claude Code CLI, enabling you to access multiple AI models for assisted programming with simple configuration.

<Frame>
  <img src="https://mintcdn.com/apicore/_4UKBib4iqrgK4Ws/images/integrations/claude-code/claude-code-cli.png?fit=max&auto=format&n=_4UKBib4iqrgK4Ws&q=85&s=219739f4029aa915b90253ad02b01437" alt="Claude Code Main Interface" width="2574" height="360" data-path="images/integrations/claude-code/claude-code-cli.png" />
</Frame>

## Prerequisites

Claude Code is a command-line AI programming assistant by Anthropic that supports direct AI conversation, code generation, and debugging in the terminal.
By connecting to APIMart, you can use multiple models including GPT, Claude, and Gemini within Claude Code.

Before you begin, make sure you have:

1. **Obtained an APIMart API Key**
   Log in to the [APIMart Console](https://apimart.ai/keys) to get your API key (starts with `sk-`)

<Note>**Tip:** If you don't have an APIMart account yet, please register at [APIMart](https://apimart.ai) first and obtain your API key.</Note>

## Step 1: Install Claude Code

Choose any of the following methods to install:

<Tabs>
  <Tab title="macOS / Linux (Recommended)">
    Install with the official script:

    ```bash theme={null}
    curl -fsSL https://claude.ai/install.sh | bash
    ```

    Or install via Homebrew:

    ```bash theme={null}
    brew install --cask claude-code
    ```

    <Note>If you encounter permission issues, add `sudo` before the command.</Note>
  </Tab>

  <Tab title="Windows">
    **PowerShell:**

    ```powershell theme={null}
    irm https://claude.ai/install.ps1 | iex
    ```

    **CMD:**

    ```cmd theme={null}
    curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
    ```
  </Tab>

  <Tab title="NPM Install">
    If you have Node.js 18 or newer installed, you can install via npm:

    ```bash theme={null}
    npm install -g @anthropic-ai/claude-code
    ```

    Works on all operating systems.
  </Tab>
</Tabs>

### Verify Installation

After installation, run the following command to confirm:

```bash theme={null}
claude --version
```

If a version number is displayed (e.g., `1.x.x`), the installation was successful.

## Step 2: Configure APIMart API

Three configuration methods are available. Choose the one that suits your workflow.

### Method 1: Edit settings.json (Recommended)

The most stable approach — configure once and it persists.

**1. Locate the configuration directory:**

* Windows: Press `Win + R`, enter `%userprofile%\.claude`
* macOS: Press `Command + Shift + G`, enter `~/.claude`
* Linux: Navigate to `~/.claude`

<Note>If the directory doesn't exist, run `claude` once in the terminal and press `Ctrl + C` to exit — the directory will be created automatically.</Note>

**2. Create or edit the `settings.json` file:**

```json theme={null}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.apimart.ai",
    "ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxxxxxx",
    "ANTHROPIC_MODEL": "claude-sonnet-4-6-apimart",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}
```

| Parameter                                  | Description                                            |
| ------------------------------------------ | ------------------------------------------------------ |
| `ANTHROPIC_BASE_URL`                       | APIMart API address, fixed as `https://api.apimart.ai` |
| `ANTHROPIC_AUTH_TOKEN`                     | Your APIMart API key (starts with `sk-`)               |
| `ANTHROPIC_MODEL`                          | Default model to use, choose from the model list below |
| `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` | Set to `1` to reduce non-essential network requests    |

Save the file and restart Claude Code to apply.

### Method 2: Permanent Environment Variables

Write configuration to system environment so all terminal windows load it automatically.

<Tabs>
  <Tab title="macOS (zsh)">
    ```bash theme={null}
    echo 'export ANTHROPIC_BASE_URL="https://api.apimart.ai"' >> ~/.zshrc
    echo 'export ANTHROPIC_API_KEY="sk-xxxxxxxxxxxx"' >> ~/.zshrc
    echo 'export ANTHROPIC_MODEL="claude-sonnet-4-6-apimart"' >> ~/.zshrc
    source ~/.zshrc
    ```
  </Tab>

  <Tab title="macOS / Linux (bash)">
    ```bash theme={null}
    echo 'export ANTHROPIC_BASE_URL="https://api.apimart.ai"' >> ~/.bashrc
    echo 'export ANTHROPIC_API_KEY="sk-xxxxxxxxxxxx"' >> ~/.bashrc
    echo 'export ANTHROPIC_MODEL="claude-sonnet-4-6-apimart"' >> ~/.bashrc
    source ~/.bashrc
    ```
  </Tab>

  <Tab title="Windows">
    **Option A: GUI Settings**

    1. Right-click "This PC" → "Properties" → "Advanced system settings" → "Environment Variables"
    2. Add new user variables:
       * `ANTHROPIC_BASE_URL` = `https://api.apimart.ai`
       * `ANTHROPIC_API_KEY` = `sk-xxxxxxxxxxxx`
       * `ANTHROPIC_MODEL` = `claude-sonnet-4-6-apimart`
    3. Restart the terminal

    **Option B: PowerShell Commands**

    ```powershell theme={null}
    [System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://api.apimart.ai', 'User')
    [System.Environment]::SetEnvironmentVariable('ANTHROPIC_API_KEY', 'sk-xxxxxxxxxxxx', 'User')
    [System.Environment]::SetEnvironmentVariable('ANTHROPIC_MODEL', 'claude-sonnet-4-6-apimart', 'User')
    ```
  </Tab>
</Tabs>

### Method 3: Temporary Environment Variables

Suitable for quick testing — configuration is lost when the terminal is closed.

<Tabs>
  <Tab title="macOS / Linux">
    ```bash theme={null}
    export ANTHROPIC_API_KEY="sk-xxxxxxxxxxxx"
    export ANTHROPIC_MODEL="claude-sonnet-4-6-apimart"
    export ANTHROPIC_BASE_URL="https://api.apimart.ai"
    claude
    ```
  </Tab>

  <Tab title="Windows (PowerShell)">
    ```powershell theme={null}
    $env:ANTHROPIC_API_KEY="sk-xxxxxxxxxxxx"
    $env:ANTHROPIC_MODEL="claude-sonnet-4-6-apimart"
    $env:ANTHROPIC_BASE_URL="https://api.apimart.ai"
    claude
    ```
  </Tab>

  <Tab title="Windows (CMD)">
    ```cmd theme={null}
    set ANTHROPIC_API_KEY=sk-xxxxxxxxxxxx
    set ANTHROPIC_MODEL=claude-sonnet-4-6-apimart
    set ANTHROPIC_BASE_URL=https://api.apimart.ai
    claude
    ```
  </Tab>
</Tabs>

<Warning>Temporary environment variables only work in the current terminal window. You'll need to set them again after switching windows or closing the terminal.</Warning>

## Step 3: Start Using

### Verify Configuration

Launch Claude Code and send a simple message to confirm:

```bash theme={null}
claude "Hello"
```

If you receive an AI response, the configuration is successful. If you see `401`, `403`, or other errors, refer to the FAQ below.

### Usage Modes

Claude Code offers two interaction modes:

* **Interactive mode**: Run `claude` for continuous conversation, ideal for complex tasks
* **Single command**: Run `claude "your question"` for a one-off response, ideal for quick queries

### Supported Models

APIMart supports the full Claude model series. You can flexibly switch based on your needs:

| Model Name                   | Features                       | Recommended Use                           |
| ---------------------------- | ------------------------------ | ----------------------------------------- |
| `claude-opus-4-6`            | Strongest overall capability   | Complex architecture, difficult debugging |
| `claude-sonnet-4-6`          | Balanced performance and speed | Daily programming, code generation        |
| `claude-opus-4-5-20251101`   | Advanced reasoning             | Complex code, deep analysis               |
| `claude-sonnet-4-5-20250929` | Excellent code capability      | Algorithm design, code optimization       |
| `claude-haiku-4-5-20251001`  | Ultra-fast response            | Quick Q\&A, code snippets                 |

All models above support a Thinking (extended reasoning) version — append `-thinking` to the model ID, e.g., `claude-opus-4-6-thinking`. Thinking mode is ideal for complex tasks requiring deep reasoning.

#### APIMart Discounted Models

APIMart offers exclusive discounted models at **only 20% of the official price**, with the same capabilities. Simply append `-apimart` to the model ID:

| Discounted Model Name                | Features                       |
| ------------------------------------ | ------------------------------ |
| `claude-opus-4-6-apimart`            | Strongest overall capability   |
| `claude-sonnet-4-6-apimart`          | Balanced performance and speed |
| `claude-opus-4-5-20251101-apimart`   | Advanced reasoning             |
| `claude-sonnet-4-5-20250929-apimart` | Excellent code capability      |
| `claude-haiku-4-5-20251001-apimart`  | Ultra-fast response            |

Thinking versions are also available, e.g., `claude-opus-4-6-thinking-apimart`, `claude-sonnet-4-6-thinking-apimart`, etc.

<Tip>
  **Model Recommendations:**

  * 💰 **Best Value:** `claude-sonnet-4-6-apimart` — Best choice for daily programming, only 20% of official price
  * 🚀 **High Performance:** `claude-opus-4-6-apimart` — For the most complex code and architecture challenges
  * ⚡ **Fast Response:** `claude-haiku-4-5-20251001-apimart` — When you need instant feedback
  * 🧠 **Deep Thinking:** `claude-opus-4-6-thinking-apimart` — When deep reasoning is needed
</Tip>

To switch models, use the `/model` command in interactive mode, or modify the `ANTHROPIC_MODEL` field in your configuration and restart.

### Common Commands

Here are frequently used commands and shortcuts in Claude Code:

| Command             | Description                      |
| ------------------- | -------------------------------- |
| `claude`            | Enter interactive mode           |
| `claude "question"` | Single query                     |
| `claude --version`  | Check version                    |
| `/model`            | Switch model in interactive mode |
| `/help`             | View help information            |
| `Ctrl + C`          | Exit interactive mode            |

## FAQ

### Q1: Still seeing the login selection page after configuration?

If "Select login method" still appears after startup, the configuration hasn't taken effect.

**Troubleshooting steps:**

1. **Using settings.json**: Check if the file path is correct
   * Windows: `C:\Users\<username>\.claude\settings.json`
   * macOS / Linux: `~/.claude/settings.json`
2. **Using environment variables**: Make sure you launched Claude Code from the **same terminal window** where you set the variables
3. **Check JSON format**: Ensure brackets, commas, and quotes are all correct

### Q2: Getting 401 / 403 errors?

| Error Code         | Meaning                                 | Solution                                                      |
| ------------------ | --------------------------------------- | ------------------------------------------------------------- |
| `401 Unauthorized` | API key missing or invalid              | Check if the key is correct and starts with `sk-`             |
| `403 Forbidden`    | Insufficient permissions or expired key | Go to [Console](https://apimart.ai/keys) to verify key status |

Also ensure `ANTHROPIC_BASE_URL` is set to `https://api.apimart.ai`, not the official Anthropic address.

### Q3: "Unable to connect" error?

This means Claude Code failed to connect to the API service.

1. Check your network connection
2. Verify `ANTHROPIC_BASE_URL` is configured correctly
3. If using a proxy, ensure it allows access to `api.apimart.ai`

### Q4: "Auth conflict" error?

If you see a message like:

```
Auth conflict: Both a token (claude.ai) and an API key (ANTHROPIC_API_KEY) are set.
```

This means you're logged into claude.ai and have an API Key set at the same time, causing a conflict.

**Solution:** Run `/logout` in Claude Code interactive mode to sign out of claude.ai, keeping only the API Key configuration.

### Q5: max\_tokens error when using non-Claude models?

If you see an error like:

```
max_tokens is too large: 32000. This model supports at most 16384 completion tokens.
```

This is because Claude Code sends requests with Claude model parameters by default (32000 tokens), while some non-Claude models (e.g., `gpt-4o`) have lower token limits.

**Solution:** Switch to a Claude model (e.g., `claude-sonnet-4-6-apimart`), which is natively compatible with Claude Code and won't cause this issue.

### Q6: Slow response?

1. Switch to a faster model (e.g., `claude-haiku-4-5-20251001-apimart` or `claude-sonnet-4-6-apimart`)
2. Shorten your prompts to reduce context length
3. Check your network conditions

### Q7: How to switch models?

Two ways:

1. **In interactive mode**: Enter the `/model` command
2. **Edit configuration**: Change the `ANTHROPIC_MODEL` field in `settings.json` or environment variables, then restart Claude Code

### Q8: Does Claude Code automatically read local files?

No. Claude Code requires you to explicitly reference files, and it will ask for confirmation before performing sensitive operations. It's recommended to use it in dedicated project directories.

### Q9: How to analyze local files with Claude Code?

In interactive mode, you can reference files by:

* Entering the file path directly
* Dragging files into the terminal window
* Copy-pasting file content

### Q10: How to check usage and costs?

Log in to the [APIMart Console](https://apimart.ai/overview) to view:

* API call statistics
* Token consumption details
* Cost statistics and trends

## Support

If you encounter any issues:

* 📚 [APIMart Documentation](https://docs.apimart.ai)
* 💬 [Discord Community](https://discord.gg/V8zqssyZ5c)
* 🐦 [Twitter @APIMart\_](https://x.com/APIMart_)
* 📧 Technical Support: [zhihong@apimart.ai](mailto:zhihong@apimart.ai)

***

<Card title="Get Started with APIMart" icon="rocket" href="https://apimart.ai">
  Sign up for APIMart now, get your API key, and experience multi-model programming assistant in Claude Code!
</Card>
