Getting Started
Prerequisites: You'll need an API key to get started. Contact our team at drinfo.ai/contact to request access.
Quick Start
Installation
# Python
pip install drinfo
# JavaScript/Node.js
npm install drinfo-sdk
Authentication
DR. INFO API uses Bearer token authentication. Include your API key in the Authorization header of every request.
Authentication Header
Authorization: Bearer YOUR_API_KEY
Example Request
import requests
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
response = requests.post(
"https://api.drinfo.ai/v1/chat",
headers=headers,
json={"message": "What is hypertension?"}
)
Security Notice: Never expose your API key in client-side code or public repositories. Use environment variables or secure key management systems.
API Endpoints
/api/chat
Send a chat message and receive a standard response with AI-powered medical information.
Request Body:
{
"message": "string",
"conversationId": "string (optional)",
"model": "string (optional)",
"temperature": 0.7,
"maxTokens": 1000
}
Response:
{
"response": "string",
"citations": [
{
"source": "string",
"url": "string",
"relevance": "number"
}
],
"conversationId": "string",
"model": "string"
}
/api/chat/stream
Send a chat message and receive a streaming response for real-time interaction.
Request Body:
{
"message": "string",
"conversationId": "string (optional)",
"model": "string (optional)",
"temperature": 0.7
}
Response:
Server-Sent Events (SSE) stream with chunks:
data: {"content": "string", "type": "text"}
data: {"source": "string", "url": "string", "type": "citation"}
data: {"type": "end"}
/api/generate-key
Generate new API keys with custom permissions and expiration dates.
Request Body:
{
"name": "string",
"permissions": ["read", "write"],
"expiresAt": "2024-12-31T23:59:59Z (optional)"
}
Response:
{
"apiKey": "string",
"keyId": "string",
"name": "string",
"createdAt": "2024-01-01T00:00:00Z"
}
/api/conversations/:conversationId
Retrieve conversation history and context for a specific conversation.
Response:
{
"conversationId": "string",
"messages": [
{
"role": "user" | "assistant",
"content": "string",
"timestamp": "2024-01-01T00:00:00Z"
}
],
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z"
}
Code Examples
Python Example
import requests
import json
API_KEY = "your-api-key-here"
BASE_URL = "https://api.drinfo.ai/v1"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Standard request
response = requests.post(
f"{BASE_URL}/chat",
headers=headers,
json={
"message": "What are the symptoms of diabetes?",
"conversationId": "conv_123"
}
)
result = response.json()
print(result['response'])
print("Citations:", result['citations'])
JavaScript Example
const API_KEY = 'your-api-key-here';
const BASE_URL = 'https://api.drinfo.ai/v1';
// Standard request
async function askQuestion(message) {
const response = await fetch(`${BASE_URL}/chat`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: message,
conversationId: 'conv_123'
})
});
const data = await response.json();
console.log(data.response);
}
askQuestion('What is hypertension?');
React Integration
Integrate DR. INFO API seamlessly into your React applications with these examples and best practices.
Basic React Hook
import { useState } from 'react';
const useDrInfoChat = () => {
const [response, setResponse] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const sendMessage = async (message, conversationId) => {
setLoading(true);
setError(null);
try {
const res = await fetch('/api/chat', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.NEXT_PUBLIC_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ message, conversationId })
});
if (!res.ok) throw new Error('API request failed');
const data = await res.json();
setResponse(data.response);
return data;
} catch (err) {
setError(err.message);
throw err;
} finally {
setLoading(false);
}
};
return { response, loading, error, sendMessage };
};
export default useDrInfoChat;
Chat Component Example
import { useState } from 'react';
import useDrInfoChat from './hooks/useDrInfoChat';
export default function ChatInterface() {
const [input, setInput] = useState('');
const [conversationId] = useState('conv_' + Date.now());
const { response, loading, error, sendMessage } = useDrInfoChat();
const handleSubmit = async (e) => {
e.preventDefault();
if (!input.trim()) return;
try {
await sendMessage(input, conversationId);
setInput('');
} catch (err) {
console.error('Failed to send message:', err);
}
};
return (
<div className="chat-container">
<div className="messages">
{response && (
<div className="message assistant">
{response}
</div>
)}
</div>
<form onSubmit={handleSubmit}>
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Ask a medical question..."
disabled={loading}
/>
<button type="submit" disabled={loading}>
{loading ? 'Sending...' : 'Send'}
</button>
</form>
{error && <div className="error">{error}</div>}
</div>
);
}
Error Handling
The API uses standard HTTP status codes and returns detailed error messages in JSON format.
Status Codes
Error Response Format
{
"error": {
"code": "string",
"message": "string",
"details": "string (optional)"
}
}
Example Error Handling
try:
response = requests.post(
f"{BASE_URL}/chat",
headers=headers,
json={"message": query}
)
response.raise_for_status()
data = response.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 401:
print("Authentication failed. Check your API key.")
elif e.response.status_code == 429:
print("Rate limit exceeded. Please wait.")
else:
error_data = e.response.json()
print(f"Error: {error_data['error']['message']}")
Rate Limits
Rate limits are applied per API key to ensure fair usage and system stability.
Default Limits
Tier | Req/Min | Req/Mon |
---|---|---|
Free Tier | 10 | 100 |
Pay As You Go | 500 | Unlimited |
Rate Limit Headers
Every API response includes headers with rate limit information:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1640995200
Need higher limits? Contact us to discuss enterprise plans with custom rate limits and dedicated support.
Pricing
DR. INFO offers flexible pricing plans to suit organizations of all sizes, from startups to large healthcare enterprises.
Free Tier
- 100 API calls/month
- Basic support
- Community access
- Standard models
Pay As You Go
- No monthly commitment
- Pay only for what you use
- Priority support
- Advanced models
Token-Based Billing
All plans use token-based billing for predictable costs. Pricing is based on the number of tokens processed in your requests and responses. Contact us for detailed token pricing and volume discounts.
Frequently Asked Questions
Yes, you can change your plan at any time. Changes take effect immediately, and we'll prorate the difference.
Requests will be rate-limited once you reach your monthly quota. You can upgrade your plan or purchase additional capacity.
Yes, we offer special pricing for qualified non-profit organizations and educational institutions. Contact our sales team for details.
Need Help?
Our team is here to support your integration. Contact us for API access, technical questions, or enterprise solutions.