Chat API
Interact with the IslamChat Assistant through a conversational API.
HTTP Endpoint Summary
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/chat | Send a message to the assistant |
Authentication
To access this endpoint, you must include a API key in the request header.
x-api-key: YOUR_API_KEY
API keys are provided manually for now. Contact us at apps@midade.ai to request one.
Request
Request Body Parameters
| Field | Type | Description |
|---|---|---|
text | string | The message content to send to the assistant. |
thread_id | string | null | The ID of the thread to continue. Use null to start a new thread. |
Re-using the same
thread_idwill continue the same conversation context. Usenullto reset context and start a fresh session.
Code Examples
- JavaScript
- Python
- cURL
fetch("https://ai.midadedev.com/api/chat", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "msk-your-secret-key", // Required API key
},
body: JSON.stringify({
text: "السلام عليكم", // The user’s message
thread_id: null, // Start a new thread
}),
})
.then((res) => res.json())
.then((data) => console.log(data));
import requests
headers = {
"Content-Type": "application/json",
"x-api-key": "msk-your-secret-key" # Required API key
}
response = requests.post("https://ai.midadedev.com/api/chat", json={
"text": "السلام عليكم", # The user's input
"thread_id": None, # Set to None for a new conversation
})
print(response.json())
curl -X POST https://ai.midadedev.com/api/chat \
-H "Content-Type: application/json" \
-H "x-api-key: sk-your-secret-key" \
-d '{
"text": "السلام عليكم", # Your message
"thread_id": null, # New conversation
}'
Response
Response Fields
| Field | Type | Description |
|---|---|---|
thread_id | string | The ID of the conversation thread |
message | string | The assistant’s reply to the user’s message |
title | string | A system-generated title summarizing the chat |
Error Responses
| Status Code | Meaning | Cause |
|---|---|---|
| 401 | Unauthorized | Missing or invalid x-api-key |
| 400 | Bad Request | Invalid or malformed JSON body |
| 404 | Not Found | Assistant or endpoint does not exist |
| 429 | Too Many Requests | You’ve hit your rate limit |
| 500 | Internal Server Error | Something went wrong on our end |
Sample Output
Expect a sample response containing:
{
"thread_id": "thread_xxxxxxxxxxxxxxxxxxxxxxxx",
"message": "وعليكم السلام! كيف يمكنني مساعدتك اليوم؟",
"title": "Random Greeting Chaos!"
}
Rate Limits
Each API key has a rate limit of 100 requests per minute. Exceeding this will return a 429 Too Many Requests error.
API Version
This is the v1 of the API. Backward-incompatible changes will result in a new version.