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

# Claude Code

> Anthropic's official Claude Code CLI connected directly to FortAPI

[Claude Code](https://docs.claude.com/en/docs/claude-code/overview) is Anthropic's official command-line coding assistant. It hits `api.anthropic.com` by default — set **`ANTHROPIC_BASE_URL`** to point it at FortAPI instead, no proxy layer required.

<Note>
  This page covers **direct** setup. If you'd rather manage multiple providers in a GUI, see [CC Switch](/en/integrations/ccswitch).
</Note>

## Prerequisites

<Steps>
  <Step title="FortAPI API key">
    Console → **Tokens** → **Create token** to get a `sk-...` string. See [API keys & security](/en/authentication).
  </Step>

  <Step title="Node.js ≥ 18">
    Claude Code needs Node.js 18+. Check with:

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

    If missing, grab the LTS from [nodejs.org](https://nodejs.org), or on macOS:

    ```bash theme={null}
    brew install node
    ```
  </Step>
</Steps>

## Install Claude Code

<Tabs>
  <Tab title="macOS / Linux">
    ```bash theme={null}
    npm install -g @anthropic-ai/claude-code
    ```

    Confirm:

    ```bash theme={null}
    claude --version
    ```
  </Tab>

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

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

    <Warning>
      Some Claude Code shell features assume a Unix-like environment. We recommend **WSL2** on Windows — follow the macOS / Linux path inside it.
    </Warning>
  </Tab>
</Tabs>

## Point Claude Code at FortAPI

Three configuration methods, in order of preference:

### Method 1: `settings.json` (recommended)

Edit `~/.claude/settings.json` (macOS / Linux) or `%USERPROFILE%\.claude\settings.json` (Windows). Create it if missing. Replace `your-model-name` with any model name from the pricing page on the main site:

```json theme={null}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://www.fortapi.com",
    "ANTHROPIC_API_KEY": "sk-your-FortAPI-token",
    "ANTHROPIC_MODEL": "your-model-name",
    "ANTHROPIC_SMALL_FAST_MODEL": "your-model-name"
  }
}
```

<Warning>
  Do **not** append `/v1` to `ANTHROPIC_BASE_URL`. The Anthropic SDK adds `/v1/messages` itself, and an extra `/v1` causes 404s.
</Warning>

<AccordionGroup>
  <Accordion title="What each field does">
    | Field                        | Meaning                                                                                                             |
    | ---------------------------- | ------------------------------------------------------------------------------------------------------------------- |
    | `ANTHROPIC_BASE_URL`         | The FortAPI endpoint                                                                                                |
    | `ANTHROPIC_API_KEY`          | Your FortAPI token (**not** the official Anthropic key)                                                             |
    | `ANTHROPIC_MODEL`            | Default Claude model. `claude-sonnet` is the best price/performance balance                                         |
    | `ANTHROPIC_SMALL_FAST_MODEL` | Tiny model Claude Code uses for internal tasks (title generation, path completion) — `claude-haiku` keeps costs low |
  </Accordion>
</AccordionGroup>

### Method 2: shell env vars

For a quick trial:

<Tabs>
  <Tab title="macOS / Linux (zsh / bash)">
    ```bash theme={null}
    export ANTHROPIC_BASE_URL="https://www.fortapi.com"
    export ANTHROPIC_API_KEY="sk-your-key"
    claude
    ```

    Add the same lines to `~/.zshrc` or `~/.bashrc` to make them permanent.
  </Tab>

  <Tab title="Windows (PowerShell)">
    ```powershell theme={null}
    $env:ANTHROPIC_BASE_URL = "https://www.fortapi.com"
    $env:ANTHROPIC_API_KEY  = "sk-your-key"
    claude
    ```

    For permanent:

    ```powershell theme={null}
    [Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://www.fortapi.com", "User")
    [Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-your-key", "User")
    ```
  </Tab>
</Tabs>

### Method 3: use CC Switch

If you bounce between FortAPI and your official account, install [CC Switch](/en/integrations/ccswitch) and manage providers from a GUI.

## First call

Open a new terminal (so env vars are loaded), `cd` into any project:

```bash theme={null}
cd ~/some-project
claude
```

In the interactive prompt, ask the simplest possible thing:

```
> Reply with one English sentence: hello
```

You should get an immediate Claude reply, and the FortAPI Console → **Logs** should show the request with a token-level cost line.

<Tip>
  To double-check the call really went through FortAPI, open FortAPI Console → **Logs** and look at the newest entry — the model name should match `claude-sonnet` (or whatever you configured).
</Tip>

## Switch models on the fly

Inside a session, run `/model` with any model name from the pricing page on the main site:

```
/model your-model-name
```

Full model list on the [Pricing page](https://www.fortapi.com).

## Troubleshooting

<AccordionGroup>
  <Accordion title="401 Unauthorized / Invalid API key">
    * `ANTHROPIC_API_KEY` must be your **FortAPI** token (`sk-...`), not Anthropic's `sk-ant-...`.
    * Watch for trailing whitespace or line breaks when copying.
    * In FortAPI Console → **Tokens**, confirm the key is enabled and that the model allowlist (if any) doesn't exclude the model you're calling.
  </Accordion>

  <Accordion title="404 / model not found">
    * Typo in the model ID. Claude model families on FortAPI match Anthropic's naming: `claude-sonnet`, `claude-opus`, `claude-haiku`.
    * Don't add `/v1` to `ANTHROPIC_BASE_URL`.
  </Accordion>

  <Accordion title="403 / insufficient balance">
    Check USD balance on the Console home page. Long-context conversations and tool calls burn tokens fast.
  </Accordion>

  <Accordion title="Network timeout / can't connect">
    * Verify reachability: `curl -I https://www.fortapi.com`
    * If you're behind a corporate proxy, make sure `HTTPS_PROXY` isn't routing to a dead endpoint.
    * No VPN required.
  </Accordion>

  <Accordion title="Keep both the official account and FortAPI">
    Use [CC Switch](/en/integrations/ccswitch) for one-click toggling, or [direnv](https://direnv.net/) to bind different env vars per project directory.
  </Accordion>
</AccordionGroup>

## Advanced

* **MCP servers**: independent of which backend API you use — configure as usual.
* **Tool calls / function calling**: FortAPI forwards Anthropic's tool calls unchanged.
* **Streaming / SSE**: on by default, nothing extra to configure.

For more Claude Code tips, see the [official documentation](https://docs.claude.com/en/docs/claude-code/overview).
