📚 Complete Tutorial: Medical Chatbot Configuration with AI Engine
💰 TOKEN SYSTEM AND COST OPTIMIZATION
🔤 WHAT ARE TOKENS?
Tokens are the basic units used for billing AI services. One token represents approximately:
📝 1 token = 4 characters in English
📝 1 token = 1 short word in foreign language
📖 1000 tokens ≈ 750 words
Practical examples:
Simple question: “what medicines for cough?” → ~10 tokens
Short medical answer (200 words) → ~250 tokens
Complete conversation (question + answer) → ~300-500 tokens
🏪 OPENROUTER – THE AI “SUPERMARKET”
OpenRouter functions as a centralized marketplace where different AI providers compete on price:
YOUR APPLICATION → OPENROUTER → [Provider1, Provider2, Provider3...] ↓ Automatically chooses the lowest price
🎯 HOW IT WORKS:
A single API Key for all providers
Automatic selection of the cheapest available model
Unified billing – a single monthly invoice
Transparent switching between providers without code change
📊 TOKEN PRICE COMPARISON TABLE
| Provider | Model | Input (1M tokens) | Output (1M tokens) | Performance |
|---|---|---|---|---|
| OpenRouter | DeepSeek | $0.14 | $0.28 | ✅ Excellent |
| OpenRouter | Mistral 7B | $0.14 | $0.42 | ✅ Good |
| OpenRouter | Llama 3.1 8B | $0.18 | $0.54 | ✅ Very Good |
| OpenAI Direct | GPT-3.5 Turbo | $0.50 | $1.50 | ✅ Good |
| OpenRouter | Claude Haiku | $0.25 | $1.25 | ✅ Excellent |
| OpenAI Direct | GPT-4 Turbo | $10.00 | $30.00 | ✅ Exceptional |
| Google Direct | Gemini Pro | $0.50 | $1.50 | ✅ Good |
💡 CONVERSATION COST CALCULATION:
Typical Conversation: 500 tokens With DeepSeek: (500 ÷ 1,000,000) × $0.28 = $0.00014 With GPT-4 Turbo: (500 ÷ 1,000,000) × $30.00 = $0.01500
🏆 COST-PERFORMANCE RECOMMENDATIONS:
🥇 DEEPSEEK (via OpenRouter)
Best price-quality ratio
Cost: 10x lower than GPT-4 Turbo
Performance: Excellent
🥈 MISTRAL (via OpenRouter)
Cost similar to DeepSeek
Specialized for European languages
🥉 GPT-3.5 TURBO (direct)
Good for prototyping
Decent cost, moderate performance
🚀 COST OPTIMIZATION STRATEGY
1. FOR TESTING/DEVELOPMENT:
OpenRouter + DeepSeek: $0.14/M input - Minimum cost with good performance - Ideal for fast iterations
2. FOR QUALITY PRODUCTION:
OpenRouter with fallback: DeepSeek → Mistral → Claude - Perfect cost-quality balance - Automatic redundancy
3. FOR MAXIMUM ACCURACY:
GPT-4 Turbo direct: $10.00/M input - Most obedient to prompts - Guaranteed quality, higher cost
👉 OpenRouter offers the best cost-flexibility ratio for medical projects!
🗃️ MEDICINE DATABASE (JSON)
[
{
“name”: “Amoxicillin”,
“category”: “Antibiotic”,
“prescription”: “Yes”,
“indications”: “Bacterial respiratory infections, Dental infections, Urinary tract infections. Administered only on a doctor’s recommendation.”
},
{
“name”: “Ciprofloxacin”,
“category”: “Fluoroquinolone Antibiotic”,
“prescription”: “Yes”,
“indications”: “Urinary tract infections, Gastrointestinal infections, and Respiratory infections. Requires a medical prescription.”
},
{
“name”: “Metronidazole”,
“category”: “Antibiotic / Antiparasitic”,
“prescription”: “Yes”,
“indications”: “Anaerobic infections and Parasitic infections. Administration only under medical supervision.”
},
{
“name”: “Prednisone”,
“category”: “Corticosteroid”,
“prescription”: “Yes”,
“indications”: “Inflammatory and autoimmune conditions. Administered only upon the doctor’s indication.”
},
{
“name”: “Enalapril”,
“category”: “Antihypertensive (ACE Inhibitor)”,
“prescription”: “Yes”,
“indications”: “Arterial hypertension and heart failure. Requires medical monitoring.”
},
{
“name”: “Diazepam”,
“category”: “Anxiolytic / Sedative”,
“prescription”: “Yes”,
“indications”: “Anxiety disorders and insomnia. Uncontrolled administration can lead to dependence.”
},
{
“name”: “Insulin”,
“category”: “Antidiabetic Hormone”,
“prescription”: “Yes”,
“indications”: “Treatment of diabetes mellitus. Dosage is determined exclusively by the doctor.”
},
{
“name”: “Paracetamol”,
“category”: “Antipyretic / Analgesic”,
“prescription”: “No”,
“indications”: “Fever and mild pain. Available without prescription.”
},
{
“name”: “Ibuprofen”,
“category”: “Non-steroidal Anti-inflammatory Drug (NSAID)”,
“prescription”: “No”,
“indications”: “Muscle pain, Joint pain, Dental pain, and fever. No prescription required for low doses.”
},
{
“name”: “Loratadine”,
“category”: “Antihistamine”,
“prescription”: “No”,
“indications”: “Seasonal allergies and hives. Can be purchased without a prescription.”
}
]
🎯 PROJECT GOAL
Creating a medical chatbot that:
Answers EXCLUSIVELY from its own medicine database
Never invents medicines or indications
Provides short and precise answers (under 200 words)
Recommends medical consultation for treatment
Uses cost-optimized infrastructure
🏗️ SYSTEM ARCHITECTURE
Data Flow:
User → Chatbot AI Engine → Qdrant Vector DB → Medicines JSON → Response
Critical Components:
AI Engine Pro – the chatbot platform
Qdrant Cloud – vector database
OpenAI GPT-4 Turbo – optimized AI model
PDF/JSON – the medicine database






