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

# Use Claude Code with CometAPI

> Use this guide to configure Claude Code with CometAPI through Anthropic-compatible credentials, base URL settings, and Claude model IDs.

Use this guide to connect [Claude Code](https://code.claude.com/docs/en/overview) to CometAPI.

Official references:

* [Claude Code Overview](https://code.claude.com/docs/en/overview)
* [Claude Code Getting Started](https://code.claude.com/docs/en/getting-started)

<Note>
  Model availability changes over time. For current Claude model IDs, check
  the [CometAPI Models page](/overview/models).
</Note>

## Prerequisites

* A CometAPI key from your [dashboard](https://www.cometapi.com) (starts with `sk-`)
* Git installed
* Supported OS: macOS, Linux, or Windows

## Install Claude Code

<Steps>
  <Step title="Run the official installer">
    <Tabs>
      <Tab title="macOS / Linux">
        ```bash theme={null}
        curl -fsSL https://claude.ai/install.sh | bash
        ```
      </Tab>

      <Tab title="Homebrew">
        ```bash theme={null}
        brew install --cask claude-code
        ```
      </Tab>

      <Tab title="Windows">
        PowerShell:

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

        CMD:

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

        <Info>Windows requires [Git for Windows](https://git-scm.com/downloads/win) installed first.</Info>
      </Tab>
    </Tabs>
  </Step>

  <Step title="Verify installation">
    ```bash theme={null}
    claude --version
    ```
  </Step>
</Steps>

## Configure CometAPI endpoint

Create or edit the settings file:

* macOS / Linux: `~/.claude/settings.json`
* Windows: `%USERPROFILE%\.claude\settings.json`

```json theme={null}
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-your-cometapi-key",
    "ANTHROPIC_BASE_URL": "https://api.cometapi.com"
  }
}
```

Replace `sk-your-cometapi-key` with your actual CometAPI key, then start Claude Code:

```bash theme={null}
cd your-project
claude
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="settings.json does not take effect">
    1. Restart your terminal completely by closing all windows and reopening it.
    2. If it still does not work, create `~/.claude.json` and add:

    ```json theme={null}
    {
      "hasCompletedOnboarding": true
    }
    ```

    3. As a fallback, export environment variables directly:

    ```bash theme={null}
    # Add to ~/.zshrc (macOS) or ~/.bashrc (Linux)
    export ANTHROPIC_AUTH_TOKEN="sk-your-cometapi-key"
    export ANTHROPIC_BASE_URL="https://api.cometapi.com"
    ```
  </Accordion>

  <Accordion title="Invalid API Key or Please run /login">
    Check that `~/.claude/settings.json` exists and the JSON format is valid with no trailing commas and correct quotes. Validate at [jsonlint.com](https://jsonlint.com).
  </Accordion>

  <Accordion title="Cached official credentials are used">
    Claude Code prioritizes cached official credentials. Run `/logout` inside Claude Code, close it, then restart.

    If it still fails, remove the cached auth file:

    ```bash theme={null}
    rm -rf ~/.config/claude-code/auth.json
    ```
  </Accordion>

  <Accordion title="Status shows offline">
    Claude Code checks connectivity via Google. `offline` means Google is unreachable. This does not affect CometAPI usage.
  </Accordion>

  <Accordion title="Fetch or web browsing fails">
    Claude Code's Fetch feature calls Anthropic's native service first, which requires direct internet access. A system-wide proxy may be needed.
  </Accordion>
</AccordionGroup>

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/claude-code#howto",
        "name": "Use Claude Code with CometAPI",
        "description": "Use this guide to configure Claude Code with CometAPI through Anthropic-compatible credentials, base URL settings, and Claude model IDs.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/claude-code#step-1",
            "position": 1,
            "name": "Review prerequisites",
            "text": "Complete the Review prerequisites step in the Use Claude Code with CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/claude-code#step-2",
            "position": 2,
            "name": "Install Claude Code",
            "text": "Complete the Install Claude Code step in the Use Claude Code with CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/claude-code#step-3",
            "position": 3,
            "name": "Configure CometAPI endpoint",
            "text": "Complete the Configure CometAPI endpoint step in the Use Claude Code with CometAPI guide."
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI Docs",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Integrations",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "Use Claude Code with CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/claude-code"
          }
        ]
      }
    ]
    }
    `}
</script>
