$ show sums001/Windows-Copilot-API
Windows Copilot API is an unofficial Python library and OpenAI-compatible HTTP server that bridges the consumer Microsoft Copilot chat service. It uses a pure-HTTP driver with curl_cffi to impersonate Chrome and speak Copilot's WebSocket protocol, handling authentication, proof-of-work challenges, and Cloudflare Turnstile clearance in-process. A Playwright-based browser module enables interactive sign-in and scheduled clearance refresh. The server wraps the library behind FastAPI endpoints exposing /v1/chat/completions and /v1/models with full streaming support, rate limiting, and concurrency serialization to cope with Copilot's single-account constraints. Notable features include transparent token refresh, conversation persistence, and a diagnostic tool for session debugging. The codebase is well-structured, with clear separation of concerns across protocol constants, challenge solvers, models, and drivers. It demonstrates advanced reverse-engineering and browser-emulation skills.
The LLM identified 3 files worth highlighting for reuse:
Implements hashcash and a custom Copilot arithmetic proof-of-work challenge solver. Computes nonce values for leading-zero-bit SHA-256 hashes and rounds arithmetic expressions, all in pure Python with no external dependencies. The module is fully self-contained, well-documented, and can be extracted for any service requiring similar challenge responses.
A thread-safe token bucket rate limiter with configurable refill rate (RPM) and burst capacity. Supports injectable monotonic clock for deterministic testing, non-blocking try_acquire with retry-after calculation, and a disable-by-zero mode. Cleanly isolated from the rest of the project and easily reusable in any Python application needing a simple rate throttle.
Centralized definition of the User-Agent string, client hints, and TLS impersonation profile used by both the HTTP driver and Playwright browser. Ensures cf_clearance cookies earned in one component are valid in the other by presenting identical browser fingerprints. Demonstrates deep understanding of Cloudflare's clearance-binding mechanism and best practice for maintaining coherence across multiple execution contexts.