Add OpenAI-compatible API server for AI agent integration#2
Open
falcga wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add full OpenAI API v1 compatibility to dskpp, enabling the service to be used as a drop-in replacement for OpenAI's API in AI agents and tools like Cline, LangChain, OpenAI Python SDK, and more.
Motivation
dskpp currently provides an async Python client for DeepSeek chat, but there was no way to use it as an API server that AI agents could connect to. By implementing the OpenAI API format, dskpp can now serve as a local proxy that translates standard OpenAI requests into DeepSeek's internal WebSocket protocol.
Changes
New Files
openai_compat.py— OpenAI API compatibility layerChatCompletionRequest,ChatMessage,ModelList,ModelObjectdeepseek-chat(standard),deepseek-reasoner(thinking enabled)generate_id(),estimate_tokens(),make_error_response()Modified Files
server.py— Major expansion from bypass server to full API serverGET /v1/models,POST /v1/chat/completions,GET /healthAuthorization: Bearer <key>header +?key=query param)data:prefix,chat.completion.chunkobjects,[DONE]terminator)error.message,error.type,error.code)except→ specific exceptions, unused imports removed, f-string fixesREADME.md— Complete rewriterequirements.txt— Addedwebsockets>=12.0dependency.gitignore— Addedgoal.md/GOAL.mdNew API Endpoints
GET/v1/modelsPOST/v1/chat/completionsGET/healthAll existing endpoints (
/cookies,/html) remain unchanged and functional.Environment Variables
AUTH_KEYMODEL_NAMEdeepseek-chatSERVER_PORT8021Usage Example
Start server with auth
export AUTH_KEY=your-secret-key python server.pyUse with OpenAI SDK
Testing
Verified all endpoints:
GET /v1/models— Returns correct OpenAI format model listPOST /v1/chat/completions(non-streaming) — Returns proper response with usagePOST /v1/chat/completions(streaming) — SSE chunks with correct format +[DONE]GET /health— Returns{"status": "ok"}Breaking Changes
None. All existing endpoints remain unchanged.