# AIDevProxy **Repository Path**: jiehanlin/aidev-proxy ## Basic Information - **Project Name**: AIDevProxy - **Description**: AIProxy 是一个轻量级 ASP.NET Core LLM API 反向代理。为使用llm服务的开发提供透明的llm请求响应分析。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-24 - **Last Updated**: 2026-05-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AIProxy A lightweight ASP.NET Core reverse proxy for LLM (Large Language Model) APIs. Routes requests to multiple AI service backends, captures full request/response logs, and supports SSE (Server-Sent Events) streaming. ## Features - **Multi-Backend Routing** — Route requests to different LLM providers (OpenAI, Azure OpenAI, DeepSeek, Qwen, etc.) based on URL path prefix. - **Request/Response Logging** — Full request and response bodies are captured and saved as structured JSON files, organized by date. - **SSE Streaming Support** — Transparently proxies Server-Sent Events (e.g., `text/event-stream`) from backends while collecting stream content. - **Real-time Console Output** — Color-coded console summaries for each proxied request (`green` for success, `yellow` for 4xx, `red` for 5xx). - **Built-in Help Page** — A styled HTML page listing all configured backends when accessing the root URL. - **Zero External Dependencies** — Built on ASP.NET Core only; no third-party NuGet packages required. ## Prerequisites - [.NET SDK 10.0](https://dotnet.microsoft.com/download/dotnet/10.0) or later ## Quick Start ### 1. Clone the repository ```bash git clone cd AIProxy ``` ### 2. Configure backends Edit `src/AIProxy/appsettings.json` under the `Proxy` section: ```json { "Proxy": { "Port": 5000, "LogDirectory": "logs", "MaxBodySizeBytes": 10485760, "Backends": [ { "Name": "openai", "PathPrefix": "/openai/", "BaseUrl": "https://api.openai.com", "ApiKey": "sk-your-openai-api-key", "Headers": {}, "TimeoutSeconds": 120 }, { "Name": "deepseek", "PathPrefix": "/deepseek/", "BaseUrl": "https://api.deepseek.com", "ApiKey": "sk-your-deepseek-api-key", "Headers": {}, "TimeoutSeconds": 120 } ] } } ``` ### 3. Run the proxy ```bash cd src/AIProxy dotnet run ``` The proxy starts on `http://localhost:5000`. Access `http://localhost:5000/` in your browser to see the help page. ### 4. Use in your LLM client Point your LLM client's base URL to the proxy with the corresponding path prefix: | Backend | Client Base URL | |---------|----------------| | OpenAI | `http://localhost:5000/openai/v1` | | DeepSeek | `http://localhost:5000/deepseek/v1` | | Azure OpenAI | `http://localhost:5000/azure/` | For example, with `curl`: ```bash curl http://localhost:5000/openai/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello!"}] }' ``` ## Configuration Reference | Key | Type | Default | Description | |-----|------|---------|-------------| | `Proxy.Port` | `int` | `5000` | Port the proxy listens on | | `Proxy.LogDirectory` | `string` | `"logs"` | Directory for log files (organized by date) | | `Proxy.MaxBodySizeBytes` | `int` | `10485760` | Max bytes to capture per request/response body | | `Proxy.Backends` | `array` | — | List of backend LLM service definitions | ### Backend Definition | Key | Type | Description | |-----|------|-------------| | `Name` | `string` | Backend identifier (e.g., `"openai"`, `"deepseek"`) | | `PathPrefix` | `string` | URL path prefix for routing (e.g., `"/openai/"`) | | `BaseUrl` | `string` | Base URL of the upstream LLM API | | `ApiKey` | `string` | API key sent as `Bearer` token in `Authorization` header | | `Headers` | `dict` | Additional HTTP headers to forward to the backend | | `TimeoutSeconds` | `int` | Request timeout in seconds (default: `120`) | ## Logs Requests and responses are logged as JSON files under the configured `LogDirectory`: ``` logs/ └── 2026-05-24/ ├── 143025123_POST_v1_chat_completions.json └── 143530456_POST_v1_completions.json ``` Each log file contains: ```json { "SessionId": "a1b2c3d4e5f6", "Timestamp": "2026-05-24T14:30:25Z", "BackendName": "openai", "BackendUrl": "https://api.openai.com/v1/chat/completions", "Request": { "Method": "POST", "Path": "/v1/chat/completions", "Headers": { "Content-Type": "application/json" }, "Body": "{ \"model\": \"gpt-4o-mini\", ... }", "BodyTruncated": false }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": "application/json" }, "Body": "{ \"choices\": [...] }", "BodyTruncated": false, "IsStreaming": false, "StreamChunkCount": 0 }, "DurationMs": 1234, "Error": null } ``` ## Project Structure ``` src/AIProxy/ ├── Models/ │ ├── ProxyConfig.cs # Global proxy configuration model │ ├── BackendDefinition.cs # Backend LLM service definition │ └── LogEntry.cs # Request-response log entry models ├── Middleware/ │ └── ProxyRouterMiddleware.cs # Core: path matching, forwarding, error handling ├── Handlers/ │ ├── CaptureDelegatingHandler.cs # HttpClient handler for capturing bodies │ └── SseStreamCopier.cs # SSE stream forwarding + collection ├── Services/ │ ├── SessionLogger.cs # JSON log file writer │ └── ConsoleReporter.cs # Color-coded console output ├── Extensions/ │ └── ServiceCollectionExtensions.cs # DI registration ├── Program.cs # Application entry point └── appsettings.json # Configuration ``` ## License This project is open source. See the license file for details.