REST API
serve() starts an HTTP server over a document or collection: Hono in TypeScript, FastAPI in Python. Both have the same endpoints and responses.
await doc.build();
const handle = await doc.serve({ port: 8085, llm: { provider: "openai" }, bearerToken: process.env.RAGLITE_TOKEN,});console.log(handle.url); // http://127.0.0.1:8085
// laterawait handle.close();Options: host (default 127.0.0.1), port (default 8085), llm, bearerToken, requestLogging. DocumentCollection.serve() takes the same options.
doc.build()
handle = doc.serve({"llm": {"provider": "openai"}}, port=8085, bearer_token=os.environ["RAGLITE_TOKEN"])print(handle.url) # http://127.0.0.1:8085
# laterhandle.close()Document.serve() runs the server in a background thread and returns. DocumentCollection.serve() blocks until stopped:
collection.serve(host="127.0.0.1", port=8085, bearer_token=os.environ["RAGLITE_TOKEN"], llm={"provider": "openai"})The llm defaults to the document’s. Without one, /ask returns 503 AskDisabled.
Endpoints
Section titled “Endpoints”| Method | Path | Auth | Body | Returns |
|---|---|---|---|---|
GET |
/health |
No | — | { status, version, chunks, namespace? } |
GET |
/info |
Yes | — | Chunk size, overlap, topK, retrieval mode, embedding provider and model, LLM provider, chunk count |
POST |
/search |
Yes | { query, topK?, scoreThreshold?, mode?, filter? } |
{ results: SearchResult[] } |
POST |
/ask |
Yes | { question, topK?, scoreThreshold?, mode?, filter?, includeCitations?, stream? } |
An AnswerResult with citations, or plain text when stream is true |
topKis 1 to 50.modeisvector,keywordorhybrid.filteris a metadata filter, such as{ "page": { "gte": 3 } }. An invalid one gets400with{ "error": "ConfigError", "message": ... }.- A
rerankdefault set on the document or collection applies to both endpoints. - With a bearer token set, send
Authorization: Bearer <token>. A missing or wrong token gets401. - An invalid body gets
400with{ "error": "ValidationError", "details": ... }.
Examples
Section titled “Examples”curl http://127.0.0.1:8085/health
curl -X POST http://127.0.0.1:8085/search \ -H "Authorization: Bearer $RAGLITE_TOKEN" \ -H 'Content-Type: application/json' \ -d '{"query": "refund policy", "topK": 3}'
curl -X POST http://127.0.0.1:8085/ask \ -H "Authorization: Bearer $RAGLITE_TOKEN" \ -H 'Content-Type: application/json' \ -d '{"question": "What is the refund policy?"}'
# Streamed answer: plain text, written as it arrivescurl -N -X POST http://127.0.0.1:8085/ask \ -H "Authorization: Bearer $RAGLITE_TOKEN" \ -H 'Content-Type: application/json' \ -d '{"question": "Summarize the document", "stream": true}'From the CLI
Section titled “From the CLI”raglite serve ./docs --llm-provider openai --port 8085 --token "$RAGLITE_TOKEN"See CLI.