Skip to main content

Agent Query (Legacy)

POST /v1/agent/query is the legacy alias of POST /v1/ask: same read-only turn, same flat charge, with ?wait=<seconds> for a bounded synchronous 200 answer.

POST /v1/agent/query is the legacy alias of POST /v1/ask: it answers a natural-language question over your workspace with cited documents, for integrations built against the original surface. Both endpoints run the same read-only turn and charge the same flat agent_ask unit (100 credits per accepted question, charged once per turn). The difference is the result: the ask endpoints return the full payload with the verification verdict and usage, while the query poll returns a compact {status, answer, tier, citations} body. Scoping, conversations, processing-option selection, output formatting and streaming exist only on /v1/ask. Use /v1/ask for new integrations.

The request body carries one field, query (up to 20,000 characters). By default the submission answers 202 Accepted with a turnId; poll GET /v1/agent/query/:id roughly every 2 seconds until status leaves processing. The alias requires a workspace-scoped key with the read scope, runs read-only with the document visibility of the user who created the key, and is isolated per workspace: a turn started by another workspace reads as 404.

Bounded synchronous mode: ?wait

?wait=<seconds> opts into a bounded synchronous answer. Simple lookup and total questions are often answered within a couple of seconds; when the answer is ready inside your budget, the request returns 200 OK with the completed payload (turnId, status: "completed", answer, tier, citations[]) and you skip the poll. Anything else, including an answer that overran the budget and every question that needs a longer turn, returns the same 202 {turnId} as without wait.

wait is capped by a configured ceiling (10 seconds by default): a value that is not a number between 0 and the ceiling is rejected with 400 naming the valid range, so a typo never silently falls back to async. Overrunning the budget costs nothing: the answer is saved the moment it is ready, so your first poll returns it. Longer turns take 10 to 60 seconds and are never held open by wait; treat the 202 as the normal case and the 200 as a latency bonus for simple questions.

answer is markdown prose that states the answer, the documents it covered, and a source line per cited value. When the turn produced tables or ranked lists, they are included in answer as markdown, so a headless consumer receives the whole result.

Charging is identical in both modes: one flat agent_ask unit (100 credits) per accepted question, keyed to the turn. wait changes what is returned, never what is charged: a 200, a 202 and a poll of the same turn all bill exactly once.
POST/v1/agent/query

Query parameters

waitnumberOptional. Seconds to hold the request open for an inline answer (0 up to the configured ceiling, 10 by default). Absent = always 202. Out-of-range or non-numeric values are rejected with 400.

Request body (JSON)

query*stringThe natural-language question, up to 20,000 characters.
GET/v1/agent/query/:id

curl: synchronous when possible (?wait)

curl -s -X POST "https://api.talonic.com/v1/agent/query?wait=5" \
  -H "Authorization: Bearer $TALONIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "What is the total gross amount across June invoices?"}'

Response (200, answered within the wait budget)

{
  "turnId": "7c2f1e04-51ab-4b8e-9d2f-3a6c8e0b4d21",
  "status": "completed",
  "answer": "The total gross amount across June invoices is EUR 48,200.00...",
  "tier": "retrieval_fast_path",
  "citations": [
    {
      "quote": "48,200.00",
      "document_id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "kind": "cell",
      "reference": "bruttobetrag",
      "filename": "invoice-0847.pdf",
      "app_url": "https://app.talonic.com/documents/c3d4e5f6-..."
    }
  ]
}

curl: asynchronous (default 202 + poll)

TURN_ID=$(curl -s -X POST https://api.talonic.com/v1/agent/query \
  -H "Authorization: Bearer $TALONIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "Summarize our open invoices by vendor."}' | jq -r '.turnId')

curl -s https://api.talonic.com/v1/agent/query/$TURN_ID \
  -H "Authorization: Bearer $TALONIC_API_KEY"

Poll response fields

statusstringprocessing, completed, or error.
answerstringThe final answer as markdown, including any tables the turn produced. Empty string until the turn completes.
tierstringWhich answer path produced the answer: retrieval_fast_path for quick answers, agent_loop for a full turn. Informational.
citationsarrayStructured citations: quote, document_id, kind, reference, filename, app_url. Same shape as on POST /v1/ask. Empty until the turn completes.
The 200 body of a ?wait request is the poll body plus turnId, built from the same saved values a later poll of the same turn returns, so the two can never disagree about what was answered or cited.

Errors

Error responses

400validation_errorMissing or over-length query, the API key is not workspace-scoped, or wait is present but not a number of seconds within the configured ceiling.
401unauthorizedMissing or invalid API key.
402insufficient_creditsBalance cannot cover one agent_ask unit.
404not_foundOn the poll: no turn with this id exists in your workspace.

Frequently asked questions

Should I use /v1/agent/query or /v1/ask?+
Use POST /v1/ask for anything new: same turn, same price, plus scoping, conversations, processing-option selection, output formatting, streaming, the verification verdict and usage reporting. The query alias keeps integrations built against the original surface working.
When does ?wait return 200 instead of 202?+
Only when the answer is ready within your budget, which is common for simple lookup and total questions. Questions that need a longer turn return 202 immediately, because those take 10 to 60 seconds and are never held open by wait.
What happens if the answer takes longer than my wait budget?+
Nothing is lost: you get the same 202 {turnId}, and because the answer is saved the moment it is ready, your first poll of GET /v1/agent/query/:id returns it. An overrun costs no extra credits.
How large can wait be?+
From 0 up to a configured ceiling, 10 seconds by default. A value outside that range, or a non-numeric one, is rejected with a 400 naming the valid range rather than being silently ignored.
Does using wait cost more?+
No. Both modes charge one flat agent_ask unit (100 credits) per accepted question, keyed to the turn so retries never double-bill. wait changes only what is returned.
Can I poll a turn started via /v1/agent/query through /v1/ask/:id?+
Treat the two surfaces as separate contracts: poll the surface you submitted on, and move the submission to /v1/ask when you want the richer payload.