API · Queries
Ask a question
/api/v1/documents/{id}/queries
Model tokens (the document is cached after the first question)
Answers from the document's text and images with page citations. Give a JSON schema to get a structured answer. Runs synchronously and returns 200 when it finishes in time; send "async": true (or wait for a 202) and poll the query instead. When the workspace already has several questions running it also answers 202, and the question runs in the background. Repeated questions over the same document reuse a cached prompt prefix.
A 200 can carry status: "failed" with an error: type is insufficient_credits (the credit left cannot cover this question's estimate), document_too_large (too long for the model you chose), document_expired, schema_mismatch or query_failed. A 402 means the workspace has no credit left at all.
Path parameters
-
idstring requiredThe document's id.
Body application/json
-
questionstring requiredWhat you want to know, in plain words.
at most 4000 characters
-
asyncboolean optional default falsetrueanswers202straight away with apoll_url, instead of waiting for the answer. -
instructionsstring optionalHow to answer: length, units, what to do when unsure.
at most 4000 characters
-
modelauto | swift | summit optional default autoWhich model answers:
swift(fast, economical),summit(most capable) orauto(by the document's size). -
schemaobject optionalA JSON Schema (
type: object) the answer must follow. With one,answer.answeris an object you can store; without, it is a sentence.
Returns 200
Answered
-
idstringThe query's id.
-
objectstringAlways
query. -
answerQueryAnswerThe answer, once
statusiscompleted. SeeQueryAnswer.4 fields
-
answerobjectA string, or an object following the query's
schema. -
citationsarray of objectEvery page and quote the answer came from.
2 fields
-
pageinteger -
quotestring
-
-
confidencenumberHow sure the model is, from 0 to 1.
at least 0 · at most 1
-
not_foundbooleantruewhen the document does not answer the question.
-
-
completed_atstringWhen it was answered.
-
costobjectHeld, then charged, in micro-USD.
2 fields
-
estimated_microinteger -
settled_microinteger
-
-
created_atstringWhen you asked.
-
document_idstringThe document it was asked of.
-
errorobjectWhy it failed.
2 fields
-
messagestring -
typeinsufficient_credits | document_too_large | document_expired | schema_mismatch | query_failed
-
-
instructionsstringThe instructions you sent, if any.
-
modelobjectThe model you asked for and the one that answered.
2 fields
-
requestedstring -
usedstring
-
-
questionstringWhat you asked.
-
schemaobjectThe JSON Schema you asked the answer to follow, if any.
-
statusqueued | processing | completed | failedcompletedmeansansweris ready;failedmeans readerror.
Errors
-
401Missing, revoked or expired key
-
402No credits left, or (for an upload) not enough for its estimated cost. A URL document or a question whose estimate the credit cannot cover is accepted and then fails with
error.type: insufficient_credits. -
404No document or query with that id for this key (documents are scoped to the key's workspace and live/test mode)
-
409The document has not finished processing
-
410Retention ran out and the result was purged
-
422Body or options failed validation (
detailslists the fields), or the document is too large (document_too_large) -
429Per-second burst limit for the plan exceeded; retry after
Retry-Afterseconds
Every error has the same shape. See Errors.