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:
- GitHub Repository: https://github.com/AskYourDatabase/nextjs-chatbot (opens in a new tab)
- Live Demo: https://nextjs-ayd-demo.vercel.app/chat-demo (opens in a new tab)
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
- Log in to your AskYourDatabase dashboard
- Navigate to Settings → API Keys
- Click Generate New API Key
- 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 Settings → Usage.
Supported Endpoints
POST /api/ask
- Send questions to your chatbotGET /api/chatbot/messages
- Retrieve chat messagesPOST /api/chatbot/newChat
- Create new chat sessions
Security Best Practices
- Rotate API Keys Regularly: Generate new keys periodically and revoke old ones
- Use HTTPS Only: Never send API keys over unencrypted connections
- Server-Side Only: Keep API keys on your backend servers, never in frontend code
- Environment Variables: Store API keys in environment variables, not in code
- Monitor Usage: Regularly check your API usage for any unusual activity