RAGIFY
/Docs
developer mode
Audience: developerRead Time: 4 minStatus: built

Quickstart

Quickstart

Last verified against: commit 6f2f20b (v1.0)
Estimated Read Time: 4 min
Status: built

This guide demonstrates how to integrate with the Locus public chat endpoint using HTTP requests. You can authenticate either server-side using a secret API key or client-side (in browsers and mobile webviews) using a publishable key exchanged for a short-lived session token.


1. Authentication Modes

Locus provides two key kinds:

  • Publishable Key (locus_pk_...): Used in client-side applications. It cannot call /v1/chat directly; it must be exchanged at POST /v1/session with an allowed Origin header.
  • Secret Key (locus_sk_...): Used exclusively in backend environments. Passed directly as a Bearer token in the Authorization header to /v1/chat.

2. Client-Side Flow: Session Token Exchange

In web browsers, exchange your publishable key for a short-lived chat session token valid for 1 hour (3600 seconds).

# 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"}'
import httpx

resp = httpx.post(
    "http://127.0.0.1:8000/v1/session",
    headers={"Origin": "http://localhost:3000"},
    json={"publishable_key": "locus_pk_REPLACE_ME"}
)
session_token = resp.json()["session_token"]
print("Acquired session token:", session_token)
const response = await fetch("http://127.0.0.1:8000/v1/session", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Origin": "http://localhost:3000",
  },
  body: JSON.stringify({ publishable_key: "locus_pk_REPLACE_ME" }),
});
const data = await response.json();
const sessionToken = data.session_token;

Response (HTTP 200 OK):

{
  "session_token": "locus_cs_EXAMPLE_TOKEN_STRING",
  "expires_at": "2026-11-19T17:00:00Z",
  "remaining_rpm": 59
}

3. Querying the Chat Endpoint

Submit a query to an assistant bound to your knowledge spaces. The endpoint accepts either a session token or a secret key.

# 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": "support-bot",
    "message": "What are the available subscription plans?"
  }'
import httpx

headers = {
    "Authorization": "Bearer locus_cs_REPLACE_ME",
    "Content-Type": "application/json"
}
payload = {
    "assistant_slug": "support-bot",
    "message": "What are the available subscription plans?"
}
response = httpx.post("http://127.0.0.1:8000/v1/chat", headers=headers, json=payload)
data = response.json()
print("Answer:", data["answer"])
print("Citations:", data["citations"])
const chatRes = await fetch("http://127.0.0.1:8000/v1/chat", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer locus_cs_REPLACE_ME",
  },
  body: JSON.stringify({
    assistant_slug: "support-bot",
    message: "What are the available subscription plans?",
  }),
});
const result = await chatRes.json();
console.log(result.answer);

Response (HTTP 200 OK):

{
  "answer": "We offer Free, Pro, and Team plans.",
  "citations": [
    {"source_id": 12, "chunk_id": 44, "label": "pricing.md"}
  ],
  "latency_ms": 142.5
}

4. Error Handling and Status Codes

The API returns standard HTTP status codes:

HTTP StatusReasonRemedy
401 UnauthorizedInvalid, missing, or expired tokenEnsure Authorization: Bearer ... header is populated with an active token
403 ForbiddenPublishable key used directly on /v1/chat, origin mismatch, or assistant is not marked publicExchange publishable key at /v1/session first; check allowed origins
404 Not FoundAssistant slug not found in tenant spaceVerify the assistant slug in your Locus console
429 Too Many RequestsExceeded rate limit (Default 60 RPM)Back off until the sliding window resets

5. Checking Current Rate Limits

To check your remaining quota programmatically:

# Run in terminal
curl -X GET http://127.0.0.1:8000/v1/limits \
  -H "Authorization: Bearer locus_cs_REPLACE_ME"

Response (HTTP 200 OK):

{
  "remaining_rpm": 58,
  "limit_rpm": 60,
  "reset_in_seconds": 42
}
Checked against build git-rev-quickstart
Truth Audit Specification Validated