MCPcopy Index your code
hub / github.com/HuggingBear/DuckDuckGo-AI

github.com/HuggingBear/DuckDuckGo-AI @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
18 symbols 35 edges 4 files 5 documented · 28%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

DuckDuckGo AI API

This is a heavily modified fork of duckduckgo-ai.

Yet another DuckDuckGo AI reverse engineering API running on Cloudflare Worker.

DuckDuckGo AI: https://duckduckgo.com/?q=DuckDuckGo&ia=chat

Deployment

  1. Clone the repo.
  2. Install dependencies by running npm i, configure KV storage and API_KEY to protect this deployment.
  3. Deploy to Cloudflare Worker by running npm run deploy.
  4. Open the worker URL in the browser and enjoy!

Warning: If API_KEY is not set, your API will be publicly accessible.

Configure API_KEY and KV storage: 1. Open wrangler.toml with your editor. 2. Fill in your own API_KEY (Actually a password), for example: sk-my-private-api-do-not-use. 3. Fill in your own KV storage ID, create and find it in your Cloudflare console.

Supported Models

  • gpt-4o-mini
  • claude-3-haiku-20240307
  • meta-llama/Llama-3.3-70B-Instruct-Turbo
  • o3-mini
  • mistralai/Mistral-Small-24B-Instruct-2501

Usage

Replace worker_url with your own:

Create conversation:

curl https://worker_url/v1/chat/completions \
-H "Authorization: Bearer $MY_WORKER_APIKEY" \
-H "Content-Type: application/json" \
-d '{
  "model": "o3-mini",
  "messages": [
    {
      "role": "user",
      "content": "Yo"
    }
  ]
}'

Response:

Note: The worker will attempt to save and restore the x-vqd-4 header by hashing your chat history, but it's not guaranteed to work. You should manually obtain it from the response header and pass it in the next request to ensure continuous chat functionality.

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding
x-vqd-4: 4-974561083254981360721938476051293847215
Server: cloudflare

{
  "id": "chatcmpl-duckduckgo-ai",
  "object": "chat.completion",
  "created": 1718720705,
  "model": "o3-mini",
  "system_fingerprint": "fp_e7692cea7",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Yo! What's up?"
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}

Known Limits

Conversation with more than one prompt message

DuckDuckGo AI requires the x-vqd-4 header to continue your conversation from the last response. The worker will try to save and restore it by hashing your messages, but this might cause issues when multiple persons send exactly the same message or your client application does not bring all history messages. You should obtain the x-vqd-4 header from the response header and pass it when you need to continue the conversation.

Extension points exported contracts — how you extend this code

OpenAIRequest (Interface)
(no doc)
src/types.d.ts
OpenAIResponseChoice (Interface)
(no doc)
src/types.d.ts
OpenAIResponse (Interface)
(no doc)
src/types.d.ts
OpenAIStreamResponseChoice (Interface)
(no doc)
src/types.d.ts
OpenAIStreamResponse (Interface)
(no doc)
src/types.d.ts

Core symbols most depended-on inside this repo

generateConversationHash
called by 4
src/conversation.ts
saveConversationId
called by 3
src/conversation.ts
getModelFingerprint
called by 2
src/index.ts
hashString
called by 2
src/utils.ts
getConversationId
called by 1
src/conversation.ts
createNewConversationId
called by 1
src/index.ts
createStreamResponse
called by 1
src/index.ts
handleStreamResponsePart
called by 1
src/index.ts

Shape

Function 13
Interface 5

Languages

TypeScript100%

Modules by API surface

src/index.ts9 symbols
src/types.d.ts5 symbols
src/conversation.ts3 symbols
src/utils.ts1 symbols

For agents

$ claude mcp add DuckDuckGo-AI \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact