TypeScript
Install and use @adlass/api.
npm install @adlass/apiThe package exports createAdlassClient, the paginate helper, the AdlassError class and the generated paths, components and operations types. It runs anywhere fetch exists: Node.js 20+, Deno, Bun, Cloudflare Workers and Vercel Edge.
Create a client
import { createAdlassClient } from "@adlass/api";
const client = createAdlassClient({
token: process.env.ADLASS_API_KEY!,
// baseUrl: "https://dev.adlass.io/v1", // development environment, adl_test_ keys
// maxRetries: 3, maxRetryDelayMs: 60_000,
});client is an openapi-fetch client. Paths, parameters and bodies are checked at compile time against the schema.
Read
const { data, error, response } = await client.GET("/spaces/{space_id}", {
params: { path: { space_id: "123e4567-e89b-42d3-a456-426614174000" } },
});
if (error) throw new Error(`${response.status}: ${error.code}`);
console.log(data.name);error is the parsed problem body with code, detail and request_id. Keep request_id for support requests.
Write
const { data } = await client.POST("/spaces", {
body: { name: "Customer documents" },
headers: { "Idempotency-Key": orderId }, // optional; a UUID is generated otherwise
});Paginate
import { paginate } from "@adlass/api";
for await (const document of paginate((cursor) =>
client.GET("/documents", { params: { query: { limit: 100, cursor } } }),
)) {
console.log(document.file_name);
}paginate follows next_cursor until it is null and throws AdlassError when a page fails.
Retries and cancellation
429 responses are retried up to maxRetries times, waiting for Retry-After or an exponential backoff, never longer than maxRetryDelayMs. Pass an AbortSignal through signal in any request to cancel waits and requests. Redirects are rejected so a key never leaves the API origin.