API Usage Examples

Ready-to-use examples for all Docura AI endpoints using cURL, Python, and Postman.

Example API Usage Examples
A demo of the API Usage Examples component in action.

API Endpoints Overview

HackRx
Query & answers
Cache
Memory management
Health
Status monitoring

How to add

# Production API
BASE_URL="https://yourapi.example.com"

# Local Development
BASE_URL="http://localhost:8000"

How to use

# Quick Health Check
curl -X GET "https://yourapi.example.com/health"

# Quick Query Example
curl -X POST "https://yourapi.example.com/hackrx/run" \
  -H "Content-Type: application/json" \
  -d '{"documents": ["document.pdf"], "questions": ["What is this document about?"]}'

🧠 HackRx Query Processing

Single Document Query - cURL

# Query a single document
curl -X POST "https://yourapi.example.com/hackrx/run" \
  -H "Content-Type: application/json" \
  -d '{
    "documents": ["document.pdf"],
    "questions": ["What is the main topic of this document?"],
    "search_strategy": "hybrid"
  }'

# Multiple questions on same document
curl -X POST "https://yourapi.example.com/hackrx/run" \
  -H "Content-Type: application/json" \
  -d '{
    "documents": ["report.pdf"],
    "questions": [
      "What are the key findings?",
      "What recommendations are made?",
      "What is the conclusion?"
    ],
    "search_strategy": "semantic"
  }'

Multiple Documents Query - cURL

# Query multiple documents
curl -X POST "https://yourapi.example.com/hackrx/run" \
  -H "Content-Type: application/json" \
  -d '{
    "documents": ["doc1.pdf", "doc2.docx", "presentation.pptx"],
    "questions": [
      "Compare the main findings across all documents",
      "What common themes appear in these documents?"
    ],
    "search_strategy": "hybrid"
  }'

Postman HackRx Query

1

Create New Request

β€’ Method: POST
β€’ URL: https://yourapi.example.com/hackrx/run
2

Headers

Content-Type: application/json
3

Body (raw JSON)

{
  "documents": ["document.pdf"],
  "questions": ["What is this document about?"],
  "search_strategy": "hybrid"
}

Advanced Postman Setup

1

Environment Variables

Create a new environment with:
baseUrl: https://yourapi.example.com
localUrl: http://localhost:8000
2

Multiple Questions Example

{
  "documents": ["doc1.pdf", "doc2.docx"],
  "questions": [
    "What are the main findings?",
    "What recommendations are made?",
    "Compare the two documents"
  ],
  "search_strategy": "semantic"
}
3

Tests Tab (Optional)

Add response validation:
pm.test("Status is 200", function () {
Β Β pm.response.to.have.status(200);
});

πŸ’š Health Check

Health Status - cURL

# Check API health
curl -X GET "https://yourapi.example.com/health"

# With verbose output
curl -X GET "https://yourapi.example.com/health" -v

# Save health status
curl -X GET "https://yourapi.example.com/health" -o health.json

Postman Health Check

1

Create Health Check Request

β€’ Method: GET
β€’ URL: https://yourapi.example.com/health
2

Expected Response

{
  "status": "healthy",
  "timestamp": 1691234567.89
}

Postman Health Monitoring

1

Collection Setup

Create a collection named "API Health Monitoring" with the health endpoint
2

Collection Runner

β€’ Run β†’ Iterations: 10
β€’ Delay: 30000ms (30 seconds)
β€’ Save responses for monitoring
3

Monitor Setup (Pro)

Use Postman Monitors to automatically check health every 5 minutes

πŸ—„οΈ Cache Management

Cache Operations - cURL

# Get cache statistics
curl -X GET "https://yourapi.example.com/cache/stats"

# Clear all cache entries
curl -X POST "https://yourapi.example.com/cache/clear"

# Clear expired entries (no-op for this API)
curl -X POST "https://yourapi.example.com/cache/clear-expired"

Postman Cache Management

1

Cache Stats Request

β€’ Method: GET
β€’ URL: https://yourapi.example.com/cache/stats
2

Clear Cache Request

β€’ Method: POST
β€’ URL: https://yourapi.example.com/cache/clear
3

Collection Organization

Create a "Cache Management" folder with all cache endpoints for easy access

Postman Workspace Setup

Complete API Collection Structure:

πŸ“ Docura AI API
Β Β πŸ“ HackRx Queries
Β Β Β Β πŸ“„ Single Document Query
Β Β Β Β πŸ“„ Multiple Documents Query
Β Β πŸ“ Health Monitoring
Β Β Β Β πŸ“„ Health Check
Β Β πŸ“ Cache Management
Β Β Β Β πŸ“„ Get Cache Stats
Β Β Β Β πŸ“„ Clear Cache
Β Β Β Β πŸ“„ Clear Expired Cache
Pro Tip: Save all requests in a collection and export for team sharing!

πŸ“„ Response Examples

βœ… HackRx Query Success

{
  "answers": [
    "The document discusses machine learning applications in healthcare, focusing on diagnostic imaging and patient outcome prediction.",
    "Key findings include 95% accuracy in disease detection and 20% improvement in treatment effectiveness."
  ]
}

βœ… Health Check

{
  "status": "healthy",
  "timestamp": 1691234567.89
}

βœ… Cache Statistics

{
  "total_entries": 25,
  "memory_usage_mb": 145.7,
  "hit_rate": 0.85,
  "cache_size_limit": "1GB"
}

❌ Error Response

{
  "status": "error",
  "error": "Invalid file type",
  "supported_formats": ["pdf", "docx", "pptx", "html", "eml"],
  "received_format": "txt"
}

πŸ” Search Strategies

Semantic

🧠 Meaning-based search
🎯 Best for concept queries
πŸ“ Understands context

Hybrid

⚑ Best of both worlds
🎯 Semantic + keyword
πŸ“Š Recommended default

Keyword

πŸ”€ Exact term matching
⚑ Fast performance
πŸ“ Precise word search

⚑ Quick Reference

Endpoints

POST /hackrx/run
GET /health
GET /cache/stats
POST /cache/clear

File Limits

πŸ“ Max: ~50MB per file
⏱️ Timeout: 60 seconds
πŸ“ Types: PDF, DOCX, PPTX, HTML, EML

Best Practices

βœ… Use absolute file paths
βœ… Handle errors gracefully
βœ… Set appropriate timeouts

Environment

🌐 Prod: yourapi.example.com
🏠 Local: localhost:8000
πŸ”§ Use environment variables
Note: All examples use the production API endpoint. For local development, replace the URL with http://localhost:8000. The HackRx endpoint processes queries in parallel for better performance.