Koveh API

Web Search API

Web search using DuckDuckGo Instant Answer API

Web Search API

Web search functionality using DuckDuckGo Instant Answer API for real-time information retrieval.

Base URL: api.koveh.com/web-search/

Endpoints

MethodEndpointDescription
GET/healthService health check
POST/searchPerform web search
GET/search/historyGet search history
GET/search/sessionsGet search sessions
GET/search/statsGet search statistics
GET/modelsGet available search models
GET/usageGet usage statistics

Authentication

All endpoints require Bearer token authentication:

curl -H "Authorization: Bearer YOUR_API_KEY" \
  "api.koveh.com/web-search/search"

Perform web searches and retrieve real-time information.

Endpoint: POST /search

Request Body

{
  "query": "Python FastAPI tutorial",
  "max_results": 5,
  "region": "wt-wt",
  "time": "m",
  "include_links": true
}

Parameters

  • query (string, required): Search query
  • max_results (number, optional): Maximum number of results. Default: 10
  • region (string, optional): Region for search results. Default: "wt-wt"
  • time (string, optional): Time filter (d, w, m, y). Default: null
  • include_links (boolean, optional): Include links in response. Default: true

Response

{
  "query": "Python FastAPI tutorial",
  "results": [
    {
      "title": "FastAPI Tutorial - User Guide",
      "url": "https://fastapi.tiangolo.com/tutorial/",
      "description": "FastAPI is a modern, fast web framework for building APIs with Python 3.7+ based on standard Python type hints...",
      "snippet": "Learn how to use FastAPI with interactive examples..."
    }
  ],
  "total_results": 1,
  "search_time": 0.245,
  "timestamp": "2025-08-30T09:19:31.245295"
}

Example Request

curl -X POST "api.koveh.com/web-search/search" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Python FastAPI tutorial",
    "max_results": 5
  }'

Search History

Get search history for the authenticated user.

Endpoint: GET /search/history

Query Parameters

  • limit (number, optional): Number of history items to return. Default: 50
  • offset (number, optional): Number of items to skip. Default: 0

Response

{
  "history": [
    {
      "id": "search-123",
      "query": "Python FastAPI tutorial",
      "timestamp": "2025-08-30T09:19:31.245295",
      "results_count": 5,
      "search_time": 0.245
    }
  ],
  "total": 150,
  "limit": 50,
  "offset": 0
}

Example Request

curl -X GET "api.koveh.com/web-search/search/history?limit=10" \
  -H "Authorization: Bearer YOUR_API_KEY"

Search Sessions

Get search sessions for the authenticated user.

Endpoint: GET /search/sessions

Query Parameters

  • limit (number, optional): Number of sessions to return. Default: 20
  • offset (number, optional): Number of items to skip. Default: 0

Response

{
  "sessions": [
    {
      "session_id": "session-123",
      "start_time": "2025-08-30T09:00:00.000000",
      "end_time": "2025-08-30T09:30:00.000000",
      "queries_count": 5,
      "total_results": 25
    }
  ],
  "total": 45,
  "limit": 20,
  "offset": 0
}

Example Request

curl -X GET "api.koveh.com/web-search/search/sessions" \
  -H "Authorization: Bearer YOUR_API_KEY"

Search Statistics

Get search statistics for the authenticated user.

Endpoint: GET /search/stats

Response

{
  "total_searches": 1250,
  "total_results": 12500,
  "average_search_time": 0.245,
  "most_common_queries": [
    {"query": "Python tutorial", "count": 45},
    {"query": "FastAPI", "count": 32}
  ],
  "searches_by_day": [
    {"date": "2025-08-30", "count": 25},
    {"date": "2025-08-29", "count": 30}
  ]
}

Example Request

curl -X GET "api.koveh.com/web-search/search/stats" \
  -H "Authorization: Bearer YOUR_API_KEY"

Available Models

Get list of available search models and configurations.

Endpoint: GET /models

Response

{
  "models": [
    {
      "id": "duckduckgo",
      "name": "DuckDuckGo Instant Answer",
      "description": "Privacy-focused search engine with instant answers",
      "max_results": 10,
      "supported_regions": ["wt-wt", "us-en", "uk-en"],
      "supported_time_filters": ["d", "w", "m", "y"]
    }
  ]
}

