Skip to content
Try Free →

Ask a question with the API

POST /v1/query sends one question to your agent and returns a JSON answer grounded in your content, with the sources it was drawn from. It is synchronous: you get the whole answer in one response.

Before you start

Starter+
  • Create an API key. See API keys. The key identifies the workspace, so there is no workspace id in the body.
  • API access starts on Starter. The Free plan does not include it.
  • Every successful answer uses message credits, exactly like an answer on any other channel. Base models cost 1 credit, premium models cost more.

Endpoint

POST https://api.askvault.co/v1/query

Send Authorization: Bearer ak_xxx and Content-Type: application/json.

Request body

{
"query": "What is your refund policy?",
"session_id": "user_123",
"top_k": 8
}
  • query (required). The question, up to 4,000 characters. An empty string is rejected.
  • session_id (optional). Your key for one end user, up to 200 characters. Use a stable value per person so each user's conversation stays separate under one API key.
  • top_k (optional). How many passages from your knowledge are given to the agent, 1 to 20. The default is 8. A higher value gives the agent more to read.
  • conversation_id (optional). The id of a conversation, as returned by an earlier answer. Prefer session_id to keep a person's thread together.

Extra fields in the body are ignored.

Example

Terminal window
curl -X POST https://api.askvault.co/v1/query \
-H "Authorization: Bearer ak_xxx" \
-H "Content-Type: application/json" \
-d '{"query": "What is your refund policy?"}'

Response

{
"answer": "Refunds are available within 14 days of purchase.",
"sources": [
{
"document_name": "Refund Policy",
"chunk_text": "Refunds are available within 14 days of purchase...",
"relevance_score": 0.92,
"url": "https://yourstore.com/refund-policy"
}
],
"tokens_used": 450,
"query_id": "msg_xxx",
"conversation_id": "conv_xxx"
}

Those five fields are the whole body.

  • sources holds up to top_k passages. Each has the document_name, the exact chunk_text, a relevance_score and the page url. The url is null for uploaded files and for older content stored without one.
  • query_id identifies this answer. Log it and quote it when you contact support.
  • conversation_id is null when the question did not start or continue a conversation.

When the answer is not in your content

With strict answering on, which is the default, a question that matches nothing in your knowledge is not sent to the model. You get an empty sources array and a short fixed reply saying the agent couldn't find an answer and suggesting the visitor ask another way. To detect a gap in code, check for the empty sources array, not the wording of the reply, which can change. Then add the missing content and ask again.

If something was retrieved but only partly covers the question, the agent answers from what it found. Judge coverage from sources and their relevance scores, not from the tone of the answer.

An empty answer string is not a knowledge gap. It means no text was generated. Retry once, and if it repeats, contact support with the query_id.

Errors

Errors are JSON with a detail field: a string for most errors, and an object with an error_code (messages_exhausted or model_locked) for a 402. See API errors and rate limits for retry advice.

CodeMeaningWhat to do
200SuccessUse answer.
401API key missing, malformed or revokedCheck the Bearer token.
402Message credits are used up, or the workspace's model is not on your planBuy extra credits, upgrade or pick another model.
403Your plan does not include API accessUpgrade to Starter or above.
404The key's workspace or its owner no longer existsCreate a new key.
422Malformed JSON, or a field failed validationCheck the JSON, the query length and the top_k range.
429The key's rate limit was hit, or your monthly message quota is used upRead detail. Back off on a rate limit. A quota block does not clear by retrying.
500Server errorRetry with exponential backoff.

Requests rejected before an answer is written (401, 403, 422, 429) do not use message credits.

Common questions

Can I cache answers?

AskVault sends no cache headers on this endpoint. The first question in a new conversation can be answered from AskVault's answer cache, which is cleared when you change your knowledge. If you cache on your side, clear it when you update your knowledge.

How do I stream the answer?

Call POST /v1/query/stream with the same body. See Stream answers with the API.

How do I attach my user's identity?

/v1/query takes no user object. Use POST /v1/agent/ask for that, described in Conversations API. For visitors on your website, see Identify signed-in visitors.