Authentication
All protected endpoints require a valid JWT token. Obtain one by calling any of the four login endpoints, then include it in every request:
Authorization: Bearer <your-token>
Tokens are issued for one of four roles: admin, company, employee, or customer. Each role has different access levels, especially for database endpoints.
Making Requests
All endpoints accept and return JSON unless otherwise noted (e.g. file uploads use multipart/form-data, document downloads return binary). The base URL for all requests is:
https://api.jamiiai.com
Interactive Swagger documentation is available at /docs when running the API server.
AI Chat
Conversational AI powered by GPT-4o-mini with persistent conversation history, custom system prompts, and streaming support. Each user session maintains its own conversation context.
Send a message and receive an AI-generated response. The conversation history is maintained server-side.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The message to send to the AI |
Response
{
"response": "Quantum computing uses qubits..."
}
Return the full conversation history for the current session.
Response
{
"history": [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi! How can I help?"}
]
}
Clear the conversation history and start fresh.
Response
{"message": "Conversation history cleared"}
Update the system prompt that guides the AI's behaviour.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | The new system prompt |
Response
{"message": "System prompt updated", "prompt": "You are a pirate..."}
Voice Chat
Full audio pipeline β speech-to-text transcription with OpenAI Whisper, text-to-speech synthesis, and end-to-end audio conversations. Upload audio files and receive text or audio responses.
Send audio, get transcription + AI text response + audio response. Full STT β Chat β TTS pipeline.
Request
multipart/form-data with a file field containing the audio file.
Response
{
"transcription": "What is AI?",
"response": "AI stands for...",
"audio": "<base64-encoded MP3>"
}
Transcribe an audio file to text using OpenAI Whisper.
Request
multipart/form-data with a file field.
Response
{"text": "Hello, how are you?"}
Convert text to MP3 audio using OpenAI TTS.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to synthesize |
Response
Binary MP3 audio (audio/mpeg).
Send text, get AI text response + audio response (Chat β TTS).
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Message to send |
Response
{
"response": "Here is my answer...",
"audio": "<base64-encoded MP3>"
}
Video Chat
Extract audio and frames from uploaded videos using ffmpeg. Transcribe video audio, have conversations about video content, and describe video frames with GPT-4 Vision.
Upload video β extract audio β AI chat β text + audio response.
Request
multipart/form-data with a file field containing the video.
Upload video β extract audio β transcribe to text with Whisper.
Send text β chat β TTS β text + audio response.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Message to send |
Upload video β extract a frame at 1 second β describe with AI Vision.
Code Assistant
Generate, review, explain, and refactor code using AI with task-specific system prompts for focused, high-quality results. Supports all programming languages.
Generate code from a natural-language description.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
description | string | Yes | What to generate |
language | string | No | Target language (e.g. "python") |
Review code and return feedback on bugs, security issues, and improvements.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Code to review |
Explain what a piece of code does in plain language.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Code to explain |
Refactor code for better quality, readability, and maintainability.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Code to refactor |
instructions | string | No | Specific refactoring instructions |
AI Agent
Autonomous task execution with built-in tools. The agent plans, calls tools, observes results, and iterates until the task is complete. Built-in tools: calculator, datetime_now, text_transform, json_extract.
Submit a task for the AI agent to execute autonomously using tool calling.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
task | string | Yes | Task description |
Response
{
"result": "The answer is 15.",
"tools_available": ["calculator", "datetime_now", "text_transform", "json_extract"]
}
Return the agent's conversation and tool-use history.
Clear the agent's conversation history.
Image Intelligence
Describe images, answer visual questions with GPT-4 Vision, and generate images from text prompts with DALL-E 3. Supports PNG, JPEG, GIF, and WebP formats.
Describe an uploaded image using OpenAI Vision.
Request
multipart/form-data with a file field.
Response
{"description": "A sunset over a mountain range..."}
Answer a specific question about an uploaded image.
Request
multipart/form-data with file and question fields.
Generate an image from a text prompt using DALL-E 3.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Image description |
size | string | No | 1024x1024, 1024x1792, or 1792x1024 |
quality | string | No | standard or hd |
Response
{"url": "https://oaidalleapi...", "prompt": "A cat wearing a top hat"}
Document Generation
Transform text into professional Word documents, PowerPoint presentations, and PDF files β ready for download. Uses python-docx, python-pptx, and fpdf2.
Generate a Word document (.docx) from text. Returns binary file download.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Document content |
title | string | No | Document title |
Generate a PowerPoint presentation (.pptx) from text. Long text is automatically split across slides.
Generate a PDF document (.pdf) from text.
Database Intelligence
Ask questions in plain English β Jamii AI translates them to SQL, executes securely, and returns human-readable answers. Features four-role row-level access control: admins see everything, employees are restricted to allowed tables, customers are filtered by their own data.
Natural-language database query with row-level access control per role.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
question | string | Yes | Question in plain English |
Response
{"answer": "There were 1,247 orders placed in February."}
Return the database schema (tables and columns).
Execute a raw SELECT or SHOW query. Admin/company role only.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
query | string | Yes | SQL SELECT or SHOW statement |
Clear the DB chatbot conversation history.
Select a working database after customer login.
List companies the user belongs to.
Select a company database by company number.
Text AI
Translate text between languages, generate summaries with configurable style, analyse sentiment with confidence scores, and extract structured data from unstructured text β all powered by GPT.
Translate text to a target language.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to translate |
target_language | string | Yes | Target language (e.g. "French") |
source_language | string | No | Source language (auto-detected if omitted) |
Response
{"translated": "Bonjour le monde", "target_language": "French"}
Summarize text with configurable style and length.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to summarize |
max_length | string | No | Target length (e.g. "100 words") |
style | string | No | Summary style (e.g. "concise", "detailed") |
Response
{"summary": "A concise summary of the input text..."}
Analyse text sentiment β returns sentiment label, confidence score, and explanation.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to analyse |
Response
{
"sentiment": "positive",
"confidence": 0.95,
"explanation": "Strong positive language detected"
}
Extract structured data from unstructured text given a schema description.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to extract from |
schema_description | string | Yes | What fields to extract (e.g. "name, email, phone") |
Response
{
"data": {"name": "Alice", "email": "alice@example.com", "phone": "555-1234"}
}
Content Moderation
Detect harmful, hateful, violent, or sexual content instantly with OpenAI's moderation model. Returns per-category flags and confidence scores for fine-grained content filtering.
Check text for harmful content using the OpenAI Moderation API.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to moderate |
Response
{
"flagged": false,
"categories": {},
"category_scores": {"violence": 0.0012, "hate": 0.0003}
}
Embeddings
Generate text embedding vectors for semantic search, clustering, and recommendation. Compute cosine similarity between any two texts. Uses OpenAI's text-embedding-3-small model.
Generate an embedding vector for a text string.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to embed |
Response
{
"embedding": [0.012, -0.034, 0.056, ...],
"dimensions": 1536
}
Compute the cosine similarity between two texts (0 to 1).
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text1 | string | Yes | First text |
text2 | string | Yes | Second text |
Response
{"text1": "cat", "text2": "kitten", "score": 0.92}
Web Intelligence
Fetch any public URL, extract its text content, and get an AI-powered summary or ask specific questions about the page. Includes SSRF protection that blocks private IPs and non-HTTP schemes.
Fetch a URL and summarize its content, or answer a specific question about it.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
url | string | Yes | Public URL to fetch (http/https only) |
question | string | No | Specific question about the page content |
Response
{
"url": "https://example.com/article",
"summary": "The article discusses..."
}
Long-term Memory
Store, semantically recall, and manage persistent memories with embedding-based search. Perfect for building context-aware AI assistants that remember user preferences and past interactions.
Store a memory with optional metadata. An embedding vector is generated automatically for semantic recall.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
content | string | Yes | Memory content to store |
metadata | object | No | Optional key-value metadata |
Response
{
"id": 0,
"content": "User prefers dark mode",
"metadata": {"category": "preferences"}
}
Recall the most relevant memories by semantic similarity to a query.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Search query |
top_k | integer | No | Max results to return (default: 5) |
Response
{
"memories": [
{"id": 0, "content": "User prefers dark mode", "metadata": {}, "score": 0.92}
],
"count": 1
}
Clear all stored memories.
Response
{"message": "All memories cleared"}
Knowledge Base
Namespace-scoped document ingestion (text & URL) with Retrieval-Augmented Generation (RAG) for AI-powered Q&A. Build custom knowledge stores for any web application.
Ingest plain text into a knowledge base namespace. Text is automatically chunked and embedded.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
namespace | string | Yes | Knowledge base name (e.g. your app name) |
text | string | Yes | Text content to ingest |
source | string | No | Optional source label (e.g. filename) |
Response
{"namespace": "my-app", "chunks_added": 3, "source": "faq.md"}
Fetch a URL, extract text, chunk, embed, and store into a knowledge base. SSRF-protected.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
namespace | string | Yes | Knowledge base name |
url | string | Yes | Public URL to fetch (http/https only) |
Response
{"namespace": "my-app", "chunks_added": 12, "source": "https://example.com/faq"}
Query a knowledge base with a question. Uses RAG to find relevant chunks and generate an answer.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
namespace | string | Yes | Knowledge base to search |
question | string | Yes | Question to answer |
top_k | integer | No | Max context chunks (default 5, max 20) |
Response
{"answer": "Returns are accepted within 30 days.", "sources": ["faq.md"], "namespace": "my-app"}
List all knowledge base namespaces with their chunk counts.
Response
{"knowledge_bases": [{"namespace": "my-app", "chunks": 15}]}
Clear all documents from a knowledge base namespace.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
namespace | string | Yes | Knowledge base to clear |
Response
{"message": "Knowledge base 'my-app' cleared."}
Africa Lang
African language translation & detection, voice STT/TTS with language hints, context-aware chat about African topics, content moderation for African languages, and supported-language listing.
Translate text between African languages (Swahili, Yoruba, Hausa, Amharic, Wolof, Lingala, Zulu, and more).
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to translate |
target_language | string | Yes | Target language (e.g. "Swahili") |
source_language | string | No | Source language hint |
Response
{"translated": "Habari, u hali gani?", "target_language": "Swahili"}
Detect which African language a text is written in.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to identify |
Response
{"language": "Swahili", "confidence": 0.95, "script": "Latin", "region": "East Africa"}
List all supported African languages.
Response
{"languages": ["Swahili", "Yoruba", "Hausa", "Amharic", "Wolof", "Lingala", "Zulu", "..."]}
Transcribe audio with African language support. Send audio as multipart form data with an optional language hint (ISO-639-1).
Form Fields
| Field | Type | Required | Description |
|---|---|---|---|
file | file | Yes | Audio file (mp3, wav, webm) |
language | string | No | ISO-639-1 code (e.g. "sw", "yo", "ha") |
Response
{"text": "Habari yako"}
Convert African language text to speech. Returns audio/mpeg bytes.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Text to synthesize |
Chat with an AI knowledgeable about African geography, history, cultures, economics, and current affairs.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Question about Africa |
Response
{"response": "Kenya's main exports include tea, coffee, horticultural products, and textiles..."}
Clear the African context chat conversation history.
Response
{"message": "African chat history cleared."}
Moderate content in African languages, detecting hate speech, tribalism, and misinformation.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to check |
Response
{"flagged": false, "reason": "", "language_detected": "Swahili", "categories": {"hate_speech": false, "tribalism": false, "misinformation": false, "violence": false, "discrimination": false}}
Africa Life
African currency formatting & conversion, mobile money transaction parsing (M-Pesa, MTN MoMo, Orange Money), agriculture advisory, education & exam prep, and legal & business regulatory guidance.
Format an amount in an African currency (CFA, Naira, Shilling, Rand, Cedi, etc.).
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
amount | float | Yes | Numeric amount |
currency_code | string | Yes | ISO currency code (e.g. "KES") |
Response
{"formatted": "KSh 1,500.50", "currency_code": "KES", "currency_name": "Kenyan Shilling", "amount": 1500.5}
Estimate conversion between African currencies.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
amount | float | Yes | Amount to convert |
source_currency | string | Yes | Source ISO code |
target_currency | string | Yes | Target ISO code |
Response
{"source_amount": 1000, "source_currency": "KES", "target_amount": 3150, "target_currency": "NGN", "rate": 3.15, "note": "Approximate rate"}
List all supported African currencies.
Response
{"currencies": {"KES": "Kenyan Shilling", "NGN": "Nigerian Naira", "ZAR": "South African Rand", "...": "..."}}
Ask a question about mobile money services (M-Pesa, MTN MoMo, Orange Money, Airtel Money, EcoCash).
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
question | string | Yes | Question about mobile money |
Response
{"response": "To send money via M-Pesa, dial *334# and follow the prompts..."}
Parse a mobile money transaction message or USSD code into structured data.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Transaction SMS or USSD code |
Response
{"provider": "M-Pesa", "transaction_type": "send", "amount": 500, "currency": "KES", "recipient": "+254712345678", "reference": "QH45G7Z2", "status": "completed", "raw_text": "Confirmed. Ksh500 sent to +254712345678"}
Ask about African farming, crops, livestock, and agricultural practices.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
question | string | Yes | Agriculture question |
Response
{"response": "Cassava is one of the most important crops in Sub-Saharan Africa..."}
Ask education and exam prep questions for African educational systems (WAEC, JAMB, KCSE, BaccalaurΓ©at).
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
question | string | Yes | Study or exam question |
exam_system | string | No | Target exam system (e.g. WAEC, KCSE) |
Response
{"response": "In the WAEC Biology syllabus, photosynthesis is..."}
Ask about African business law and regulatory guidance.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
question | string | Yes | Legal or regulatory question |
country | string | No | Country context (e.g. Nigeria, Kenya) |
Response
{"response": "In Nigeria, the Companies and Allied Matters Act (CAMA) requires..."}
Africa Culture
African proverbs & wisdom by theme or culture, and storytelling β folktales, legends, and folklore from across the continent.
Get an African proverb by theme or culture.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
theme | string | No | Topic (e.g. wisdom, patience, unity) |
culture | string | No | Culture or ethnic group |
Response
{"proverb": "If you want to go fast, go alone...", "language": "Igbo", "culture": "Igbo", "meaning": "...", "theme": "unity"}
Tell an African folktale, legend, or story based on a topic or character.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
topic | string | Yes | Story topic or character |
culture | string | No | Cultural context |
Response
{"story": "Long ago, in the land of the Ashanti..."}
Streaming (SSE)
Real-time token-by-token streaming of chat responses via Server-Sent Events. Ideal for building responsive chat UIs that display text as it's generated.
Stream a chat response token by token. Returns text/event-stream.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Message to send |
Response (SSE stream)
data: Once
data: upon
data: a
data: time
data: [DONE]
Batch Processing
Process multiple chat messages in a single API call. Each message is processed independently β the chatbot is reset between messages so there's no cross-contamination of context.
Send multiple messages and receive individual responses for each.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
messages | array of strings | Yes | List of messages (min 1) |
Response
{
"results": ["Answer to first...", "Answer to second..."],
"count": 2
}
Authentication Endpoints
Four-role JWT authentication with row-level access control. Admins, companies, employees, and customers each get tailored access. All credentials use the customers_credential table with case-insensitive secret_answer matching.
Customer login β validates against customers_credential + customers, requires is_verified = 'yes'.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
username | string | Yes | Username (userN) |
secret_answer | string | Yes | Secret answer (case-insensitive) |
Response
{
"access_token": "eyJhbGciOi...",
"token_type": "bearer",
"role": "customer",
"firstname": "Alice"
}
Admin login β requires company_employee_links.is_admin = 1 and status = 1.
Employee login β requires company_employee_links.status = 1. JWT includes allow_tables_list.
Company login β requires customers.type = 'webcompany'. Same access rights as admin.
Get API usage statistics for the currently authenticated user.
System
System-level endpoints for health checks and monitoring.
Health check β returns API status and version. No authentication required.
Response
{"status": "ok", "version": "0.1.0"}