fetch, has no runtime dependencies, and is tested on Node 20, 22 and 24.
For the options shared with the Python client, see the SDKs overview.
Install
Vaquill-AI/vaquill-sdks, js/ on GitHub.
Quickstart
result.resolved before you rely on it. See Citation quality.
Path parameters are positional arguments. Query and body fields keep the camelCase wire names.
Client options
new Vaquill({ apiKey, baseURL, timeout, maxRetries, defaultHeaders, fetch, maxCredits, idempotencyKeys, logger, logLevel })
apiKeydefaults toVAQUILL_API_KEY. Keys that do not start withvq_key_are rejected.baseURLdefaults toVAQUILL_BASE_URL, thenhttps://api.vaquill.ai.timeoutis per attempt, in milliseconds (default 60000).maxRetriesdefaults to 2.fetchinjects a custom implementation, for a proxy or a test double.maxCreditsis the spend guard, described below.client.creditsSpentshows the running total.loggeris where log lines go: any subset ofdebug,info,warnanderror, defaulting toconsole.logLevelis the minimum level, defaultwarn.debuglogs each request and response,infoadds retries, andwarnreports deprecated endpoints once per method and path. The API key is always redacted.client.withOptions({ ... })returns a derived client that shares the key and the spend counter.- Every method takes
{ timeout, maxRetries, headers, signal, idempotencyKey }as its last argument.
JSON.stringify, util.inspect, String(client) or any error.
Namespaces and credits
A call is charged when the API declares theIdempotency-Key header on its operation.
The SDKs derive the list of charged calls from the API contract, and prices are not hard-coded in them.
Each method maps to one
operationId, so search_statutes is statutes.search and get_section_body is statutes.getSectionBody.
That is 25 of the 30 charged operations in the contract. The other five are rulemaking docket routes without a method yet; the SDKs overview lists them.
The *All iterators call charged methods and spend per page.
client.pricing.get() returns the live price list.
Spend guard
PassmaxCredits to the constructor. Once responses on this client have reported that many credits, charged calls throw SpendGuardExceededError before sending anything.
It checks what is already spent, not the cost of the next call.
The SDKs overview explains how the guard stays exact under concurrency.
Error handling
VaquillError is the base. APIConnectionError (with APITimeoutError and APIUserAbortError) means no response arrived.
ResponseParseError is thrown when a success response is not valid JSON. It carries status, requestId and bodyPreview (the first 200 characters of the body).
APIStatusError carries status, requestId, code, retryable, retryAfterSeconds, body, and the legacy detail and errors.
APIStatusError: BadRequestError, AuthenticationError, InsufficientCreditsError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError (and DailyCapExceededError), InternalServerError, and IdempotencyConflictError with IdempotencyKeyReusedError, IdempotencyInProgressError and IdempotencyReplayUnavailableError.
The code is checked first, then the status, so an unknown code still gives the status class. Fields the server did not send come back as null.
The message of an UnprocessableEntityError (422) ends with the first validation reasons from the response’s errors list, so the rejected field is in err.message.
Retries and idempotency
The SDKs retry408, 429 and 5xx responses, plus a 409 only for idempotency_in_progress.
Connection errors and timeouts are retried when it is safe to do so.
The default is 2 retries, and setting the retry limit to 0 turns retries off.
Backoff starts at 0.5 seconds, doubles to an 8 second cap and is scaled down by 0 to 25 percent jitter.
The wait comes from the retry-after-ms header first, then Retry-After (seconds or an HTTP date), then the body’s retryAfterSeconds.
A wait above 120 seconds is not slept: the error is raised at once.
Never retried: a 402 insufficient_credits, daily_cap_exceeded, any other 4xx, and anything the server marks retryable: false.
Each charged call sends one generated Idempotency-Key, reused on every retry of that call.
When the server honours the key it replays the stored response instead of charging again, and the response reports that it was replayed.
Pass your own key to choose it.
Pass idempotencyKey: "..." to choose your own key, or idempotencyKey: false to turn automatic keys off.
With keys off, a charged call is not retried after a timeout, connection error or 5xx. The SDKs overview has the details, including free POSTs such as watches.create.
Pagination
The*All methods return an async iterable of items, with .pages() for whole pages and .toArray().
They hide offset with nextOffset, cursor with nextCursor, and sinceId / beforeId paging.
Batch helpers
Each helper wraps one batch operation, splits the input at the per-call cap and returns the members of every response as one flat array in input order.optionstakes the usual request options pluschunkSize. A value above the cap is clamped to it, so the helper never sends a request the server would refuse.- The spend guard is checked before each chunk, and exact repeats in the input are sent once.
- An empty input sends nothing.
- All three are charged.
Raw responses
.withResponse() returns the parsed data, the raw response and a meta object with status, headers, requestId, creditsConsumed, idempotentReplayed, rateLimit and retries.
client.rawRequest(method, path, { query, body, charged }) reaches endpoints newer than this SDK and returns the parsed value.
The Python raw_request returns an APIResponse instead, so it needs .parse().
Alerts and webhook verification
Create a law change alert. Watches are free.verify and unwrap follow the Standard Webhooks checks described in the SDKs overview (300 second tolerance, several signatures, a list of secrets for rotation) and compare in constant time.
A secret that starts with whsec_ is base64 decoded; any other secret is used as its UTF-8 bytes.
From 0.2.1, a whsec_ secret that is not valid base64 throws WebhookVerificationError (0.2.0 used the text as the key), so copy the secret exactly.
An empty or blank secret (or a bare whsec_) throws WebhookVerificationError, so an unset environment variable cannot verify a forged event.
Any failure throws WebhookVerificationError.
See Alerts for the payload and delivery behavior.
