AI Space

Open AI Sharing Platform

API Setup Guide

Comprehensive tutorials for Claude Code and Codex CLI configuration.

Windows Configuration

Tutorial for configuring Claude Code and Codex CLI on Windows.

I. Environment Prep

1. Install Node.js

Ensure Node.js is installed (v18+ recommended):

# Check Node.js version node --version # If missing, download from: https://nodejs.org/

2. Install Claude Code CLI

# Install globally via npm npm install -g @anthropic-ai/claude-code

3. Install Codex CLI

# Install globally via npm npm install -g @openai/codex

II. Configure Claude Code

Method 1: Use Environment Variables

Open PowerShell or Command Prompt:

# Set API Base URL (your proxy address) set ANTHROPIC_BASE_URL=https://your-api-proxy.com # Set API Key (your key) set ANTHROPIC_API_KEY=sk-your-api-key-here # Start Claude Code claude

Method 2: Permanent Configuration

  1. Right-click 'This PC' → 'Properties' → 'Advanced system settings'
  2. Click 'Environment Variables'
  3. Click 'New' under 'User variables'
  4. Add the following variables:
    Variable Name: ANTHROPIC_BASE_URL Variable Value: https://your-api-proxy.com Variable Name: ANTHROPIC_API_KEY Variable Value: sk-your-api-key-here
  5. Click 'OK' to save, restart terminal to take effect

III. Configure Codex CLI

# Set OpenAI API Base URL set OPENAI_BASE_URL=https://your-api-proxy.com/v1 # Set API Key set OPENAI_API_KEY=sk-your-api-key-here # Start Codex codex
Tip: Add to permanent config to avoid resetting on reboot.

IV. Verify Configuration

# Test Claude Code claude --version claude "Hello, this is a test" # Test Codex codex --version codex "Write a hello world in Python"

macOS Configuration

Tutorial for configuring Claude Code and Codex CLI on macOS.

I. Environment Prep

1. Install Homebrew (if missing)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install Node.js

# Install via Homebrew brew install node # Verify installation node --version npm --version

3. Install Claude Code & Codex CLI

# Install Claude Code npm install -g @anthropic-ai/claude-code # Install Codex npm install -g @openai/codex

II. Configure Claude Code

Method 1: Temporary (Session only)

# Set API Base URL export ANTHROPIC_BASE_URL="https://your-api-proxy.com" # Set API Key export ANTHROPIC_API_KEY="sk-your-api-key-here" # Start Claude Code claude

Method 2: Permanent (Recommended)

Edit your shell profile:

# If using zsh (macOS default) nano ~/.zshrc # If using bash nano ~/.bash_profile

Append the following:

# Claude Code API Config export ANTHROPIC_BASE_URL="https://your-api-proxy.com" export ANTHROPIC_API_KEY="sk-your-api-key-here" # Codex API Config export OPENAI_BASE_URL="https://your-api-proxy.com/v1" export OPENAI_API_KEY="sk-your-api-key-here"

Save and reload configuration:

# Reload configuration source ~/.zshrc # 或 source ~/.bash_profile

IV. Verify Configuration

# Check if env vars are set echo $ANTHROPIC_BASE_URL echo $ANTHROPIC_API_KEY # Test Claude Code claude "Hello, this is a test" # Test Codex codex "Write a hello world in Python"
Note: Do not commit API keys to public repos

Linux Configuration

Tutorial for configuring Claude Code and Codex CLI on Linux.

I. Environment Prep

1. Install Node.js

Install latest Node.js via NodeSource:

# Ubuntu/Debian curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs # CentOS/RHEL/Fedora curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash - sudo yum install -y nodejs # Arch Linux sudo pacman -S nodejs npm # Verify installation node --version npm --version

3. Install Claude Code & Codex CLI

# Install Claude Code sudo npm install -g @anthropic-ai/claude-code # Install Codex sudo npm install -g @openai/codex

II. Configure Claude Code

Method 1: Temporary (Session only)

# Set env vars and start export ANTHROPIC_BASE_URL="https://your-api-proxy.com" export ANTHROPIC_API_KEY="sk-your-api-key-here" claude

Method 2: Permanent Configuration

Edit your shell profile:

# Use your preferred editor vim ~/.bashrc # OR nano ~/.bashrc

Append the following:

# ===== API Config ===== # Claude Code API Config export ANTHROPIC_BASE_URL="https://your-api-proxy.com" export ANTHROPIC_API_KEY="sk-your-api-key-here" # Codex API Config export OPENAI_BASE_URL="https://your-api-proxy.com/v1" export OPENAI_API_KEY="sk-your-api-key-here"

Save and reload configuration:

source ~/.bashrc

Method 3: Systemd User Service (Desktop)

# Create/Edit env file mkdir -p ~/.config/environment.d nano ~/.config/environment.d/api.conf

Append the following:

ANTHROPIC_BASE_URL=https://your-api-proxy.com ANTHROPIC_API_KEY=sk-your-api-key-here OPENAI_BASE_URL=https://your-api-proxy.com/v1 OPENAI_API_KEY=sk-your-api-key-here

IV. Verify Configuration

# Verify environment variables env | grep -E "(ANTHROPIC|OPENAI)" # Test Claude Code claude --version claude "Hello, this is a test" # Test Codex codex --version codex "Write a hello world in Python"
Tip: If you face permission issues, consider using nvm (Node Version Manager) to avoid using sudo for global packages.

IV. Troubleshooting

# Check network connection curl -I https://your-api-proxy.com/v1 # Check DNS resolution nslookup your-api-proxy.com # If using a proxy export https_proxy=http://127.0.0.1:7890 export http_proxy=http://127.0.0.1:7890

Common Configuration

Supported Environment Variables

Tool Env Variable Description
Claude Code ANTHROPIC_BASE_URL API Base URL
Claude Code ANTHROPIC_API_KEY API Key
Codex OPENAI_BASE_URL API Base URL
Codex OPENAI_API_KEY API Key
Security Notice:
  • Do not commit API keys to public repos
  • Rotate your API keys regularly
  • Use environment variables instead of hardcoding
  • Clear env vars after using shared devices