Documentation
API Authentication

API Authentication

AskYourDatabase provides REST APIs that allow you to programmatically interact with your chatbots. These APIs enable you to build completely custom chatbot UIs, integrate with platforms like Slack, WhatsApp, or any other custom applications.

Use Cases

With our APIs, you can:

  • Build Custom UI: Create your own chatbot interface with complete control over design and user experience
  • Platform Integration: Connect AskYourDatabase to Slack, WhatsApp, Discord, Microsoft Teams, or any messaging platform
  • Mobile Apps: Integrate database querying capabilities into mobile applications
  • Workflow Automation: Embed data insights into existing business workflows and tools
  • White-label Solutions: Build branded data analytics solutions for your clients
  • Voice Assistants: Integrate with Alexa, Google Assistant, or custom voice interfaces
  • Email Automation: Generate automated reports and insights via email
  • Custom Dashboards: Build specialized analytics interfaces for specific use cases

Example Implementation

We provide a complete example repository showing how to build a custom chatbot UI using our APIs:

The /chat-demo path in the example repository demonstrates a fully functional custom chatbot interface built with Next.js, showcasing:

  • Real-time Streaming: Live responses with Server-Sent Events (SSE)
  • SQL Query Visualization: Debug mode showing generated SQL queries and results
  • Function Execution Status: Visual indicators for SQL execution, Python code running, etc.
  • Modern UI Components: Responsive design with Tailwind CSS
  • Error Handling: Comprehensive error handling and user feedback
  • Message History: Persistent chat sessions with message pagination

Authentication

All API endpoints require authentication using API Keys.

Getting Your API Key

  1. Log in to your AskYourDatabase dashboard
  2. Navigate to SettingsAPI Keys
  3. Click Generate New API Key
  4. Copy and securely store your API key

⚠️ Important: Keep your API key secure and never expose it in client-side code or public repositories.

Authentication Method

All API requests must include your API key in the Authorization header using the Bearer token format:

Authorization: Bearer YOUR_API_KEY_HERE

Example Request

curl -X POST https://www.askyourdatabase.com/api/ask \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_key_here" \
  -d '{
    "question": "Show me total sales by month",
    "botid": "your_chatbot_id",
    "chatid": "your_chat_id"
  }'

Error Responses

401 Unauthorized

{
  "error": "Authentication failed"
}

400 Bad Request

{
  "error": "botid is required in API mode"
}

Rate Limits

API requests are subject to the same usage quotas as your subscription plan. Monitor your usage in the dashboard under SettingsUsage.

Supported Endpoints

Security Best Practices

  1. Rotate API Keys Regularly: Generate new keys periodically and revoke old ones
  2. Use HTTPS Only: Never send API keys over unencrypted connections
  3. Server-Side Only: Keep API keys on your backend servers, never in frontend code
  4. Environment Variables: Store API keys in environment variables, not in code
  5. Monitor Usage: Regularly check your API usage for any unusual activity