$ show justlovemaki/AIClient2API
AIClient2API (A2) is a production-grade API proxy/gateway that converts proprietary AI provider APIs (Gemini, Claude/Kiro, Qwen, Codex, Grok, OpenAI, and more) into standard OpenAI-compatible endpoints (`/v1/chat/completions`, `/v1/messages`, `/v1beta/models`). It supports multi-account OAuth credential pools with automatic token refresh, health checks, and fallback routing, enabling clients to break free-tier restrictions. The server is built on Node.js with a master-worker architecture for process management, a plugin system for extensibility (authentication, monitoring, usage statistics, API key sharing), and a Go-based TLS sidecar for JA3/JA4 bypass. A full web management console (static HTML/CSS/JS) provides configuration, provider management, credential file upload, interactive playground, and usage monitoring. The codebase demonstrates strong patterns (strategy, factory, adapter, converter) but suffers from some monolithic utility files, hardcoded provider mappings, and high maintenance overhead from multiple OAuth implementations.
The LLM identified 5 files worth highlighting for reuse:
Provides `withFileLock` and `atomicWriteFile` functions for safe concurrent file access using file system locking. Idempotent, handles race conditions, and can be extracted as a standalone utility for any Node.js project requiring coordinated writes to shared config files.
Implements a sliding window bucket algorithm for rate tracking (QPS, TPS, RPM). Supports variable window sizes and resolution, increment operations, and peak calculation. Self-contained and reusable for any application needing lightweight rate monitoring without external dependencies.
Abstract base class for protocol converters defining a consistent interface (`convertRequest`, `convertResponse`, `convertStreamChunk`, `convertModelList`). New providers can be added by subclassing and registering with ConverterFactory. Demonstrates clean separation of concerns and is reusable as a template for any API transformation layer.
Manages multiple credentials/accounts per provider type with support for health monitoring, LRU-based selection, concurrency limits (slot queue), automatic token refresh, and accelerated recovery for unhealthy nodes. Persists state with debounced writes to a JSON file. Could be extracted to manage any set of authenticated API credentials with rotation and failover.
Structured logger with support for _AsyncLocalStorage_ request context, multiple log levels, console and file output, log rotation, and configuration from environment variables. Self-contained and easily adaptable to other Node.js services requiring correlation IDs and centralized logging.