API reference

Query a knowledge base from your own application over HTTP.

Any knowledge base can be queried from your own application. The knowledge base id (hb-...) goes in dataset_ids: it selects what is searched and it authorizes the read, so a chat or retrieval call needs no header and no token. The id is on the knowledge base's page and on the API panel in Chat & Search, with the request below pre-filled. Keep it server-side, out of client bundles and out of version control, and out of a URL, and regenerate it from the knowledge base page if it is ever exposed, see Knowledge bases.

Shared knowledge bases

A share recipient is issued a scoped id instead of the dataset's own. It works the same way in dataset_ids and resolves to only what their department was granted.

Ask a question

Shell
curl -s -X POST https://brain.humains.one/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{"query": "your question", "dataset_ids": ["hb-..."]}'

The response carries the answer and the sources it was built from. Optional fields include top_k, rerank, temperature, max_tokens, reasoning_effort (off, low, medium, high, auto), a prompt to override the system prompt for this call, conversation_history for multi-turn context, and document_ids or filenames to narrow a query to specific documents within the knowledge base.

Requiring a key

A retrieval key exists per knowledge base and is still accepted in the X-Dataset-Key header. A deployment that wants it mandatory, so an id alone is refused, sets REQUIRE_DATASET_KEY=1 on the API and restarts. Callers then send:

Shell
curl -s -X POST https://brain.humains.one/api/v1/chat \
  -H "Content-Type: application/json" \
  -H "X-Dataset-Key: <retrieval key>" \
  -d '{"query": "your question", "dataset_ids": ["hb-..."]}'

Stream a response

POST /chat/stream returns the same answer as server-sent events: a meta event with retrieval timing and sources, a ttft event marking time to the first token, one token event per piece of generated text, and a done event with the total time. Use it when the answer is being displayed as it is written.

POST /chat-raw streams just the answer text with no event envelope, for external integrations that want plain text token by token.

Retrieve without generating

POST /retrieval returns the matching chunks and skips the language model entirely. Use it to feed your own prompt, to build a search experience, or to inspect what retrieval is actually finding.

Shell
curl -s -X POST https://brain.humains.one/api/v1/retrieval \
  -H "Content-Type: application/json" \
  -d '{"query": "your question", "dataset_ids": ["hb-..."], "top_k": 5}'

Common endpoints

EndpointPurpose
POST /chat
Answer a question from one or more knowledge bases.
POST /chat/stream
The same, streamed as server-sent events.
POST /chat-raw
The same, streamed as plain text with no event envelope.
POST /retrieval
Return matching passages only, with no generated answer.
GET /datasets
List knowledge bases. Requires a bearer token.
POST /datasets/{id}/documents
Upload a document. Requires a bearer token.
GET /health
Service health. No authentication.

Management calls

Everything that changes the account, creating knowledge bases, uploading, managing members, authenticates with a bearer token from sign-in rather than with a knowledge base id.

Shell
curl -s https://brain.humains.one/api/v1/datasets \
  -H "Authorization: Bearer <access token>"

Error responses

StatusMeaning
401
Missing or expired bearer token on a management call. Chat and retrieval need no token, unless nothing was asked at all with no knowledge base selected.
402
The organization has no active plan, an inactive plan, or no remaining token balance. The response body names which.
403
Authenticated, but not permitted for this organization or department.
404
No such knowledge base or document, or it is not visible to you.
410
The knowledge base id was regenerated. Fetch the current id.
429
Rate limited, either the plan's request limit or, for an unauthenticated call, this deployment's anonymous rate limit. A Retry-After header says how long to wait.
502
The configured AI provider itself returned an error.