New: Audio API, Embeddings & Realtime WebSocket now available!
osmAPI LogoosmAPI
Guides

Claude Code + osmAPI Setup Guide

Complete step-by-step guide to install Claude Code and configure it with osmAPI on macOS, Windows & Linux.

Claude Code is Anthropic's official CLI tool for interacting with Claude directly from your terminal. By connecting it to the osmAPI gateway, you get unified model access, cost tracking, and routing — all through a single API key.

Prerequisites

  • Node.js v18+ (npm comes bundled with Node.js)
  • An active osmAPI Access Token

1. Install Node.js & npm

Option A — Using the Installer:

  1. Go to https://nodejs.org
  2. Download the LTS macOS installer (.pkg)
  3. Double-click the downloaded file and follow the wizard
  4. Open Terminal and verify:
node -v
npm -v

Option B — Using Homebrew (recommended):

brew install node

Option A — Using the Installer:

  1. Go to https://nodejs.org
  2. Download the LTS Windows installer (.msi)
  3. Run the installer — check the box "Automatically install the necessary tools"
  4. Open PowerShell or Command Prompt and verify:
node -v
npm -v

Option B — Using winget:

winget install OpenJS.NodeJS.LTS

Option C — Using nvm-windows (recommended for managing multiple versions):

  1. Download nvm-windows from https://github.com/coreybutler/nvm-windows/releases
  2. Install it, then run:
nvm install lts
nvm use lts

Option A — Using NodeSource (recommended for Ubuntu/Debian):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Option B — Using nvm (recommended for managing multiple versions):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm use --lts

Fedora/RHEL:

sudo dnf install nodejs

Verify on any Linux distro:

node -v
npm -v

2. Install Claude Code

Run this command on all platforms (macOS, Windows, Linux):

npm install -g @anthropic-ai/claude-code

On macOS/Linux, if you get a permission error, either fix npm permissions (recommended) or prefix with sudo:

sudo npm install -g @anthropic-ai/claude-code

To fix npm permissions permanently (macOS/Linux):

mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc   # or ~/.zshrc on macOS
source ~/.bashrc

On Windows, run PowerShell or CMD as Administrator if you encounter permission errors.


3. Configure osmAPI Environment Variables

You need to set three environment variables so Claude Code uses the osmAPI gateway with the glm-5 model.

Temporary (current session only):

export ANTHROPIC_BASE_URL=https://api.osmapi.com
export ANTHROPIC_AUTH_TOKEN=osm_your_api_key_here
export ANTHROPIC_MODEL=glm-5

Permanent (persists across sessions):

echo 'export ANTHROPIC_BASE_URL=https://api.osmapi.com' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN=osm_your_api_key_here' >> ~/.zshrc
echo 'export ANTHROPIC_MODEL=glm-5' >> ~/.zshrc
source ~/.zshrc

Replace osm_your_api_key_here with your actual osmAPI key from the dashboard.

Option A — PowerShell (temporary, current session):

$env:ANTHROPIC_BASE_URL = "https://api.osmapi.com"
$env:ANTHROPIC_AUTH_TOKEN = "osm_your_api_key_here"
$env:ANTHROPIC_MODEL = "glm-5"

Option B — Set permanently via System Environment Variables (GUI):

  1. Press Win + R, type sysdm.cpl, press Enter
  2. Go to Advanced tab → Environment Variables
  3. Under User variables, click New for each:
Variable NameValue
ANTHROPIC_BASE_URLhttps://api.osmapi.com
ANTHROPIC_AUTH_TOKENosm_your_api_key_here
ANTHROPIC_MODELglm-5
  1. Click OK on all dialogs
  2. Restart your terminal/PowerShell

Option C — Set permanently via PowerShell:

[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.osmapi.com", "User")
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "osm_your_api_key_here", "User")
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_MODEL", "glm-5", "User")

Then restart your terminal.

Option D — Command Prompt (permanent via setx):

setx ANTHROPIC_BASE_URL "https://api.osmapi.com"
setx ANTHROPIC_AUTH_TOKEN "osm_your_api_key_here"
setx ANTHROPIC_MODEL "glm-5"

