graphlife Docs graphlife.app

Graph data

8. Asking a question

POST/v1/ask

Retrieves the relevant part of a graph and returns an answer with citations. Accepted credentials are the same as for the live endpoint, and the credential needs search and subgraph. Passages of prose are searched and quoted only when the scope also includes search_prose and does not redact text. The same operation is available as the live operation ask, where the response is wrapped in {"result": …}. It is not offered over MCP.

Request body:

Field Type Default Description
q string — The question. Required, at most 2,000 characters.
graph string — Required when the credential reaches more than one graph.
asOf string — Answer as of a date (YYYY, YYYY-MM, YYYY-MM-DD).
strict boolean false With asOf: ignore relationships whose start date is unknown.
maxTokens integer 2000 Size of the retrieved context, clamped to 500–6000.

Response 200:

{
  "answer": "Acme Srl [n1] signed the supply contract [e1] on 3 March 2026.",
  "llm": true,
  "sources": [
    { "marker": "n1", "id": "…", "kind": "node", "label": "Acme Srl" },
    { "marker": "e1", "id": "…", "kind": "edge", "label": "Acme Srl signed Supply contract 2026" }
  ],
  "conflicts": [],
  "truncated": false
}
Field Description
answer The answer text. Bracketed markers such as [n1] refer to entries in sources.
llm true when a language model wrote the answer. false when the answer is extractive: the retrieved facts themselves, with no model involved.
reason Present when llm is false for a reason: server_ai_off, no_model, budget, or llm_unavailable.
sources One entry per marker cited, in order of first use. kind is node, edge or passage.
conflicts Facts the graph records in two contradictory versions.
asOf Echoed when it was sent.
truncated true when more matched than fitted in the context.

A language model is used only when all of the following hold. Otherwise the answer is extractive and no graph content leaves the server.

  1. The graph's owner has turned server-side AI on for this graph (serverAi, section 3.3). It is off by default.
  2. A model key is available: either the organisation's own key, or the operator's key in the ANTHROPIC_API_KEY environment variable together with a positive LLM_MONTHLY_TOKENS budget. With LLM_MONTHLY_TOKENS unset, the operator's key is never used.
  3. When the operator's key is used, the monthly budget is not exhausted.

The model provider is Anthropic: the server calls the Anthropic Messages API at its public address, so it needs outbound HTTPS access to that API for model answers. An operator can also set LOCAL_LLM_BASE_URL to an OpenAI-compatible model server of its own: questions then go to that server first, and to the Anthropic key only when it cannot answer. A model key (rule 2) is required in either case. The model can be chosen with the ASK_MODEL environment variable. A model answer is limited to 1,024 output tokens. Storing an organisation's own key requires the SECRET_KEY environment variable to be set on the server to a base64-encoded 32-byte value.

Errors: the common live errors in section 5.3, plus 400 bad_request (empty or over-long q, invalid asOf) and 429 rate_limited (20 questions per 60 seconds per credential). If an organisation's stored model key can no longer be decrypted, the call fails with 500 internal rather than falling back to an extractive answer.

The answer is returned in one response; it is not streamed. The server keeps no conversation state between calls: each question is answered on its own.

curl -s https://graphlife.example.com/v1/ask \
  -H "Authorization: Bearer $GRAPHLIFE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q": "Who signed the 2026 supply contract?"}'