www222fff/muse2api
Learn how a driver‑based design lets you replace the transport layer without touching your prompt logic.
The core of muse2api is an asyncio‑driven server that mirrors the OpenAI chat/completion endpoints. Incoming JSON payloads are parsed into Pydantic request objects, then forwarded to a driver that knows how to talk to muse.ai. Responses, including streaming token chunks, are streamed back using the same async iterator pattern that the official OpenAI client expects, so existing code can switch backends with a single import change.
Drivers are the only moving part. The repository ships three implementations: a lightweight mock that returns canned responses for unit tests, a browser‑CDP driver that launches Chrome, navigates the muse.ai UI, and extracts generated text via the DevTools Protocol, and a plain HTTP driver that issues POST requests to muse.ai’s public endpoints. Each driver conforms to a tiny abstract base class exposing async send_prompt and async close methods, keeping the gateway agnostic to transport details.
Because everything runs on asyncio, the gateway can handle dozens of concurrent chats with minimal overhead. Token counting is delegated to the driver when possible, and the server enforces a configurable per‑minute request quota to avoid rate‑limit surprises. Error handling bubbles up as OpenAI‑style error objects, preserving the familiar error codes and messages that downstream clients already parse.
The repo targets Python developers building LLM‑powered products who want to experiment with muse.ai without rewriting prompt code. The mock driver accelerates CI pipelines, the CDP driver enables end‑to‑end UI testing, and the HTTP driver offers a drop‑in production path. Star growth reflects the community’s appetite for a plug‑and‑play bridge that abstracts away muse.ai’s quirks while preserving the OpenAI developer experience.
TakeawayMuse2api delivers an async OpenAI‑compatible wrapper around muse.ai with interchangeable mock, CDP, and HTTP drivers, letting you swap the transport layer without changing application code.