ProxyPilot

repository·main·Indexed 42 days ago

https://github.com/finesssee/proxypilot

A proxy server providing OpenAI, Gemini, Claude, and Grok compatible API interfaces optimized for CLI tools and developers. It features multi-account load balancing, OAuth-based access, and a CLI for toggling AI agents between proxy and native modes. Includes a plugin system for request normalization, custom authentication, and specialized routing, such as the Claude Code Web Search Router.

Tokens
60.5K
Snippets
176
Records
282
Agent score
53%

What's inside ProxyPilot

  1. Overview of CLI Proxy API

    main

    CLI Proxy API is a proxy server that provides OpenAI, Gemini, Claude, Codex, and Grok compatible API interfaces specifically designed for CLI tools.

    Key capabilities include:

    • Compatibility: Provides endpoints compatible with OpenAI, Gemini, Claude, and Grok, allowing you to use local or multi-account CLI access with standard OpenAI/Gemini/Claude compatible clients and SDKs.
    • OAuth Support: Supports OpenAI Codex (GPT models), Claude Code, and Grok Build via OAuth login.
    • Advanced Features: Supports streaming, non-streaming, and WebSocket responses (where supported), function calling/tools, and multimodal inputs (text and images).
    • Load Balancing: Implements round-robin load balancing for multiple accounts across Gemini, OpenAI, Claude, and Grok.
    • Extensibility: Supports Generative Language API keys, AI Studio build multi-account load balancing, and allows configuring OpenAI-compatible upstream providers (e.g., OpenRouter).
    • SDK: Provides a reusable Go SDK for embedding the proxy.
  2. Overview of CLI Proxy API capabilities

    main

    CLI Proxy API is a proxy server designed to provide OpenAI, Gemini, Claude, Grok, and Codex compatible API interfaces for CLI tools. It allows developers to use local or multi-account access with standard OpenAI/Gemini/Claude-compatible clients and SDKs.

    Key Features:

    • Compatibility: Supports OpenAI/Gemini/Claude/Grok compatible endpoints.
    • OAuth Support: Enables OpenAI Codex (GPT models), Claude Code, and Grok Build via OAuth login.
    • Response Types: Supports streaming, non-streaming, and WebSocket responses.
    • Advanced AI Features: Supports function calling/tools and multimodal input (text and images).
    • Load Balancing: Provides round-robin load balancing across multiple accounts for Gemini, OpenAI, Claude, and Grok.
    • Upstream Providers: Supports OpenAI-compatible upstream providers (e.g., OpenRouter) via configuration.
    • Extensibility: Includes a reusable Go SDK for embedding the proxy.
  3. Explore projects built on CLIProxyAPI

    main

    CLIProxyAPI serves as a foundation for a wide ecosystem of tools designed to manage AI subscriptions (Claude, Gemini, ChatGPT, Codex, etc.) without requiring API keys. These projects range from desktop GUIs and menu bar apps to management dashboards and VSCode extensions.

    Key categories of projects include:

    • Desktop & Menu Bar Apps: Tools like vibeproxy (macOS), ZeroLimit (Windows), Quotio (macOS), and ProxyPal (Cross-platform) provide native interfaces for monitoring quotas and managing multiple AI accounts.
    • Management Dashboards: CPA-XXX Panel and CLIProxyAPI Dashboard offer web-based interfaces for real-time logs, resource monitoring, and configuration management.
    • Developer Tools & Extensions: Claude Proxy VSCode integrates with VSCode, while CCS (Claude Code Switch) provides a CLI wrapper for switching accounts.
    • Routing & Orchestration: OmniRoute and 9Router act as AI gateways providing smart routing, load balancing, and automatic fallback between providers.
    • Specialized Utilities: Subtitle Translator for SRT files, All API Hub for browser-based account management, and Panopticon for multi-agent orchestration.
  4. Explore CLIProxyAPI C ABI Plugin Examples

    main

    The examples/plugin directory contains standard dynamic library plugin examples for the CLIProxyAPI C ABI. Most standard capability examples include implementations in go/, c/, and rust/ subdirectories.

    Key example categories include:

    • Core Capabilities: model/ (model capability), auth/ (authentication providers), executor/ (executor capability), request-translator/ (request transformation), response-translator/ (response transformation), thinking/ (thinking processing), and usage/ (usage observation).
    • Request/Response Normalization: request-normalizer/ and response-normalizer/.
    • Specialized Logic: scheduler/ (scheduling logic), codex-service-tier/ (request normalization for Codex), and cli/ (CLI extensions).
    • Host Callbacks: host-callback/ (general host callbacks), host-callback-auth-files/ (host credential file callbacks), and host-model-callback/ (host model execution callbacks).
    • Management & API: management-api/ (resource extensions) and protocol-format/ (input/output format declarations).
  5. What is Hindsight and how should it be architected?

    main

    Hindsight is an optional agent memory system designed to handle long-term memory (retain, recall, and reflect) for AI agents. It acts as a sidecar to prevent "context rot" and "prompt too long" errors by moving long-term information out of the immediate chat history and into a queryable store.

    Recommended Architecture:

    • CLIProxyAPI: Use this strictly for auth, routing, translation, compatibility fixes, and request trimming.
    • Hindsight: Run this as a separate service (via Docker or Python) and connect it to your agentic client (e.g., Droid/Factory CLI, Claude Code) using the Model Context Protocol (MCP).
    • Agent Instructions: Use your system prompt to teach the agent to use Hindsight tools to:
      • retain: Store stable preferences and project facts.
      • recall: Retrieve information before performing large context dumps.
      • reflect: Analyze successes or failures to improve future consistency.
  6. How the Watcher handles high-frequency changes

    main

    The watcher is designed to handle rapid configuration or file changes without blocking the main event threads or causing excessive overhead. It uses a two-tier buffering and merging strategy:

    1. Event Merging: The watcher maintains a currentAuths snapshot. When changes occur, it compares the new snapshot against the old one to generate a minimal list of AuthUpdate objects. Multiple changes to the same credential ID within a short window are merged (e.g., a write followed by a delete results in only a single delete update).
    2. Two-Level Backpressure:
      • Distribution Buffer: Uses a map and an ordered slice to merge duplicate events for the same credential until the consumer is ready.
      • Service Channel: A 256-capacity buffered channel combined with a "drain" logic on the consumer side allows the system to absorb sudden bursts of updates.

    This architecture ensures that even if the channel is under high pressure, the system continues to merge events so that once the consumer recovers, it applies only the latest state, avoiding redundant processing of intermediate states.

  7. Understand the ProxyPilot CLI + Tray Architecture

    main

    ProxyPilot operates using a dual-executable architecture to separate core proxy logic from the user interface management:

    • proxypilot.exe (CLI/Engine): The core engine. It handles the proxy engine (running on port 8317), the routing engine, provider authentication, and serves the web dashboard at /proxypilot.html. It can be run standalone via the command line.
    • ProxyPilot.exe (System Tray): A lightweight Windows wrapper. It manages the lifecycle (start/stop/restart) of the proxypilot.exe subprocess, provides a quick-access system tray menu, and opens the dashboard in the default web browser.
    • Web Dashboard: Accessed via a browser at http://127.0.0.1:<port>/proxypilot.html. Because the dashboard is served by the CLI, it avoids WebView2 dependencies and allows for easier debugging via browser DevTools.
  8. How the Agentic Harness middleware rewrites requests

    main

    ProxyPilot uses a middleware layer to intercept and rewrite LLM requests based on the current state of the project environment. This allows the system to switch between different agent personas (like INITIALIZER or CODING) automatically.

    When a request is intercepted, the middleware injects specific instructions into the instructions field (for Responses API) or the system message (for Chat Completions) using a <harness_mode> tag. This transformation is driven by the presence of specific files in the harness-root-dir.

  9. How CLIProxyAPI handles Claude model aliasing

    main

    CLIProxyAPI automatically rewrites common Claude Code model aliases to specific locally-available models before routing the request. This allows you to use standard model names while targeting specific backend providers.

    Mapping Logic:

    • opus or claude-opus-* $\rightarrow$ antigravity-claude-opus-4-5-thinking
    • sonnet or claude-sonnet-* $\rightarrow$ antigravity-claude-sonnet-4-5-thinking
    • haiku or claude-haiku-* $\rightarrow$ gemini-3-pro-preview
  10. Embeddings support in Cursor IDE

    main
    When using CLIProxyAPI with Cursor, the POST /v1/embeddings endpoint is fully implemented. Even if you have not configured a specific embeddings backend, CLIProxyAPI returns deterministic synthetic embeddings. This ensures that Cursor's IDE features (like codebase indexing and semantic search) continue to function correctly.
  11. Trigger CODING mode via file detection

    main

    The middleware automatically switches from INITIALIZER mode to CODING mode when it detects that the project scaffolding has been completed.

    Trigger Condition: If feature_list.json or claude-progress.txt exists under the harness-root-dir, the middleware injects the CODING prompt instead of the INITIALIZER prompt.

    Verification: You can verify the current mode by checking the response header: X-ProxyPilot-Harness-Mode: CODING

  12. How the Provider Registry and Manager work together

    main

    The @sdk/access package uses a global registry for access providers. Providers are registered globally and then attached to a Manager as a snapshot.

    Provider Registry

    • RegisterProvider(type, provider): Registers an initialized provider instance. The order of registration is preserved.
    • RegisteredProviders(): Returns the list of providers in the order they were registered.

    Manager Lifecycle

    A Manager is used to execute the authentication chain. You can create a new manager and populate it with the currently registered providers.

    If the manager is nil or has no providers configured, authentication calls will return nil, nil, which effectively disables access control.

    import (
        sdkaccess "github.com/router-for-me/CLIProxyAPI/v6/sdk/access"
    )
    
    // Create a manager and populate it with registered providers
    manager := sdkaccess.NewManager()
    manager.SetProviders(sdkaccess.RegisteredProviders())