$ show CJackHwang/ds2api
DS2API is a production-grade API proxy/gateway that translates DeepSeek's web chat API into OpenAI, Claude, Gemini, and Ollama-compatible endpoints. It provides a full-featured web UI for administration, account management, proxy configuration, and API testing. The system handles authentication (JWT, API keys, managed accounts), streaming responses with tool call detection, and multi-protocol request normalization. Architecturally, it is a Go backend with a React frontend (Vite + Tailwind). The backend is modular: protocol-specific handlers (OpenAI chat/responses, Claude messages, Gemini generate, Ollama chat) share a common prompt compatibility layer that normalizes requests to DeepSeek's internal format. A custom DeepSeek client manages authentication, PoW challenges, session lifecycle, and streaming. The SSE parsing infrastructure, tool call sieve, account pool, and config store are reusable components with extensive test coverage. Key data flows: incoming API requests are parsed and normalized to a unified prompt representation (role-tagged messages, tool descriptions, file references). The prompt is sent to DeepSeek's web chat API via a streaming or non-streaming completion runtime. Responses are parsed from SSE chunks, transformed (thinking extraction, tool call normalization, citation handling), and streamed back in the original protocol format. The system supports retry logic, account switching, and current input file injection for large contexts. External dependencies include DeepSeek's web chat API (reverse-engineered), Go standard library, chi router, utls for TLS fingerprinting, Node.js for Vercel streaming and WebUI build, and React/Vite for the frontend. The project is actively maintained with CI/CD pipelines, Docker images, and Vercel deployment support.
The LLM identified 6 files worth highlighting for reuse:
Generic line-by-line SSE parser that handles content type detection, deduplication, citation extraction, and content filter handling. Can be extracted for any SSE-based API integration. Demonstrates robust parsing of streaming events with state management.
State machine for streaming extraction of XML/DSML tool calls from model output. Handles code fences, backtick spans, and multiple markup variants (fullwidth, confusable Unicode, CJK-angle). Reusable for any streaming tool call detection system requiring robust parsing of model-generated markup.
Concurrency-limited resource pool with acquire/release, waiting queue, and dynamic limit adjustment. Implements round-robin distribution and runtime limit changes. Reusable pattern for rate limiting and resource management in any multi-account or multi-endpoint system.
Thread-safe configuration store with file and environment variable backends, atomic updates, validation, and hot-reload support. Includes indexing and writeback. Reusable for any application needing robust config management with multiple sources and runtime updates.
Accumulates streaming SSE events, deduplicates thinking and text content, strips citation markers, and detects tool call boundaries. Reusable for processing any streaming response with thinking/reasoning content, especially when the upstream sends overlapping or fragmented deltas.
Implements DeepSeekHashV1, a modified SHA3-256 variant that skips round 0, for solving PoW challenges during authentication. Demonstrates non-obvious skill in implementing a non-standard cryptographic hash and is critical for accessing DeepSeek's API.