docketrouter
DocumentationBrowse
API reference

TypeScript SDK

@docketrouter/sdk is the official TypeScript client. It has no dependencies, works on Node 20+ and in the browser (built on the global fetch), and ships as both ESM and CommonJS. Nothing in it is hand-maintained: every request and response type is walked out of the same OpenAPI document this reference is written from, by a script that runs in CI, so the SDK cannot silently drift from the API.

You do not need it -- every endpoint is plain HTTP and the examples throughout these docs use curl -- but it removes the boilerplate around auth, retries, streaming and error shapes if you are integrating in TypeScript or JavaScript.

Install

npm
npm install @docketrouter/sdk

Quickstart

A grounded, cited Texas answer in eight lines.

quickstart.ts
import { DocketRouter } from "@docketrouter/sdk";

const dr = new DocketRouter({ apiKey: process.env.DOCKETROUTER_API_KEY });

const r = await dr.chat.completions.create({
  model: "deepseek/deepseek-v4-flash",
  messages: [{ role: "user", content: "Under TRCP 21a, when is service by email complete?" }],
  docketrouter: { jurisdiction: "tx" },
});

console.log(r.choices[0]!.message.content);
console.log(r.docketrouter?.verification); // citation check + revision report

Mint a key at docketrouter.ai/keys. Every field under docketrouter is typed; see Chat completions for what each one does.

Streaming

chat.completions.stream returns an async iterator over the same chunk shape the raw SSE endpoint sends, already parsed from JSON.

stream.ts
for await (const chunk of dr.chat.completions.stream({
  model: "deepseek/deepseek-v4-flash",
  messages: [{ role: "user", content: "Summarize the standard for a Rule 91a dismissal." }],
})) {
  const delta = chunk.choices?.[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}
A streamed fabrication warning arrives as text, not just metadata

See Streaming: a streamed answer cannot be silently corrected the way a non-streaming one can, so a caught fabrication is appended as an extra content delta. Re-run without stream to get a repaired answer instead.

Error handling

Every non-2xx response throws DocketRouterError.

errors.ts
import { DocketRouter, DocketRouterError } from "@docketrouter/sdk";

try {
  await dr.chat.completions.create({ model: "gpt-4", messages: [{ role: "user", content: "hi" }] });
} catch (err) {
  if (err instanceof DocketRouterError) {
    console.error(err.status, err.type, err.message);
    // err.details, err.requestId, err.retryAfter -- see docs/errors
  }
  throw err;
}

The SDK retries 429 and 503 up to 3 times on its own, honouring Retry-After when the server sends one. Every other status is thrown immediately. Set maxRetries: 0 to handle rate limits yourself. See Errors, retries and limits for the full table.

App attribution

attribution.ts
const dr = new DocketRouter({
  apiKey: process.env.DOCKETROUTER_API_KEY,
  app: { name: "Brief Bot", url: "https://briefbot.example" },
});

Sends X-Title and HTTP-Referer on every request, the same convention OpenRouter uses. See Apps and attribution.

What's covered

One typed method per operation in the OpenAPI document.

NamespaceCoversNotes
chat.completionscreate, stream
modelslist, getpublic
keyslist, create, get, update, delete, rotatesession-gated
authKeyget
fileslist, create, delete
matterslist, create, get, update, delete, attachFile, detachFilefeature-gated: 503 if disabled on the host
ragquery, rulespublic
citationscheck, supportpublic
downloadslist, getget returns the raw Response
usagelist, get, sync, dailylist/daily overload to a CSV string on format: "csv"
billingbalance, checkout, monero, autotopupsession-gated except monero invoices
hllpublic, stats, submissionssubmissions.list/create session-gated
results, route, apps, credits, generation, analyticsone method eachpublic / key or session
Session-gated means a browser cookie, not a key

keys.* and most of billing.* require a signed-in Clerk session and are deliberately unreachable with a dr-... key, so a leaked key can never mint or enumerate keys. They're in the SDK for completeness; called with only apiKey set, they 401.

Relation to the OpenAPI spec

Nothing in the SDK's types is hand-written. A script walks the OpenAPI document's schemas and every operation's request/response body into TypeScript, and a test regenerates and diffs on every run -- the SDK fails its own build if the spec changes without a matching regeneration.

  • Source: github.com/docketrouter/docketrouter, packages/docketrouter-sdk.
  • License: MIT.

Something here wrong or missing? Mail hello@docketrouter.ai with the request_id and we will fix the docs or the API, whichever is broken.