Home / Learn / Claude Code API key setup with CAK
Claude Code API key setup with CAK

Claude Code API key setup with CAK

This walkthrough connects Claude Code to a CAK gateway key. It covers paid access, shell configuration and a small connection check before you run a coding task.

Reviewed 2026-10-10 · Claude API documentation

Before you start

You need a CAK account, an API key for the intended group, and either an active subscription or funded prepaid access for that group. A new account with a $0 balance does not have funded API usage. Registration and API access are separate steps.

Install Claude Code using its official setup instructions. The CAK key is a gateway credential; it is not your Claude.ai login or a key issued by Anthropic Console.

1. Activate access and create a key

Choose a timed plan or read the prepaid credit guide. After activation, open API Keys. Select the group that matches your purchase when creating the key. For a timed plan, choose Claude Unlimited.

Keep the credential in your own environment. Do not paste it into a public repository, screenshot, issue, or this website’s calculator.

2. Set the base URL and credential

Start with a temporary terminal session so you can verify the configuration before saving it permanently. The following examples prompt for the key instead of storing it in the command text.

macOS or Linux: Bash

export ANTHROPIC_BASE_URL="https://claudeapikey.dev"
read -rsp "CAK API key: " ANTHROPIC_API_KEY; printf '\n'
export ANTHROPIC_API_KEY
curl --fail-with-body --silent --show-error \
  "$ANTHROPIC_BASE_URL/v1/models" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01"

Windows: PowerShell

$env:ANTHROPIC_BASE_URL = "https://claudeapikey.dev"
$keyInput = Read-Host "CAK API key" -AsSecureString
$env:ANTHROPIC_API_KEY = [System.Net.NetworkCredential]::new("", $keyInput).Password
Invoke-RestMethod -Uri "$env:ANTHROPIC_BASE_URL/v1/models" -Headers @{
  "x-api-key" = $env:ANTHROPIC_API_KEY
  "anthropic-version" = "2023-06-01"
}

These commands list models; they do not generate a response. Use the model IDs returned for this key. A successful list verifies authentication and discovery, but a short generation request is still needed to check inference.

3. Verify a short message

Download the CAK API starter. It includes dependency-free Python and Node.js clients, model listing and readable error handling. Set CAK_API_KEY and CAK_MODEL as described there, then run its short message check. The message uses your plan or credits.

If authentication fails, check the group and the credential before changing the model. If the model is unavailable, re-read the list for this key. A request returning 200 verifies that request; it does not certify every tool feature.

4. Launch Claude Code from this terminal

claude --model YOUR_MODEL_ID

Replace YOUR_MODEL_ID with an ID returned by the gateway. Use /status inside Claude Code to check the active configuration. If another credential is already set, resolve that conflict rather than setting both credential variables without knowing which one the client uses.

For persistent configuration, use Claude Code’s documented user or local settings, or your shell profile. An editor launched from the Start menu or dock might not inherit variables exported in a terminal. Do not assume a project .env file is automatically loaded.

If the first request fails

The troubleshooting guide explains the checks and what information to send support.

Reference

CAK-specific URLs and plan behavior are documented here. For client configuration and credential precedence, consult the official Claude Code gateway guide.

Questions

Do I need an Anthropic Console key?
For this gateway setup, use a key generated in your CAK account. A direct Anthropic key and a CAK key belong to different services.
Can a new account make free requests?
Registration alone does not fund requests. Activate an eligible plan or add prepaid credits for the chosen group. Only a specific offer that is actually granted to your account changes this.
Should I put /v1 in ANTHROPIC_BASE_URL?
Use https://claudeapikey.dev for this Anthropic-format setup. The client adds the endpoint path. An OpenAI-compatible client normally uses https://claudeapikey.dev/v1 instead.
Will a project .env file configure Claude Code automatically?
Do not rely on that. Export the variables in the shell that launches the CLI, or configure its documented settings. A .env file only works when the program or your launcher explicitly loads it.

Claude API is an independent gateway and is not affiliated with or endorsed by Anthropic. Claude and Anthropic are trademarks of their respective owners.