Skip to content

TypeScript SDK

The TypeScript SDK (@midlyr/sdk-js) is the official typed client for MidLyr. It runs anywhere modern fetch is available — Node.js, Bun, Deno, Cloudflare Workers, and the browser — and ships with no runtime HTTP dependencies.

Terminal window
npm install @midlyr/sdk-js

The package ships with TypeScript types out of the box.

Generate an API key from the MidLyr dashboard and pass it to the client. Keep keys out of source control — read them from the environment or a secret manager.

import { Midlyr } from "@midlyr/sdk-js";
const midlyr = new Midlyr({
apiKey: process.env.MIDLYR_API_KEY!,
});

The client sends the key on every request via the x-api-key header.

const response = await midlyr.analysis.screen({
content: { type: "text", text: "Get 0% APR for life!" },
scenario: "marketing_asset",
});
const job = await midlyr.jobs.get(response.id);

Screening is asynchronous — analysis.screen returns a job ID, and jobs.get reads the current status. Poll until the job reaches a terminal state.

const results = await midlyr.regulations.browse({
query: "provisional credit",
limit: 10,
});
for (const doc of results.documents) {
console.log(doc.id, doc.title);
}
const detail = await midlyr.regulations.get("cmdoc_01HXZ3K4M7QR9VP2N8WYJF5GTB");
const body = await midlyr.regulations.readContent(detail.id, {
offset: 0,
limit: 40000,
});

regulations.query(body) returns Promise<{ results: RegulationCitation[] }>. Each RegulationCitation pairs a parent regulation with one or more chunks (text, byte offsets, sectionPath) — the same shape returned by Screen Analysis citations.

import type { RegulationCitation } from "@midlyr/sdk-js";
const { results } = await midlyr.regulations.query({
query: "provisional credit timing requirements",
limit: 5,
filters: { authorities: ["cfpb"] }, // or "cfpb" — single-string form is accepted
});
for (const citation of results) {
console.log(citation.regulation.title);
for (const chunk of citation.chunks) {
console.log(chunk.sectionPath, chunk.text);
}
}

query is a retrieval primitive — it returns the top relevant regulation chunks for a natural-language query and does not invoke an LLM. Compose with your own model to build retrieval-augmented generation.

NamespaceMethodPurpose
regulationsbrowseSearch the regulatory library.
regulationsgetInspect document metadata and table of contents.
regulationsreadContentPull source text by byte range.
regulationsqueryVector-search the corpus for relevant chunks (retrieval, not generation).
analysisscreenSubmit a compliance-screening job.
jobsgetPoll a job for status or terminal result.