A Go implementation that provides an OpenAI-compatible API interface for DuckDuckGo's chat service.
- OpenAI-compatible API endpoints
- Support for streaming responses
- Multiple model mappings
- Token-based authentication
- Proxy support
- Health check endpoints
- CORS enabled
"ddg/gpt-4o-mini" = "gpt-4o-mini"
"ddg/claude-3-haiku" = "claude-3-haiku-20240307"
"ddg/mixtral-8x7b" = "mistralai/Mixtral-8x7B-Instruct-v0.1"
"ddg/meta-Llama-3-1-70B-Instruct-Turbo" = "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo"
- Install the binary:
go install github.com/nerdneilsfield/go-ddg-chat-api@latest
-
Install from Releases
-
Install from docker:
# docker hub
docker pull nerdneils/go-ddg-chat-api
# ghcr
docker pull ghcr.io/nerdneilsfield/go-ddg-chat-api
Create a config.toml
file:
port = 8085
host = "0.0.0.0"
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
tokens = ["duckduckgo-chat-api-token"]
ddg_chat_api_url = "https://duckduckgo.com/"
[model_mapping]
"ddg/gpt-4o-mini" = "gpt-4o-mini"
"ddg/claude-3-haiku" = "claude-3-haiku-20240307"
"ddg/mixtral-8x7b" = "mistralai/Mixtral-8x7B-Instruct-v0.1"
"ddg/meta-Llama-3-1-70B-Instruct-Turbo" = "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo"
Run the server:
go-ddg-chat-api run config.toml
Check version:
go-ddg-chat-api version
Debug output:
go-ddg-chat-api run config.toml -v
Run with docker:
# normal output
docker run -d --name go-ddg-chat-api -p 8085:8085 -v $(pwd)/config.toml:/app/config.toml nerdneils/go-ddg-chat-api
# with proxy
docker run -d --name go-ddg-chat-api -p 8085:8085 -e HTTPS_PROXY=http://your-proxy-url:8080 -v $(pwd)/config.toml:/app/config.toml nerdneils/go-ddg-chat-api
# debug output
docker run -d --name go-ddg-chat-api -p 8085:8085 -v $(pwd)/config.toml:/app/config.toml nerdneils/go-ddg-chat-api /app/go-ddg-chat-api run /app/config.toml -v
GET /v1/models
- List available modelsPOST /v1/chat/completions
- Create chat completionDELETE /v1/chat/completions/{id}
- Delete chat completionGET /live
- Liveness probeGET /ready
- Readiness probe
curl -X POST http://localhost:8085/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-token" \
-d '{
"model": "ddg/claude-3-haiku",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
],
"stream": true
}'
HTTPS_PROXY
orhttps_proxy
- Proxy server URL (optional)
Requirements:
- Go 1.21 or higher
Build from source:
git clone https://github.com/nerdneilsfield/go-ddg-chat-api
cd go-ddg-chat-api
go build
+-----------------+
| |
| Client Request |
| |
+--------+--------+
|
v
+----------------+ +-----------------+ +----------------------+
| | | | | |
| Auth Middleware+--->+ Chat Completion +--->+ Generate UUID |
| | | Handler | | for Conversation |
+----------------+ +-----------------+ +----------------------+
|
v
+-----------------+ +----------------------+
| | | |
| Stream Response |<---+ Create Response |
| Channel | | Channel |
+--------+--------+ +----------------------+
|
v
+-----------------+ +---------------------+ +------------------+
| | | | | |
| Get VQD Token +<---+ Chat with DDG API +--->+ Process Messages |
| | | | | |
+-----------------+ +---------------------+ +------------------+
| | |
v v v
+-----------------+ +---------------------+ +------------------+
| | | | | |
| Random UserAgent| | Stream DDG Response | | Update History |
| | | | | |
+-----------------+ +---------------------+ +------------------+
|
v
+-----------------+
| |
| Client Response |
| |
+-----------------+
MIT License
References:
This project provides an OpenAI-compatible interface for DuckDuckGo's chat service. It is not affiliated with or endorsed by DuckDuckGo or OpenAI.