CoolFace
Apppublic

Yash030/claude-code-proxy

sourceHugging Faceupdated 4mo agoView on Hugging Face
2likes
App README

<div align="center">

๐Ÿค– Free Claude Code

Use Claude Code with free NVIDIA NIM models through a lightweight proxy.

![License: MIT](https://opensource.org/licenses/MIT) ![Python 3.14](https://www.python.org/downloads/) ![uv](https://github.com/astral-sh/uv) ![Code style: Ruff](https://github.com/astral-sh/ruff)

</div>

The Problem

Claude Code costs $100+/month for API access. This project lets you run it using free NVIDIA NIM models instead.

The Solution

A FastAPI proxy that translates Claude Code's Anthropic API calls to NVIDIA NIM's OpenAI-compatible endpoint. Zero code changes needed in Claude Code.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      Anthropic API       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Claude Code   โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ  โ”‚  Free Claude    โ”‚
โ”‚   (Official)    โ”‚                          โ”‚     Code        โ”‚
โ”‚                 โ”‚ โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚    Proxy        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    SSE Streaming         โ”‚   (:8082)       โ”‚
                                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                   โ”‚
                                          OpenAI Chat API
                                                   โ”‚
                                                   โ–ผ
                                          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                          โ”‚   NVIDIA NIM     โ”‚
                                          โ”‚  (Free Models)   โ”‚
                                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Features

  • โ€”Drop-in replacement for Claude Code's Anthropic API
  • โ€”7 free NVIDIA NIM models available via auto-routing
  • โ€”Automatic failover - switches to next model if one hits rate limit
  • โ€”Multi-model support - use different models for different tasks
  • โ€”Local optimizations - fast-path for common probes (saves API calls)
  • โ€”Streaming - real-time response with SSE
  • โ€”Tool support - Claude Code tools work with NIM models
  • โ€”Thinking blocks - reasoning support where models support it
  • โ€”Discord/Telegram bots - remote Claude Code sessions
  • โ€”Voice notes - transcribe voice messages with Whisper

Quick Start (Cloud - No Setup)

The easiest way to use this project is on HuggingFace Spaces (free tier available).

1. Deploy to HuggingFace Spaces

<a target="_blank" href="https://huggingface.co/new-space?template=Yash030/claude-code-proxy"> <img src="https://huggingface.co/datasets/huggingface/badges/raw/main/deploy-to-spaces-lg.svg" alt="Deploy to HuggingFace Spaces"/> </a>

Or manually:

  1. 1.Go to huggingface.co/spaces/Yash030/claude-code-proxy
  2. 2.Duplicate the space
  3. 3.Set your secrets in the Space settings:
  4. 4.NVIDIA_NIM_API_KEY - Your NVIDIA API key
  5. 5.ANTHROPIC_AUTH_TOKEN - Your auth token (any secret)

2. Get NVIDIA API Key

Get a free key at build.nvidia.com/settings/api-keys.

3. Connect Claude Code

bash
# Use your HuggingFace Space URL (ends with .hf.space)
export ANTHROPIC_AUTH_TOKEN="your-secret-token"
export ANTHROPIC_BASE_URL="https://your-space-name.hf.space"
claude

That's it! Claude Code will use free NVIDIA NIM models.

Quick Start (Local)

1. Install Requirements

bash
# Install Claude Code
curl -LsSf https://download.anthropic.com/install.sh | sh

# Install uv (fast Python package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.14

2. Clone and Configure

bash
git clone https://github.com/Yashwant00CR7/claude-code-nvidia.git
cd claude-code-nvidia
cp .env.example .env

Edit .env:

dotenv
NVIDIA_NIM_API_KEY="nvapi-your-key"
ANTHROPIC_AUTH_TOKEN="freecc"
MODEL="nvidia_nim/z-ai/glm4.7"

3. Start Proxy

bash
uv sync
uv run uvicorn server:app --host 0.0.0.0 --port 8082

4. Run Claude Code

bash
export ANTHROPIC_AUTH_TOKEN="freecc"
export ANTHROPIC_BASE_URL="http://localhost:8082"
claude

Available Models

The proxy automatically routes to these models in order:

ModelBest ForSpeed
qwen3-coder-480bCode generationFast
glm4.7General purposeFast
step-3.5-flashFast responsesVery Fast
mistral-large-3ReasoningMedium
dracarys-llama-3.1-70bComplex tasksMedium
seed-oss-36bBalancedFast
mistral-nemotronThinking tasksMedium

How Auto-Routing Works

When you use auto model, the proxy:

  1. 1.Tries models in order of speed/reliability
  2. 2.Skips rate-limited models - pre-flight check before each request
  3. 3.Fast failover - if one model times out, immediately tries next
  4. 4.No API waste - common probes handled locally
Request: "Write a function"
    โ†“
Check if model 1 is rate-limited? โ†’ Yes โ†’ Skip
Check if model 2 is rate-limited? โ†’ No โ†’ Try
    โ†“
Model 2 responds? โ†’ Yes โ†’ Stream response
Model 2 timeout? โ†’ Try model 3 โ†’ Success!

Environment Variables

Required

dotenv
NVIDIA_NIM_API_KEY="nvapi-your-key"     # From build.nvidia.com
ANTHROPIC_AUTH_TOKEN="your-secret"     # Any secret you choose

Optional

dotenv
MODEL="nvidia_nim/z-ai/glm4.7"          # Default model
MODEL_OPUS="nvidia_nim/qwen/qwen3-..."  # Model for Opus requests
MODEL_SONNET="nvidia_nim/z-ai/glm4.7"    # Model for Sonnet requests
MODEL_HAIKU="nvidia_nim/z-ai/glm4.7"    # Model for Haiku requests

# Auto-routing order (comma-separated)
AUTO_MODEL_PRIORITY="nvidia_nim/qwen/...,nvidia_nim/z-ai/..."

# Thinking support
ENABLE_MODEL_THINKING=true              # Enable reasoning blocks

IDE Integration

VS Code Extension

Add to .vscode/settings.json:

json
{
  "claudeCode.environmentVariables": [
    { "name": "ANTHROPIC_BASE_URL", "value": "http://localhost:8082" },
    { "name": "ANTHROPIC_AUTH_TOKEN", "value": "freecc" }
  ]
}

JetBrains ACP

Edit ~/.jetbrains/acp.json:

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:8082",
    "ANTHROPIC_AUTH_TOKEN": "freecc"
  }
}

