# Chat Relay: OpenAI-Compatible Relay for AI Chat Interfaces Chat Relay is a system that allows Cline/RooCode to communicate with web-based AI chat interfaces (like Gemini, AI Studio, ChatGPT, and Claude) through an OpenAI-compatible API. This enables using models that may not have public APIs through their web interfaces. It also alows you to use models that are fast or good at tools (Claude) in combination with slower smarter models (Google Pro 2.5). --- ## Architecture Overview The system consists of three main components: 1. **OpenAI-Compatible API Server**: Implements an OpenAI-compatible API endpoint that Cline/RooCode can connect to. 2. **Browser Extension**: Connects to the API server via WebSocket and interacts with the chat interface. 3. **MCP Server**: Provides additional tools and resources for the system. ### ASCII Diagram ``` ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌──────────────┐ │ │ │ │ │ │ │ │ │ Cline/ │◄── http ──►│ OpenAI- │◄─ websocket -►│ Browser │◄───────►│ Chat │ │ RooCode │ │ Compatible │ │ Extension │ │ Interface │ │ (App) │ │ Relay │ │ │ │ (Gemini, │ └─────────────┘ └─────────────┘ └─────────────┘ │ AI Studio, │ │ ChatGPT, │ │ Claude) │ └──────────────┘ ``` ### Mermaid Diagram ```mermaid graph TD A["Client / RooCode"] -->|HTTP POST /chat/completions| B["API Relay Server"] B -->|WebSocket| C["Browser Extension"] C -->|User Input| D["Chat Interface (Gemini / AI Studio / ChatGPT / Claude)"] D -->|AI Response| C C -->|Captured Response| B B -->|OpenAI-format JSON| A ``` --- ## Data Flow 1. **Cline/RooCode to API Server**: - Sends HTTP POST to `/v1/chat/completions` 2. **API Server to Browser Extension**: - Sends message + `requestId` via WebSocket 3. **Extension to Chat Interface**: - Inserts text, clicks send 4. **Chat Interface to Extension**: - Captures response from UI 5. **Extension to API Server**: - Returns response tied to `requestId` 6. **API Server to Cline/RooCode**: - Formats response in OpenAI structure --- ## Components ### 1. OpenAI-Compatible API Server The API server implements an OpenAI-compatible endpoint and manages browser extension connectivity. **Key Features:** - OpenAI-style `/v1/chat/completions` endpoint - WebSocket server for real-time relay - Comprehensive admin interface with real-time monitoring - Live server logs and message history tracking - Configurable settings with persistent storage - Ping/pong health checks - Request timeouts, retry handling - Tracks connection state ### 2. Browser Extension Interacts with Gemini, AI Studio, ChatGPT, and Claude UIs. Injects chat, captures responses. **Key Features:** - Auto-send with retry/backoff - DOM/debugger-based response capture - Modular provider architecture: - [`AIStudioProvider`](extension/providers/aistudio.js) - [`ChatGptProvider`](extension/providers/chatgpt.js) - [`ClaudeProvider`](extension/providers/claude.js) - [`KimiK2Provider`](extension/providers/kimi_k2.js) **Supported Chat Interfaces:** - Gemini (`gemini.google.com`) - AI Studio (`aistudio.google.com`) - ChatGPT (`chatgpt.com`) - Claude (`claude.ai`) - Kimi K2 (`k2.kimi.ai`) ChatGPT is a trademark of OpenAI. Gemini and AI Studio are trademarks of Google. Claude is a trademark of Anthropic. This project is not affiliated with, endorsed by, or sponsored by OpenAI, Google, or Anthropic. ### 3. MCP Server An optional developer utility server for simulating messages, testing extensions, or viewing traffic. --- ## Important Considerations & Responsible Use **Compliance with Provider Terms:** Users of Chat Relay are solely responsible for ensuring that their use of this tool complies with the terms of service, usage policies, and any other relevant agreements of the AI service providers they access through Chat Relay (e.g., OpenAI, Google, Anthropic). **Respect Provider Limits:** It is crucial to be mindful of and respect any rate limits, usage quotas, or other restrictions imposed by the AI service providers. Automating interactions can potentially exceed these limits if not managed carefully. **Avoid System Disruption:** Do not use Chat Relay in any manner that could disrupt, overburden, or impair the services of the AI providers. Responsible use includes avoiding excessive requests or any activity that could negatively impact the stability or performance of their systems. **User Responsibility:** By using Chat Relay, you acknowledge that you understand these considerations and agree to use the tool responsibly and at your own risk concerning compliance with third-party provider terms. The developers of Chat Relay assume no liability for misuse or violations of third-party terms of service. --- ## Installation & Setup ### Prerequisites - Node.js (v14+) - npm (v6+) - Chrome browser ### API Server Setup ```bash cd api-relay-server npm install nodemon start ``` ### Browser Extension Setup 1. Open Chrome → `chrome://extensions/` 2. Enable Developer Mode 3. Click "Load unpacked" 4. Select `extension/` directory ### MCP Server (Optional) ```bash cd mcp-server npm run build npm install -g . ``` or package installation and install ```bash cd mcp-server npm run build npm pack npm install -g C:/Users/user/Projects/chat-relay/mcp-server/chat-relay-mcp-0.0.1.tgz ```