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/querySend 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. Prefersession_idto keep a person's thread together.
Extra fields in the body are ignored.
Example
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?"}'import os, requestsr = requests.post( "https://api.askvault.co/v1/query", headers={"Authorization": f"Bearer {os.environ['ASKVAULT_API_KEY']}"}, json={"query": "What is your refund policy?"}, timeout=60,)print(r.json()["answer"])const r = await fetch("https://api.askvault.co/v1/query", {method: "POST",headers: { "Authorization": `Bearer ${process.env.ASKVAULT_API_KEY}`, "Content-Type": "application/json",},body: JSON.stringify({ query: "What is your refund policy?" }),});console.log((await r.json()).answer);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.
sourcesholds up totop_kpassages. Each has thedocument_name, the exactchunk_text, arelevance_scoreand the pageurl. Theurlisnullfor uploaded files and for older content stored without one.query_ididentifies this answer. Log it and quote it when you contact support.conversation_idisnullwhen 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.
| Code | Meaning | What to do |
|---|---|---|
| 200 | Success | Use answer. |
| 401 | API key missing, malformed or revoked | Check the Bearer token. |
| 402 | Message credits are used up, or the workspace's model is not on your plan | Buy extra credits, upgrade or pick another model. |
| 403 | Your plan does not include API access | Upgrade to Starter or above. |
| 404 | The key's workspace or its owner no longer exists | Create a new key. |
| 422 | Malformed JSON, or a field failed validation | Check the JSON, the query length and the top_k range. |
| 429 | The key's rate limit was hit, or your monthly message quota is used up | Read detail. Back off on a rate limit. A quota block does not clear by retrying. |
| 500 | Server error | Retry 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.