API Documentation
Version 1 · REST · JSON
Overview
MHN AI API gives you a ready AI assistant. Send a message, get a smart reply. It understands Bengali, English and other languages, knows the current date/time, and can search the web for fresh information.
Every request needs an API key. Just add ?key=YOUR_API_KEY at the end of the URL — nothing else changes. CORS is enabled, so it works from servers, bots and browsers.
Endpoint
POST
https://mhngpt.xyz/api/public/ai-chat?key=YOUR_API_KEY
Replace YOUR_API_KEY with the key you received. The key can also be sent as header x-api-key, Authorization: Bearer ..., or a "key" field in the body.
Header: Content-Type: application/json
Request body
json
{
"message": "আপনার প্রশ্ন...", // required · long questions allowed
"history": [ // optional
{ "role": "user", "content": "..." },
{ "role": "assistant", "content": "..." }
]
}| Field | Type | Required | Description |
|---|---|---|---|
| message | string | Yes | The user's question. |
| history | array | No | Previous messages for context (role: user / assistant). |
Response
200 OK
{ "success": true, "reply": "AI এর উত্তর..." }Errors
json
400 { "success": false, "error": "message is required" }
401 { "success": false, "error": "API key missing / Invalid API key" }
403 { "success": false, "error": "API key expired" }
429 { "success": false, "error": "API key request limit reached" }
503 { "success": false, "error": "Service temporarily unavailable. Please try again." }Always check success before reading reply.
Limits
- Each key may have an expiry date and a request limit set by the admin (or be unlimited).
- Large questions are supported.
- Set your timeout to at least 60 seconds.
- Messages are not stored on our servers.
Connect to a Telegram bot
- Create a bot with
@BotFatherand copy its token. - Install:
pip install python-telegram-bot requests - Paste the code below, put your token in
YOUR_BOT_TOKEN, run it.
python · bot.py
# pip install python-telegram-bot requests
import requests
from telegram import Update
from telegram.ext import Application, MessageHandler, ContextTypes, filters
API = "https://mhngpt.xyz/api/public/ai-chat?key=YOUR_API_KEY"
history = {}
async def reply(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
uid = update.effective_user.id
msg = update.message.text
h = history.get(uid, [])[-20:]
r = requests.post(API, json={"message": msg, "history": h}, timeout=60).json()
answer = r.get("reply") or "দুঃখিত, এখন উত্তর দিতে পারছি না।"
history[uid] = h + [{"role": "user", "content": msg},
{"role": "assistant", "content": answer}]
await update.message.reply_text(answer)
app = Application.builder().token("YOUR_BOT_TOKEN").build()
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, reply))
app.run_polling()Add to a website
Paste this into any HTML page for a minimal chat box:
html
<div id="chat"></div>
<input id="q" placeholder="Ask MHN AI..." />
<button onclick="ask()">Send</button>
<script>
async function ask() {
const q = document.getElementById("q").value;
const r = await fetch("https://mhngpt.xyz/api/public/ai-chat?key=YOUR_API_KEY", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: q }),
}).then(r => r.json());
document.getElementById("chat").innerText = r.reply || r.error;
}
</script>Code examples
curl
curl -X POST https://mhngpt.xyz/api/public/ai-chat?key=YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{"message": "হ্যালো, কেমন আছো?"}'javascript
const res = await fetch("https://mhngpt.xyz/api/public/ai-chat?key=YOUR_API_KEY", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: "Hello!" }),
});
const data = await res.json();
console.log(data.reply);python
import requests
r = requests.post("https://mhngpt.xyz/api/public/ai-chat?key=YOUR_API_KEY",
json={"message": "Hello!"}, timeout=60)
print(r.json()["reply"])php
<?php
$ch = curl_init("https://mhngpt.xyz/api/public/ai-chat?key=YOUR_API_KEY");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode(["message" => "Hello!"]),
]);
echo json_decode(curl_exec($ch), true)["reply"];