Skip to content

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
// later
await handle.close();

Options: host (default 127.0.0.1), port (default 8085), llm, bearerToken, requestLogging. DocumentCollection.serve() takes the same options.

The llm defaults to the document’s. Without one, /ask returns 503 AskDisabled.

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
  • topK is 1 to 50. mode is vector, keyword or hybrid.
  • filter is a metadata filter, such as { "page": { "gte": 3 } }. An invalid one gets 400 with { "error": "ConfigError", "message": ... }.
  • A rerank default set on the document or collection applies to both endpoints.
  • With a bearer token set, send Authorization: Bearer <token>. A missing or wrong token gets 401.
  • An invalid body gets 400 with { "error": "ValidationError", "details": ... }.
Terminal window
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 arrives
curl -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}'
Terminal window
raglite serve ./docs --llm-provider openai --port 8085 --token "$RAGLITE_TOKEN"

See CLI.