Then restart your terminal.

Temporary (current session only):

export ANTHROPIC_BASE_URL=https://api.osmapi.com
export ANTHROPIC_AUTH_TOKEN=osm_your_api_key_here
export ANTHROPIC_MODEL=glm-5

Permanent (persists across sessions):

echo 'export ANTHROPIC_BASE_URL=https://api.osmapi.com' >> ~/.bashrc
echo 'export ANTHROPIC_AUTH_TOKEN=osm_your_api_key_here' >> ~/.bashrc
echo 'export ANTHROPIC_MODEL=glm-5' >> ~/.bashrc
source ~/.bashrc

For Fish shell users:

set -Ux ANTHROPIC_BASE_URL https://api.osmapi.com
set -Ux ANTHROPIC_AUTH_TOKEN osm_your_api_key_here
set -Ux ANTHROPIC_MODEL glm-5

4. Verify Installation

Run these commands to confirm everything is set up:

# Check Node.js and npm
node -v
npm -v

# Check Claude Code is installed
claude --version
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKEN
echo $ANTHROPIC_MODEL
echo $env:ANTHROPIC_BASE_URL
echo $env:ANTHROPIC_AUTH_TOKEN
echo $env:ANTHROPIC_MODEL

Expected output:

ANTHROPIC_BASE_URL  → https://api.osmapi.com
ANTHROPIC_AUTH_TOKEN → osm_your_api_key_here
ANTHROPIC_MODEL     → glm-5

5. Using Claude Code

Starting Claude Code

Open your terminal and navigate to your project directory:

cd /path/to/your/project
claude

Claude Code will launch in interactive mode, connected to the osmAPI gateway using the glm-5 model.

Common Commands

CommandDescription
claudeStart interactive mode in current directory
claude "your prompt here"Run a one-shot command
claude -p "your prompt"Print-only mode (no interactive session)
claude configView/edit configuration
claude updateUpdate Claude Code to the latest version

Example Usage

# Ask Claude to explain your codebase
claude "explain this codebase"

# Ask Claude to create a new file
claude "create a Python script that downloads a CSV from a URL and converts it to JSON"

# Fix a bug
claude "find and fix the bug in app.py that causes a 500 error on the /users endpoint"

# Run in a specific project
cd my-project
claude

Claude Code works best when run from your project root directory so it can see your files. Use /help inside the interactive session for available commands. Use Ctrl+C to cancel a running operation and Ctrl+D or type /exit to quit.


6. Troubleshooting

"command not found: claude"

Your global npm bin directory is not in PATH.

export PATH="$(npm config get prefix)/bin:$PATH"

Add the above line to your ~/.zshrc or ~/.bashrc to make it permanent.

Ensure the npm global directory is in your system PATH. Typically: C:\Users\<you>\AppData\Roaming\npm

"ANTHROPIC_AUTH_TOKEN not set" or Authentication Error

Double-check your environment variable is set correctly. Make sure there are no extra spaces or quotes around the value. Restart your terminal after setting permanent variables.

Permission errors during npm install

  • macOS/Linux: Use the npm prefix fix described in Section 2, or use sudo.
  • Windows: Run your terminal as Administrator.

Network / Proxy Issues

If you're behind a corporate proxy, set the proxy for npm:

npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

Updating Claude Code

npm update -g @anthropic-ai/claude-code

Quick Reference

┌─────────────────────────────────────────────────────────┐
│                 osmAPI + Claude Code                    │
├─────────────────────────────────────────────────────────┤
│  ANTHROPIC_BASE_URL   = https://api.osmapi.com          │
│  ANTHROPIC_AUTH_TOKEN = osm_your_api_key_here       │
│  ANTHROPIC_MODEL      = glm-5                           │
├─────────────────────────────────────────────────────────┤
│  Install:   npm install -g @anthropic-ai/claude-code    │
│  Run:       claude                                      │
│  Update:    npm update -g @anthropic-ai/claude-code     │
└─────────────────────────────────────────────────────────┘

How is this guide?