Remote/Ssh

For remote development, deploy to HuggingFace Spaces and use:

bash
export ANTHROPIC_BASE_URL="https://your-space.hf.space"

Deployment Options

HuggingFace Spaces (Recommended for Cloud)

Free tier includes:

  • โ€”2 vCPU
  • โ€”Community support
  • โ€”Automatic HTTPS
  • โ€”Git-based deployment

Setup:

  1. 1.Fork the space
  2. 2.Add NVIDIA_NIM_API_KEY to Space secrets
  3. 3.Access at https://your-space.hf.space

Railway (Easy Deploy)

  1. 1.Connect GitHub repo
  2. 2.Set environment variables
  3. 3.Deploy with auto-scaling

Render (Free Tier)

  1. 1.Create Web Service
  2. 2.Connect GitHub
  3. 3.Set build command: uv sync
  4. 4.Set start command: uv run uvicorn server:app --host 0.0.0.0 --port $PORT

Fly.io (Global Edge)

bash
fly launch
fly secrets set NVIDIA_NIM_API_KEY="nvapi-..."
fly deploy

Local/Docker

bash
docker build -t free-claude-code .
docker run -p 8082:8082 \
  -e NVIDIA_NIM_API_KEY="nvapi-..." \
  -e ANTHROPIC_AUTH_TOKEN="freecc" \
  free-claude-code

Architecture

api/
โ”œโ”€โ”€ routes.py          # FastAPI endpoints
โ”œโ”€โ”€ services.py       # Request handling & failover
โ”œโ”€โ”€ model_router.py   # Model resolution
โ”œโ”€โ”€ detection.py      # Request type detection
โ””โ”€โ”€ optimization_handlers.py  # Fast-path responses

core/
โ”œโ”€โ”€ anthropic/        # SSE, token counting, tool parsing
โ””โ”€โ”€ task_detector.py # Task capability detection

providers/
โ”œโ”€โ”€ openai_compat.py  # Base OpenAI transport
โ”œโ”€โ”€ nvidia_nim/       # NVIDIA NIM provider
โ””โ”€โ”€ rate_limit.py     # Rate limiting

messaging/
โ”œโ”€โ”€ discord.py        # Discord bot wrapper
โ””โ”€โ”€ telegram.py       # Telegram bot wrapper

Troubleshooting

"undefined ... input_tokens" error

  • โ€”Update to latest version: git pull
  • โ€”Check ANTHROPIC_BASE_URL doesn't end with /v1

Provider disconnects during streaming

  • โ€”Reduce PROVIDER_MAX_CONCURRENCY
  • โ€”Increase HTTP_READ_TIMEOUT
  • โ€”Check NVIDIA NIM status at status.nvidia.com

Model not responding

  • โ€”Check your NVIDIA API key is valid
  • โ€”Verify rate limits haven't been hit
  • โ€”Try a different model

VS Code extension shows login

  • โ€”Reload the extension after setting env vars
  • โ€”Confirm environment variables are set correctly

Contributing

  1. 1.Fork the repo
  2. 2.Create a feature branch
  3. 3.Run checks: uv run ruff format && uv run ruff check && uv run ty check
  4. 4.Submit PR

License

MIT License - See LICENSE

Links