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.
Install
Section titled “Install”npm install @midlyr/sdk-jsThe package ships with TypeScript types out of the box.
Authenticate
Section titled “Authenticate”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.
Submit a Screening Job
Section titled “Submit a Screening Job”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.
Browse the Regulatory Library
Section titled “Browse the Regulatory Library”const results = await midlyr.regulations.browse({ query: "provisional credit", limit: 10,});
for (const doc of results.documents) { console.log(doc.id, doc.title);}Read a Document
Section titled “Read a Document”const detail = await midlyr.regulations.get("cmdoc_01HXZ3K4M7QR9VP2N8WYJF5GTB");
const body = await midlyr.regulations.readContent(detail.id, { offset: 0, limit: 40000,});Query the Corpus
Section titled “Query the Corpus”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.
Capabilities Summary
Section titled “Capabilities Summary”| Namespace | Method | Purpose |
|---|---|---|
regulations | browse | Search the regulatory library. |
regulations | get | Inspect document metadata and table of contents. |
regulations | readContent | Pull source text by byte range. |
regulations | query | Vector-search the corpus for relevant chunks (retrieval, not generation). |
analysis | screen | Submit a compliance-screening job. |
jobs | get | Poll a job for status or terminal result. |
Next Steps
Section titled “Next Steps”- Authentication — generating and rotating API keys.
- API Reference — full endpoint documentation.
- MCP Overview — connect AI assistants directly to MidLyr.