API Documentation
Complete guide to integrating with the DocuDroid API for document analysis and intelligent chat interactions.
🔐 Authentication
Currently, the API operates without authentication for demo purposes. In a production environment, implement appropriate authentication mechanisms such as API keys or OAuth2.
📋 Workflow Guide
1. Initialize a Session
- Start by calling
/session/initto get athread_id - This
thread_idis required for all subsequent interactions
2. Choose Your Interaction Mode
- General Chat: Start chatting immediately using
/chatwithmode: "general" - PDF Analysis:
- Upload PDF using
/upload/pdf - Check processing status via
/status/{process_id} - Start chatting with
/chatusingmode: "pdf"
- Upload PDF using
- Web Content Analysis:
- Submit URLs via
/upload/web - Start chatting with
/chatusingmode: "web"
- Submit URLs via
💬 Chat Modes
DocuDroid supports three distinct chat modes, each designed for specific use cases:
General Mode
Standard conversation mode without document context.
- Default mode if none specified
- Suitable for general queries and system information
- No prior content upload required
PDF Mode
Enables conversation about uploaded PDF documents.
- Requires prior PDF upload
- Supports document analysis and specific queries
- Maintains context across conversations
Web Mode
Facilitates discussion about processed web content.
- Requires prior URL submission
- Analyzes web page content
- Suitable for web research and content analysis
🔄 Session Management
Each interaction is managed through a session identified by a unique thread_id.
thread_id maintains conversation context and must be included in all requests after initialization.
📡 API Endpoints
/session/init
Initialize Chat Session
Creates a new chat session and returns a thread ID for subsequent requests.
Curl Example:
curl -X POST http://localhost:8000/session/init \
-H "Content-Type: application/json"
Success Response:
{
"thread_id": "550e8400-e29b-41d4-a716-446655440000",
"message": "Welcome! You can:\n1. Chat generally\n2. Upload PDFs for analysis\n3. Share URLs for web content analysis"
}
/chat
Send Chat Message
Send a message and receive an AI response based on the selected mode.
| Parameter | Type | Description |
|---|---|---|
| messagerequired | string | The user's message or question |
| thread_idrequired | string | Session identifier from /session/init |
| modeoptional | string | Chat mode: "general" (default), "pdf", or "web" |
- "pdf" mode requires prior PDF upload
- "web" mode requires prior URL submission
Curl Example:
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{
"message": "Tell me about your capabilities",
"thread_id": "550e8400-e29b-41d4-a716-446655440000",
"mode": "general"
}'
Success Response:
{
"response": "I am DocuDroid, an intelligent document assistant. I can help you with general conversations, analyze PDF documents after they're uploaded via the /upload/pdf endpoint, and process web content that's been shared through the /upload/web endpoint."
}
Error Response:
{
"detail": "No PDF content has been loaded yet. Please upload a PDF first."
}
/upload/pdf
Upload PDF Document
Upload a PDF file for analysis. Uses multipart/form-data format.
| Parameter | Type | Description |
|---|---|---|
| filerequired | file | PDF file to upload (max size: 10MB) |
| thread_idrequired | string | Session identifier |
Curl Example:
curl -X POST http://localhost:8000/upload/pdf \
-H "Content-Type: multipart/form-data" \
-F "file=@document.pdf" \
-F "thread_id=550e8400-e29b-41d4-a716-446655440000"
Success Response:
{
"status": "processing",
"message": "📄 Processing PDF: document.pdf...",
"filename": "document.pdf",
"process_id": "proc-550e8400-e29b-41d4-a716-446655440000"
}
/upload/web
Add Web Content
Process content from provided URLs for analysis.
| Parameter | Type | Description |
|---|---|---|
| thread_idrequired | string | Session identifier |
| urlsrequired | array | Array of URLs to process |
Curl Example:
curl -X POST http://localhost:8000/upload/web \
-H "Content-Type: application/json" \
-d '{
"thread_id": "550e8400-e29b-41d4-a716-446655440000",
"urls": [
"https://example.com/article1",
"https://example.com/article2"
]
}'
Success Response:
{
"status": "success",
"message": "🌐 Successfully added web content. You can now ask questions about it."
}
/status/{process_id}
Check Processing Status
Check the status of a PDF processing task.
Curl Example:
curl -X GET http://localhost:8000/status/proc-550e8400-e29b-41d4-a716-446655440000
Success Response:
{
"status": "completed",
"message": "✅ Successfully processed document.pdf. You can now ask questions about its content."
}
⚡ Best Practices
- Always initialize a new session before starting interactions
- Store the thread_id securely and include it in all subsequent requests
- For PDF uploads, poll the status endpoint until processing is complete
- Keep PDF files under 10MB for optimal processing
- When using web mode, ensure URLs are accessible and contain relevant content
- Handle rate limits appropriately in production environments
- Implement proper error handling for all API responses
- Use appropriate timeouts for long-running operations
⚠️ Error Handling
The API uses standard HTTP status codes and provides detailed error messages:
| Status Code | Description | Common Scenarios |
|---|---|---|
| 200 | Success | Request processed successfully |
| 400 | Bad Request | Missing parameters, invalid file type |
| 404 | Not Found | Invalid process_id, resource not found |
| 413 | Payload Too Large | PDF file exceeds size limit |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Processing error, server issues |
Error Response Format:
{
"detail": "Detailed error message explaining what went wrong"
}
🔄 Rate Limiting
Recommended limits for production:
- Chat messages: 60 requests per minute
- PDF uploads: 10 requests per minute
- Web content: 30 requests per minute
Rate limit headers will be included in responses:
X-RateLimit-Limit: [requests_per_window]
X-RateLimit-Remaining: [requests_remaining]
X-RateLimit-Reset: [reset_timestamp]