Claude CodeTutorialSetup Guide

How to Set Up Claude Code with an Affordable API Provider(em inglês)

2026-04-20

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 over 50% 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"

Then run:

source ~/.bashrc  # or source ~/.zshrc
claude

Windows PowerShell

Add to your PowerShell profile ($PROFILE):

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

Then just run claude.

One-liner (temporary)

Mac/Linux:

ANTHROPIC_AUTH_TOKEN="your-key" ANTHROPIC_BASE_URL="https://api.apivai.com" claude

PowerShell:

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

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.5"
model_provider = "apivai"

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

Then run:

OPENAI_API_KEY="your-apivai-key" codex

Available Models

ModelBest For
Claude Opus 4.7Most complex tasks, research
Claude Opus 4.6Complex coding, analysis
Claude Sonnet 5Latest Sonnet, advanced reasoning
Claude Sonnet 4.6Best balance of speed and quality
Claude Haiku 4.5Fast tasks, simple queries
GPT-5.5Alternative perspective and code generation

Cost Comparison

Daily UsageOfficial APIAPIVAI
Light (10 msgs/day)~$6/moLess than half
Medium (30 msgs/day)~$18/moLess than half
Heavy (100 msgs/day)~$60/moLess than half

Exact per-model rates are on the live pricing page.

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, over 50% cheaper.

Pronto para começar?

Obtenha sua chave de API em 30 segundos. Pague pelo uso do Claude e do GPT.