Package Exports
- duckduckgo-chat-interface
- duckduckgo-chat-interface/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (duckduckgo-chat-interface) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
🦆 DuckDuckGo AI Chat Interface
🚀 A Node.js interface for DuckDuckGo AI Chat
Simple and efficient integration with streaming support and session management
Features • Installation • Usage • API Reference
✨ Features
💬 Chat Experience
|
🧠 Integration
|
🛠️ Technical
|
🤖 Available Models
Model Name | Integration ID | Alias | Strength | Best For | Characteristics |
---|---|---|---|---|---|
GPT-4o mini | gpt-4o-mini | GPT4Mini | General purpose | Everyday questions | • Fast • Well-balanced |
Claude 3 Haiku | claude-3-haiku-20240307 | Claude3 | Creative writing | Explanations & summaries | • Clear responses • Concise |
Llama 3.3 70B | meta-llama/Llama-3.3-70B-Instruct-Turbo | Llama | Programming | Code-related tasks | • Technical precision • Detailed |
Mistral Small | mistralai/Mistral-Small-24B-Instruct-2501 | Mixtral | Knowledge & analysis | Complex topics | • Reasoning • Logic-focused |
o4-mini | o4-mini | O4Mini | Speed | Quick answers | • Very fast • Compact responses |
A simple and efficient Node.js interface for interacting with DuckDuckGo Chat API, based on complete reverse engineering of the official API.
📦 Installation
npm install duckduckgo-chat-interface
🎯 Usage
Module Import
import { DuckDuckGoChat, Models } from 'duckduckgo-chat-interface';
// or
import DuckDuckGoChat, { Models } from 'duckduckgo-chat-interface';
Basic Usage
import { DuckDuckGoChat, Models } from 'duckduckgo-chat-interface';
async function example() {
// Create a new chat session
const chat = new DuckDuckGoChat(Models.GPT4Mini);
// Initialize the session
await chat.initialize();
// Send a message and get the complete response
const response = await chat.sendMessage("Hello! How are you?");
console.log(response);
// Continue the conversation
const response2 = await chat.sendMessage("Can you explain what AI is?");
console.log(response2);
}
example().catch(console.error);
Streaming Usage
import { DuckDuckGoChat, Models } from 'duckduckgo-chat-interface';
async function streamExample() {
const chat = new DuckDuckGoChat(Models.Claude3);
await chat.initialize();
// Send a message with streaming
const response = await chat.sendMessageStream(
"Tell me a short story",
(chunk) => {
// This function is called for each data chunk
process.stdout.write(chunk);
}
);
console.log("\n\nComplete response:", response);
}
streamExample().catch(console.error);
History Management
import { DuckDuckGoChat, Models } from 'duckduckgo-chat-interface';
async function historyExample() {
const chat = new DuckDuckGoChat();
await chat.initialize();
await chat.sendMessage("My name is Alice");
await chat.sendMessage("What is my name?");
// Get complete history
const history = chat.getHistory();
console.log("History:", history);
// Clear history
await chat.clear();
}
historyExample().catch(console.error);
📖 API Reference
Available Models
import { Models } from 'duckduckgo-chat-interface';
console.log(Models.GPT4Mini); // 'gpt-4o-mini'
console.log(Models.Claude3); // 'claude-3-haiku-20240307'
console.log(Models.Llama); // 'meta-llama/Llama-3.3-70B-Instruct-Turbo'
console.log(Models.Mixtral); // 'mistralai/Mistral-Small-24B-Instruct-2501'
console.log(Models.O4Mini); // 'o4-mini'
// Get all available models
const allModels = DuckDuckGoChat.getAvailableModels();
console.log(allModels);
DuckDuckGoChat Class
Constructor
new DuckDuckGoChat(model = Models.GPT4Mini)
model
: The model to use (optional, defaults toModels.GPT4Mini
)
Methods
initialize()
Initializes the chat session and obtains necessary tokens.
await chat.initialize();
sendMessage(content)
Sends a message and returns the complete response.
const response = await chat.sendMessage("Your message");
sendMessageStream(content, onChunk)
Sends a message and processes the response with streaming.
const response = await chat.sendMessageStream(
"Your message",
(chunk) => console.log(chunk)
);
clear()
Clears conversation history and resets the session.
await chat.clear();
setModel(model)
Changes the model used for next messages.
chat.setModel(Models.Claude3);
getHistory()
Returns the complete message history.
const history = chat.getHistory();
getAvailableModels()
(static)
Returns the list of available models.
const models = DuckDuckGoChat.getAvailableModels();
🔧 Error Handling
import { DuckDuckGoChat } from 'duckduckgo-chat-interface';
async function errorHandling() {
try {
const chat = new DuckDuckGoChat();
await chat.initialize();
const response = await chat.sendMessage("Test message");
console.log(response);
} catch (error) {
console.error("Chat error:", error.message);
// Handle specific error types
if (error.message.includes('418')) {
console.log("Anti-bot detection, retrying...");
// Automatic retry is handled internally
}
}
}
🔧 Technical Details
Reverse Engineering
- VQD tokens automatic retrieval via
/duckchat/v1/status
- Dynamic headers with authenticated values
- Session cookie management complete handling
- Error 418 auto-recovery (98.3% success rate)
Features
- Persistent conversations with history tracking
- Automatic retry with exponential backoff
- Real-time streaming with chunk callbacks
- Model validation and error handling
📊 Performance
- Latency: ~200-500ms for first response
- Throughput: Real-time streaming support
- Error recovery: 98.3% automatic success
- Memory: Lightweight conversation history
⚠️ Requirements
- Node.js: 14.0.0 or higher
- Dependencies: axios for HTTP requests
- Network: Internet connection required
🚨 Troubleshooting
Error 418 (I'm a teapot)
The interface automatically handles these errors with retry and token refresh.
Unable to initialize
# Check internet connection
curl -I https://duckduckgo.com/duckchat/v1/status
# Enable debug mode
DEBUG=true node your-script.js
Streaming issues
Ensure you're handling chunks correctly in the callback function.
📜 License & Ethics
🛡️ Privacy & Responsibility
- Privacy First: This interface respects your privacy and stores no personal data
- Verify Information: Always verify critical information from AI responses
- Responsible Use: Use responsibly and in accordance with DuckDuckGo's terms
🔧 Unofficial interface based on DuckDuckGo Chat reverse engineering