Skip to main content

POST /api/query

Query the Bhagavad Gita with natural language questions. This endpoint uses semantic search to find the most relevant verse and generates contextual commentary tailored to your specific question.

Request

query
string
required
The user’s question or search query. Must be 1-500 characters.

Request Body Example

{
  "query": "How do I overcome fear and anxiety?"
}

Response

Returns a verse with contextual commentary addressing the user’s question.
chapter
integer
Chapter number (1-18)
verse
integer
Verse number within the chapter
translation
string
English translation of the verse
summarized_commentary
string
AI-generated contextual commentary that addresses the user’s specific question
full_commentary
string
Complete traditional commentary on the verse

Response Example

{
  "chapter": 2,
  "verse": 47,
  "translation": "You have the right to perform your prescribed duties, but you are not entitled to the fruits of your actions. Never consider yourself to be the cause of the results of your activities, nor be attached to inaction.",
  "summarized_commentary": "When facing fear and anxiety, focus on your actions rather than worrying about outcomes. The Gita teaches that we should perform our duties without attachment to results, which reduces anxiety about success or failure.",
  "full_commentary": "..."
}

Error Responses

error
string
Error message describing what went wrong
Status CodeDescription
400Invalid request - query is missing, empty, or too long (>500 characters)
404No matching verses found
429Rate limit exceeded (20 requests per minute)
500Internal server error
504Request timeout (>30 seconds)

Rate Limiting

  • Frontend: 20 requests per minute per client
  • Backend: 30 requests per minute per IP address

Code Examples

curl -X POST https://gitachat.org/api/query \
  -H "Content-Type: application/json" \
  -d '{
    "query": "How do I overcome fear and anxiety?"
  }'

Notes

  • Query results are automatically saved to the authenticated user’s history
  • The contextual commentary is generated using AI to address the specific question
  • If AI commentary generation fails, the endpoint falls back to pre-computed summaries
  • Queries are trimmed of whitespace before processing

Build docs developers (and LLMs) love