Example Request

curl -X GET "api.koveh.com/web-search/models" \
  -H "Authorization: Bearer YOUR_API_KEY"

Usage Statistics

Get usage statistics for the authenticated user.

Endpoint: GET /usage

Response

{
  "total_requests": 1250,
  "requests_this_month": 150,
  "requests_this_week": 25,
  "requests_today": 5,
  "rate_limit_remaining": 35,
  "rate_limit_reset": "2025-08-30T10:00:00.000000"
}

Example Request

curl -X GET "api.koveh.com/web-search/usage" \
  -H "Authorization: Bearer YOUR_API_KEY"

Health Check

Check service health status.

Endpoint: GET /health

Response

{
  "status": "healthy",
  "timestamp": "2025-08-30T09:19:31.245295",
  "search_engine": "duckduckgo",
  "api_available": true
}

Example Request

curl -X GET "api.koveh.com/web-search/health"

Integration Examples

Python Example

import requests

def search_web(query, max_results=5):
    response = requests.post(
        "http://api.koveh.com/web-search/search",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "query": query,
            "max_results": max_results
        }
    )
    return response.json()

# Perform a search
results = search_web("Python FastAPI tutorial")
for result in results['results']:
    print(f"Title: {result['title']}")
    print(f"URL: {result['url']}")
    print(f"Description: {result['description']}")
    print("---")

JavaScript Example

async function searchWeb(query, maxResults = 5) {
    const response = await fetch('http://api.koveh.com/web-search/search', {
        method: 'POST',
        headers: {
            'Authorization': 'Bearer YOUR_API_KEY',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            query: query,
            max_results: maxResults
        })
    });
    return await response.json();
}

// Perform a search
searchWeb('Python FastAPI tutorial')
    .then(results => {
        results.results.forEach(result => {
            console.log(`Title: ${result.title}`);
            console.log(`URL: ${result.url}`);
            console.log(`Description: ${result.description}`);
            console.log('---');
        });
    });

Perplexity-like Search with AI Response

import requests

def search_and_analyze(query):
    # 1. Search for information
    search_response = requests.post(
        "http://api.koveh.com/web-search/search",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={"query": query, "max_results": 5}
    )
    search_results = search_response.json()
    
    # 2. Generate response with context
    context = "\n".join([f"- {r['title']}: {r['description']}" for r in search_results['results']])
    
    chat_response = requests.post(
        "http://api.koveh.com/qwen3/chat",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "messages": [
                {"role": "user", "content": f"Based on this search: {context}, answer: {query}"}
            ]
        }
    )
    
    return chat_response.json()

# Use the function
result = search_and_analyze("What are the best practices for FastAPI development?")
print(result['choices'][0]['message']['content'])

Error Handling

The API returns standard error responses:

{
  "error": "Invalid search query provided",
  "status_code": 400,
  "timestamp": "2025-08-30T09:19:31.245295"
}

Common error codes:

  • 400: Bad Request (invalid parameters)
  • 401: Unauthorized (missing or invalid API key)
  • 404: Not Found (invalid endpoint)
  • 429: Too Many Requests (rate limit exceeded)
  • 500: Internal Server Error (search engine error)

Rate Limiting

  • Rate Limit: 60 requests per minute
  • Concurrent Requests: 10 simultaneous requests
  • Timeout: 30 seconds per request

Best Practices

  1. Query Specificity: Use specific, well-formed search queries
  2. Result Limits: Use appropriate max_results values (5-10 for most use cases)
  3. Error Handling: Always check for error responses and rate limits
  4. Caching: Cache search results when appropriate
  5. User Experience: Implement loading states for search requests
  6. Privacy: Be mindful of user privacy when storing search history

Use Cases

  • Information Retrieval: Get real-time information from the web
  • Research: Gather data for research and analysis
  • Content Discovery: Find relevant content and resources
  • Fact Checking: Verify information against web sources
  • News Aggregation: Collect current news and updates
  • Educational Content: Find tutorials and learning resources