DEV Community

APIVAI
APIVAI

Posted on • Originally published at apivai.com

How to Set Up Claude Code with a Cheap API Provider

What is Claude Code?

Claude Code is Anthropic's official CLI tool that lets you use Claude directly in your terminal. It's incredibly powerful for coding, debugging, and automating development tasks.

The problem? It uses the Anthropic API, which means you're paying $3/$15 per million tokens for Sonnet, or $5/$25 for Opus.

The Solution: Use a Cheaper API Provider

Instead of connecting directly to Anthropic, you can route Claude Code through APIVAI — an API gateway that offers the same models at up to 90% off.

What changes: One environment variable (the base URL)
What stays the same: Everything else — same models, same quality, same features

Setup Guide

Prerequisites

  • Claude Code installed (npm install -g @anthropic-ai/claude-code)
  • A APIVAI account (sign up here)
  • An API key from your APIVAI dashboard

Mac / Linux

Add these to your ~/.bashrc or ~/.zshrc for permanent setup:

export ANTHROPIC_AUTH_TOKEN="your-apivai-api-key"
export ANTHROPIC_BASE_URL="https://api.apivai.com"
Enter fullscreen mode Exit fullscreen mode

Then run:

source ~/.bashrc  # or source ~/.zshrc
claude
Enter fullscreen mode Exit fullscreen mode

Windows PowerShell

Add to your PowerShell profile ($PROFILE):

$env:ANTHROPIC_AUTH_TOKEN="your-apivai-api-key"
$env:ANTHROPIC_BASE_URL="https://api.apivai.com"
Enter fullscreen mode Exit fullscreen mode

Then just run claude.

One-liner (temporary)

Mac/Linux:

ANTHROPIC_AUTH_TOKEN="your-key" ANTHROPIC_BASE_URL="https://api.apivai.com" claude
Enter fullscreen mode Exit fullscreen mode

PowerShell:

$env:ANTHROPIC_AUTH_TOKEN="your-key"; $env:ANTHROPIC_BASE_URL="https://api.apivai.com"; claude
Enter fullscreen mode Exit fullscreen mode

Also Works With Codex CLI

Since Codex 0.121+, you need a config file:

mkdir -p ~/.codex && cat > ~/.codex/config.toml << 'EOF'
model = "gpt-5.3-codex"
model_provider = "apivai"

[model_providers.apivai]
name = "APIVAI"
base_url = "https://api.apivai.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
EOF
Enter fullscreen mode Exit fullscreen mode

Then run:

OPENAI_API_KEY="your-apivai-key" codex
Enter fullscreen mode Exit fullscreen mode

Available Models

Model Best For
Claude Opus 4.7 Most complex tasks, research
Claude Opus 4.6 Complex coding, analysis
Claude Sonnet 4.6 Best balance of speed and quality
Claude Haiku 4.5 Fast tasks, simple queries
GPT-5.4 Alternative perspective
GPT-5.3 Codex Code generation

Cost Comparison

Daily Usage Official API APIVAI Monthly Savings
Light (10 msgs/day) ~$6/mo ~$1.20/mo $4.80
Medium (30 msgs/day) ~$18/mo ~$3.60/mo $14.40
Heavy (100 msgs/day) ~$60/mo ~$12/mo $48

Troubleshooting

"Unauthorized" error: Make sure your API key starts with sk-ant- and has sufficient balance.

"Connection refused": Check that ANTHROPIC_BASE_URL is set to https://api.apivai.com (no trailing slash, no /v1).

Slow responses: First request may be slower due to prompt caching. Subsequent requests are faster.

Get Started

  1. Sign up at apivai.com
  2. Top up your balance (minimum $10)
  3. Copy your API key from the dashboard
  4. Set the environment variables and run claude

That's it. Same Claude Code, 90% cheaper.

Top comments (0)