{"openapi":"3.0.3","info":{"title":"Jasika AI - Product of MSM Classes","description":"Interactive API documentation for Jasika AI, a premium virtual educational tutor and assistant by MSM Classes (Maa Saraswati Mentors Education) and part of msmedu. Exposes endpoints for chat tutoring (completions), image/SVG vector art generation, document indexing/retrieval (semantic RAG), translation, summarization, and sentiment analysis.","version":"2.0.0","contact":{"name":"MSM Classes Support","url":"https://msmclass.in","email":"support@msmclass.in"}},"servers":[{"url":"https://ai.msmclass.in","description":"Production Server"},{"url":"https://staging-ai.msmclass.in","description":"Staging Server"},{"url":"http://localhost:8787","description":"Local Development Server"}],"paths":{"/api/v1/chat/completions":{"post":{"summary":"V1 Chat Completions","description":"Standard chat completion endpoint. Supports text chat, vision input (images in base64/URL), and basic keyword-based RAG.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionsRequest"}},"multipart/form-data":{"schema":{"$ref":"#/components/schemas/MultipartCompletionsRequest"}}}},"parameters":[{"name":"cf-timezone","in":"header","required":false,"description":"User timezone (e.g. Asia/Kolkata) to align date/time awareness.","schema":{"type":"string","default":"Asia/Kolkata"}},{"name":"cf-region","in":"header","required":false,"description":"User region (e.g. Delhi) to adapt context.","schema":{"type":"string","default":"Delhi/NCR"}},{"name":"accept-language","in":"header","required":false,"description":"User preferred language.","schema":{"type":"string","default":"en-IN"}}],"responses":{"200":{"description":"Successful response matching OpenAI completions format.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionsResponse"}}}}}}},"/api/v1/images/generations":{"post":{"summary":"V1 Image Generation","description":"Creates an image based on a prompt. Routed via Cloudflare AI Gateway compatibility.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["prompt"],"properties":{"prompt":{"type":"string","description":"Text description of the image to generate.","maxLength":4000},"model":{"type":"string","default":"dall-e-3"},"n":{"type":"integer","default":1},"size":{"type":"string","enum":["256x256","512x512","1024x1024"],"default":"1024x1024"}}}}}},"responses":{"200":{"description":"Generated image URLs.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"url":{"type":"string"}}}}}}}}}}}},"/api/v1/rag/upload":{"post":{"summary":"Upload RAG Document","description":"Uploads and indexes a document for RAG search. Supported types: PDF, DOCX, XLSX, JSON, CSV, TXT, images (tagged via Resnet), audio (transcribed via Whisper).","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["file"],"properties":{"file":{"type":"string","format":"binary","description":"Document/Audio/Image file to upload (Max 20MB)."}}}}}},"responses":{"200":{"description":"Document uploaded and indexed successfully.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"docId":{"type":"string"},"filename":{"type":"string"},"chunkCount":{"type":"integer"},"keywords":{"type":"array","items":{"type":"string"}}}}}}}}}},"/api/v1/rag/documents":{"get":{"summary":"List Uploaded Documents","description":"Retrieves metadata and status of all indexed documents in the KV storage.","security":[{"BearerAuth":[]}],"responses":{"200":{"description":"List of documents.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"documents":{"type":"array","items":{"type":"object","properties":{"docId":{"type":"string"},"filename":{"type":"string"},"uploadedAt":{"type":"string"}}}}}}}}}}}},"/api/v1/rag/documents/{docId}":{"delete":{"summary":"Delete Document","description":"Deletes the metadata and all associated chunks of an indexed document from KV storage.","security":[{"BearerAuth":[]}],"parameters":[{"name":"docId","in":"path","required":true,"description":"The unique ID of the document to delete.","schema":{"type":"string"}}],"responses":{"200":{"description":"Document deleted successfully.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"}}}}}}}}},"/api/v2/chat/completions":{"post":{"summary":"V2 Chat Completions (Streaming & Enhancements)","description":"Enhanced V2 completions. Supports streaming responses (Server-Sent Events) and non-streaming responses. Automatically runs system prompt, timezone, region, and real-time context injections.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionsRequest"}},"multipart/form-data":{"schema":{"$ref":"#/components/schemas/MultipartCompletionsRequest"}}}},"parameters":[{"name":"cf-timezone","in":"header","required":false,"description":"User timezone.","schema":{"type":"string","default":"Asia/Kolkata"}},{"name":"cf-region","in":"header","required":false,"description":"User region.","schema":{"type":"string","default":"Delhi/NCR"}},{"name":"accept-language","in":"header","required":false,"description":"User preferred language.","schema":{"type":"string","default":"en-IN"}}],"responses":{"200":{"description":"Completions response. If stream=true, returns a Server-Sent Events stream of chunks.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionsResponse"}},"text/event-stream":{"description":"SSE stream. Each data chunk is an OpenAI-compatible delta chunk followed by data: [DONE]."}}}}}},"/api/v2/images/generations":{"post":{"summary":"V2 Image & SVG Generation","description":"Generates high-quality images using Cloudflare Workers AI models (SD-XL, Dreamshaper fallback) or creates SVG XML code using Llama 3.1. Features prompt enhancement, aspect ratios, and transparency modifiers.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/V2ImageRequest"}}}},"responses":{"200":{"description":"Image returned as raw binary file or base64 JSON.","content":{"image/png":{"schema":{"type":"string","format":"binary"}},"image/svg+xml":{"schema":{"type":"string","description":"Raw XML text of generated SVG graphic."}},"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"image":{"type":"string","description":"Base64 encoded data URI (e.g. data:image/png;base64,...)."},"enhanced_prompt":{"type":"string"},"model":{"type":"string"},"format":{"type":"string"}}}}}}}}},"/api/v2/auto":{"post":{"summary":"V2 All-In-One Intelligent Auto Route","description":"Intelligent gateway route. Uses AI to automatically classify the user's prompt (into image, rag, translate, summarize, sentiment, or chat intents) and dispatches it internally to the corresponding flow, returning the appropriate payload.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["prompt"],"properties":{"prompt":{"type":"string","description":"Natural language query representing any intent."},"messages":{"type":"array","items":{"type":"object"}},"stream":{"type":"boolean","default":false}}}}}},"responses":{"200":{"description":"Response matches the routed endpoint (JSON, streaming, binary, or base64 data object).","content":{"application/json":{"schema":{"type":"object"}},"image/png":{"schema":{"type":"string","format":"binary"}}}}}}},"/api/v2/ai/embeddings":{"post":{"summary":"Generate Embeddings","description":"Generates semantic embedding vector using `@cf/baai/bge-base-en-v1.5`.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["text"],"properties":{"text":{"type":"string"}}}}}},"responses":{"200":{"description":"Generated embeddings vector.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"array","items":{"type":"number"}}}}}}}}}},"/api/v2/ai/translate":{"post":{"summary":"Translate Text","description":"Translates text between languages using `@cf/meta/m2m100-1.2b`.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["text","target_lang"],"properties":{"text":{"type":"string"},"source_lang":{"type":"string","default":"en"},"target_lang":{"type":"string"}}}}}},"responses":{"200":{"description":"Translated text.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"string"}}}}}}}}},"/api/v2/ai/sentiment":{"post":{"summary":"Analyze Sentiment","description":"Analyzes sentiment of text using `@cf/huggingface/distilbert-sst-2-en`.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["text"],"properties":{"text":{"type":"string"}}}}}},"responses":{"200":{"description":"Sentiment results.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"object","properties":{"label":{"type":"string"},"score":{"type":"number"}}}}}}}}}}},"/api/v2/ai/entities":{"post":{"summary":"Extract Named Entities","description":"Extracts entities like places, names, organizations using `@cf/huggingface/ner-multilingual`.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["text"],"properties":{"text":{"type":"string"}}}}}},"responses":{"200":{"description":"Entities list.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"object","properties":{"entities":{"type":"array","items":{"type":"object"}}}}}}}}}}}},"/api/v2/ai/summarize":{"post":{"summary":"Summarize Text","description":"Creates text summary using `@cf/facebook/bart-large-cnn`.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["text"],"properties":{"text":{"type":"string"}}}}}},"responses":{"200":{"description":"Summary text.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"string"}}}}}}}}},"/api/v2/analyze/comprehensive":{"post":{"summary":"Comprehensive Analysis Pipeline","description":"Runs multiple operations (sentiment, NER, embeddings, language) on a single text in a pipeline.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["text"],"properties":{"text":{"type":"string"}}}}}},"responses":{"200":{"description":"Pipeline results.","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/api/v2/analyze/qa":{"post":{"summary":"Context-Based Question Answering","description":"Answers a specific question based on the provided context block using `@cf/deepset/roberta-base-squad2`.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["context","question"],"properties":{"context":{"type":"string"},"question":{"type":"string"}}}}}},"responses":{"200":{"description":"QA Answer.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"object","properties":{"answer":{"type":"string"},"score":{"type":"number"}}}}}}}}}}},"/api/v2/rag-enhanced/search":{"post":{"summary":"Enhanced RAG Search","description":"Performs semantic RAG retrieval from KV stores using parallelized searches and cosine similarity vectors.","security":[{"BearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["query"],"properties":{"query":{"type":"string"},"enhance_with":{"type":"array","items":{"type":"string"}}}}}}},"responses":{"200":{"description":"Retrieved document chunks.","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/api/v2/docs":{"get":{"summary":"Get V2 Route Catalog","description":"Lists all available features, endpoint mappings, and migration paths for the V2 API catalog.","responses":{"200":{"description":"V2 API metadata and descriptions.","content":{"application/json":{"schema":{"type":"object"}}}}}}}},"components":{"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","description":"Use your authentication token to access API routes."}},"schemas":{"ChatCompletionsRequest":{"type":"object","required":["model","messages"],"properties":{"model":{"type":"string","description":"The AI model to use (e.g. gpt-4, claude-3)."},"messages":{"type":"array","items":{"$ref":"#/components/schemas/Message"}},"stream":{"type":"boolean","default":false},"use_rag":{"type":"boolean","default":false,"description":"If true, retrieves relevant context from uploaded documents."},"rag_query":{"type":"string","description":"The query string to search for documents (required if use_rag is true)."},"rag_limit":{"type":"integer","default":5}}},"MultipartCompletionsRequest":{"type":"object","required":["messages"],"properties":{"messages":{"type":"string","description":"JSON-stringified array of Messages (e.g., '[{\"role\":\"user\",\"content\":\"hello\"}]')."},"model":{"type":"string","default":"gpt-4"},"stream":{"type":"boolean","default":false},"file":{"type":"string","format":"binary","description":"Inline file attachment (PDF/DOCX/Audio/Image). Contents are parsed and attached to messages."}}},"Message":{"type":"object","required":["role","content"],"properties":{"role":{"type":"string","enum":["system","user","assistant"]},"content":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"object"}}]}}},"ChatCompletionsResponse":{"type":"object","properties":{"id":{"type":"string"},"object":{"type":"string"},"created":{"type":"integer"},"model":{"type":"string"},"choices":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"message":{"$ref":"#/components/schemas/Message"},"finish_reason":{"type":"string"}}}}}},"V2ImageRequest":{"type":"object","required":["prompt"],"properties":{"prompt":{"type":"string","description":"Description of the image to generate."},"aspect_ratio":{"type":"string","enum":["1:1","16:9","9:16","4:3","3:4"],"default":"1:1"},"extension":{"type":"string","enum":["png","jpg","webp","svg"],"default":"png"},"transparent":{"type":"boolean","default":false,"description":"If true, modifies prompt to generate a transparent/isolated background."},"response_format":{"type":"string","enum":["binary","base64"],"default":"binary","description":"Select output: binary image stream or base64 JSON wrapper."}}}}}}