Repository navigation
API Reference
Interactive docs (Swagger UI) are served at /docs and the OpenAPI schema at /openapi.json. Routes have no prefix.
- No authentication. CORS allows every origin, method and header. Put the service behind an authenticating proxy before exposing it (Operations and Troubleshooting).
-
X-Session-IDrequest header (optional): stored with the logged interaction. The column holds 36 characters. -
X-Process-Timeresponse header: server processing time. - Validation errors return HTTP 422 in FastAPI's standard shape.
- Model failures do not return an error status. If the language model call fails, the endpoint returns a fallback body with HTTP 200 and logs the error. A client can only tell by the content (Known Issues and Limitations).
- Input text is trimmed and lower-cased before use.
Answer a nutrition question from the knowledge base.
Request:
{ "user_query": "What are good sources of iron for a toddler?" }user_query must be at least 1 character.
Response (HTTP 200):
{
"status": "success",
"message": "Query processed successfully",
"data": {
"original_query": "What are good sources of iron for a toddler?",
"processed_query": "what are good sources of iron for a toddler?",
"retrieved_context": [
{ "text": "...", "source": "<document file name>", "authority": "<publisher>", "domain": "nutrition" }
],
"generated_response": "Iron-rich foods include ... [1]"
}
}-
retrieved_contextholds the top 3 chunks after re-ranking. It is empty for small talk. -
generated_responsecites the chunks inline as[1],[2], matching the order ofretrieved_context. -
Small talk shortcut: if the lower-cased query contains any of
hello, hi, hey, who are you, what are you, what can you do, help, thanks, thank you, bye, goodbye, retrieval is skipped and the easy tier answers. This is a substring match, so it also fires on words that containhi(for example "which") orhelp(Known Issues and Limitations). -
Not returned: the route computes
citations_present, but the response model does not include it, so it is dropped from the response. It is stored in the log database. - Not returned: the grounding score. Verification runs after the response is sent and is only logged (Grounding Verification).
A short lesson as 4-5 "beats" for the robot: what to say, which gesture to make and what to show on the tablet.
Request:
{ "concept": "iron deficiency in children" }concept is 2-200 characters. Retrieval uses the top 6 chunks.
Response data:
{
"concept": "...",
"total_beats": 5,
"beats": [
{
"beat_number": 1,
"type": "introduction",
"speech": "Plain text for text-to-speech, no symbols or markdown",
"gesture": "welcoming",
"tablet": { "display_type": "key_fact", "heading": "...", "body": "..." }
}
],
"sources": ["<document file name>"]
}| Field | Allowed values |
|---|---|
type |
introduction, kenyan_context, key_facts, safety_tip, practical_advice, quiz
|
gesture |
explaining, pointing_tablet, tip_gesture, warning_gesture, thinking, welcoming
|
tablet.display_type |
key_fact (heading, body), food_list (heading, items[]), tip (heading, body), warning (heading, body), quiz (question, options[], correct_answer) |
The route returns the raw dictionary, so these values are enforced by the prompt and by a sanitising step in the generator, not by a response model. On a model or JSON error the endpoint returns a single-beat fallback lesson.
A long-form narrative lesson.
Request:
{
"concept": "balanced diet",
"description": "Focus on school-age children aged 6 to 12 in rural Kenya"
}concept is 2-200 characters. description is optional, 5-1000 characters, and steers audience and focus. Retrieval uses the top 10 chunks. The description is passed to the model as additional guidance, so treat it as untrusted text (Prompts and Lessons).
Response data:
{
"concept": "balanced diet",
"lesson_text": "...",
"quiz_hints": ["...", "..."],
"sources": ["<document file name>"]
}On a model or JSON error the endpoint returns a short fallback lesson.
curl -s -X POST http://127.0.0.1:8000/learn/structured \
-H 'Content-Type: application/json' -H 'X-Session-ID: demo-1' \
-d '{"concept": "food safety when storing leftovers"}'
curl -s -X POST http://127.0.0.1:8000/learn/text \
-H 'Content-Type: application/json' \
-d '{"concept": "balanced diet", "description": "for primary school children"}'Expect /query to take several seconds and the lesson endpoints tens of seconds, dominated by the language model (Evaluation has historical figures).
Documentation last verified against the code on 2026-11-05. Evaluation figures are historical, see Evaluation. Educational tool, not medical advice.
Use it
How it works
- Architecture
- Retrieval Pipeline
- LLM Layer
- Prompts and Lessons
- Grounding Verification
- Knowledge Base
- Data and Logging
Quality
Develop