Spaces:
Running
Running
docs: update CLAUDE.md with model list and health tracking
Browse files- Add Zen free models (big-pickle, ring-2.6-1t-free, nemotron-3-super-free)
- Add NVIDIA NIM model descriptions
- Document auto-routing with health tracking
- Simplify key modules section
- Update environment configuration
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
5 unmodified lines6789101119 unmodified lines3132333435363738394041424344454647484950515253545556575859603 unmodified lines6465666768697071727374755 unmodified linesFree Claude Code is a FastAPI proxy that routes Claude Code's Anthropic Messages API calls to backend providers (NVIDIA NIM, Zen). It translates between client-side Anthropic protocol and provider-specific transports (OpenAI chat format, native APIs), handling SSE streaming, thinking blocks, tool calls, and token usage metadata normalization.## Commands```bash19 unmodified lines```Claude Code CLI β api/routes.py (FastAPI) β api/model_router.py β providers/* β upstreamβcore/chain_engine.py (sticky sessions)```### Key Modules- **api/routes.py** β FastAPI route handlers for `/v1/messages`, `/v1/models`, `/v1/messages/counttokens`- **api/admin.py** β Admin dashboard endpoints: `GET /admin` (HTML), `GET /api/admin/sessions` (JSON)- **api/services.py** β Sticky session logic: once a model yields first event (including thinking blocks), it stays committed for that turn- **api/model_router.py** β Resolves Claude model names to provider/model pairs using MODEL_OPUS/MODEL_SONNET/MODEL_HAIKU/MODEL env vars- **api/gateway_model_ids.py** β Gateway model ID mapping for picker integration and "(no thinking)" variants- **api/detection.py** β Request type detection for optimization routing- **api/optimization_handlers.py** β Handles local optimization for trivial requests (health probes, capability checks)- **api/dependencies.py** β Dependency injection for providers, settings, and request validation- **api/web_server_tools.py** β Web fetch/search tool implementations for Claude Code server tools- **providers/registry.py** β Provider factory and caching; builds ProviderConfig from settings, creates provider instances- **providers/base.py** β Abstract `BaseProvider` interface; `stream_response()` yields Anthropic SSE- **providers/openai_compat.py** β OpenAI chat β Anthropic SSE translation for NVIDIA NIM- **providers/nvidia_nim/** β NVIDIA NIM-specific transport implementation- **providers/zen/** β Zen (opencode.ai) native transport implementation- **core/chain_engine.py** β Orchestrates multi-provider fallback chains- **core/task_detector.py** β Detects trivial requests for local optimization- **core/session_tracker.py** β Tracks active sessions and request state- **core/model_capabilities.py** β Model capability detection and feature routing- **messaging/** β Discord/Telegram bot wrappers for remote Claude Code sessions### Provider Model FormatModel values use `provider_id/model/name` format (e.g., `nvidia_nim/z-ai/glm4.7` or `zen/minimax-m2.5-free`).3 unmodified lines## Python 3.14 NotesThe `except X, Y:` syntax is valid in Python 3.14 (reintroduced). PyUpgrade is configured for py314, so don't modernize this syntax away.## Environment ConfigurationSettings are loaded via pydantic-settings from `.env`. Key variables:- `MODEL` β Comma-separated fallback model list (e.g., `zen/minimax-m2.5-free,nvidia_nim/z-ai/glm4.7`)- `MODEL_OPUS`, `MODEL_SONNET`, `MODEL_HAIKU` β Per-tier overrides- `ANTHROPIC_AUTH_TOKEN` β Must match value sent by Claude Code client- Provider API keys: `NVIDIA_NIM_API_KEY`, `ZEN_API_KEY`5 unmodified lines67891011121314151617181920212223242526272819 unmodified lines48495051525354555657585960616263646566676869707172733 unmodified lines777879808182838485868788895 unmodified linesFree Claude Code is a FastAPI proxy that routes Claude Code's Anthropic Messages API calls to backend providers (NVIDIA NIM, Zen). It translates between client-side Anthropic protocol and provider-specific transports (OpenAI chat format, native APIs), handling SSE streaming, thinking blocks, tool calls, and token usage metadata normalization.## Free Models### Zen/OpenCode (Free Tier)- `zen/minimax-m2.5-free` - Default, Claude Code capable- `zen/big-pickle` - Free tier- `zen/ring-2.6-1t-free` - Free tier- `zen/nemotron-3-super-free` - Free tier### NVIDIA NIM (7 Models)- `nvidia_nim/qwen/qwen3-coder-480b-a35b-instruct` - Code generation- `nvidia_nim/z-ai/glm4.7` - General purpose- `nvidia_nim/stepfun-ai/step-3.5-flash` - Fast responses- `nvidia_nim/mistralai/mistral-large-3-675b-instruct-2512` - Reasoning- `nvidia_nim/abacusai/dracarys-llama-3.1-70b-instruct` - Complex tasks- `nvidia_nim/bytedance/seed-oss-36b-instruct` - Balanced- `nvidia_nim/mistralai/mistral-nemotron` - Thinking tasks## Commands```bash19 unmodified lines```Claude Code CLI β api/routes.py (FastAPI) β api/model_router.py β providers/* β upstreamβcore/chain_engine.py (fallback)```### Auto-Routing with Health TrackingThe proxy includes intelligent model selection:1. Pre-flight health check (recent failures in 30s window)2. Skip unhealthy models (3+ failures = unhealthy for 30s)3. Automatic failover on timeout/rate-limit4. 40 req/min rate limit respected### Key Modules- **api/routes.py** β FastAPI routes + REQUESTED_PROVIDER_MODELS list- **api/services.py** β Request handling, fallback logic, failure recording- **api/model_router.py** β Model resolution with health-aware candidate selection- **api/optimization_handlers.py** β Fast-path for trivial requests- **providers/rate_limit.py** β GlobalRateLimiter + ModelHealthTracker- **providers/nvidia_nim/client.py** β NIM provider with fast timeouts- **providers/zen/client.py** β Zen/OpenCode provider- **providers/openai_compat.py** β OpenAI chat β Anthropic SSE translation### Provider Model FormatModel values use `provider_id/model/name` format (e.g., `nvidia_nim/z-ai/glm4.7` or `zen/minimax-m2.5-free`).3 unmodified lines## Python 3.14 NotesThe `except X, Y:` syntax is valid in Python 3.14 (reintroduced). Do not modernize this syntax away.## Environment ConfigurationKey variables in `.env`:- `MODEL` β Primary model (e.g., `zen/minimax-m2.5-free`)- `AUTO_MODEL_PRIORITY` β Comma-separated fallback order- `NVIDIA_NIM_API_KEY` β NVIDIA API key- `ANTHROPIC_AUTH_TOKEN` β Auth token (any secret)- `ENABLE_MODEL_THINKING` β Enable reasoning blocks
CLAUDE.md+40-26