Public API Reference
Last verified against: commit 6f2f20b (v1.0)
Estimated Read Time: 5 min
Status: built
This page details the four public HTTP endpoints exposed by Locus for client and backend integration. The schema corresponds to the exported specification in docs/public_openapi.json.
1. POST /v1/session
Exchange a browser-visible publishable key (locus_pk_...) for a short-lived chat session token (locus_cs_...).
Request Headers
Content-Type: application/jsonOrigin: <client-origin>(Required: validated againstallowed_originsassigned to the key)
Request Body
{ "publishable_key": "locus_pk_REPLACE_ME" }
Response (200 OK)
{ "session_token": "locus_cs_EXAMPLE_SESSION_TOKEN", "expires_at": "2026-11-19T17:00:00.000000Z", "remaining_rpm": 59 }
Response Status Codes
200 OK: Session successfully issued.401 Unauthorized: Publishable key is invalid or formatted incorrectly.403 Forbidden: RequestOriginheader does not match the key's allowed origin list.429 Too Many Requests: Publishable key rate limit exceeded.
# Run in terminal curl -X POST http://127.0.0.1:8000/v1/session \ -H "Content-Type: application/json" \ -H "Origin: http://localhost:3000" \ -d '{"publishable_key": "locus_pk_REPLACE_ME"}'
2. POST /v1/chat
Execute a retrieval-augmented generation query against a designated assistant.
Request Headers
Content-Type: application/jsonAuthorization: Bearer <token>(Accepts either a session tokenlocus_cs_...or a secret keylocus_sk_...)X-Locus-User-Token: <jwt>(Optional: end-user identity token for row-scoped tables)
Request Body
{ "assistant_slug": "knowledge-bot", "message": "Summarize the customer onboarding policy.", "stream": false }
Response (200 OK - JSON Mode)
{ "answer": "The customer onboarding policy requires step 1...", "citations": [ { "source_id": 10, "chunk_id": 88, "label": "policy_doc.pdf", "score": 0.82 } ], "latency_ms": 165.2 }
Server-Sent Events (stream: true)
When stream: true is passed, the endpoint returns text/event-stream chunks:
data: {"delta": "The"}
data: {"delta": " customer"}
data: {"delta": " onboarding"}
data: [DONE]
Response Status Codes
200 OK: Query processed.401 Unauthorized: Token missing, expired, or invalid.403 Forbidden:locus_pk_passed directly without session exchange, or the assistant is private.404 Not Found: Assistant slug does not exist in the tenant workspace.429 Too Many Requests: Rate limit reached.
# Run in terminal curl -X POST http://127.0.0.1:8000/v1/chat \ -H "Content-Type: application/json" \ -H "Authorization: Bearer locus_cs_REPLACE_ME" \ -d '{"assistant_slug": "knowledge-bot", "message": "Summarize policy"}'
3. GET /v1/limits
Inspect the rate limit usage and remaining quota for the authenticated key or session.
Request Headers
Authorization: Bearer <token>(Accepts session token or secret key)
Response (200 OK)
{ "remaining_rpm": 57, "limit_rpm": 60, "reset_in_seconds": 38 }
# Run in terminal curl -X GET http://127.0.0.1:8000/v1/limits \ -H "Authorization: Bearer locus_cs_REPLACE_ME"
4. POST /v1/hosted/{slug}/chat
Unauthenticated public hosted chat endpoint for embeddable widgets, bounded by assistant slug and client IP rate limiting (15 RPM).
Path Parameters
slug(string): The unique URL slug of the public assistant.
Request Body
{ "message": "Hello, how do I register?" }
Response (200 OK)
{ "answer": "You can register by navigating to the signup page.", "citations": [], "latency_ms": 110.0 }
Response Status Codes
200 OK: Query answered.404 Not Found: Assistant not found or not marked public.429 Too Many Requests: Hosted visitor IP rate limit exceeded (15 RPM).
# Run in terminal curl -X POST http://127.0.0.1:8000/v1/hosted/support-bot/chat \ -H "Content-Type: application/json" \ -d '{"message": "Hello"}'