Skip to content

Typed clients

The API is described by an OpenAPI 3 document, the same one the reference is built from. Generators turn it into a client with every endpoint, parameter and response typed, so your editor completes them and catches mistakes before you run anything.

The document is served by every instance, matching the version it runs:

https://loomkeep.app/api/v1/openapi.json

On a self-hosted instance, use your own address. Regenerate the client after an upgrade to pick up new fields: within v1, they are only ever added.

openapi-typescript generates the types, and openapi-fetch is a small fetch wrapper that uses them.

  1. Generate the types, and install the client:

    Terminal window
    npx openapi-typescript https://loomkeep.app/api/v1/openapi.json -o loomkeep.d.ts
    npm install openapi-fetch
  2. Call the API. Paths, parameters and responses are checked against the document:

    import createClient from "openapi-fetch";
    import type { paths } from "./loomkeep";
    const loomkeep = createClient<paths>({
    baseUrl: "https://loomkeep.app",
    headers: { Authorization: `Bearer ${process.env.LOOMKEEP_API_KEY}` },
    });
    const { data, error } = await loomkeep.GET("/api/v1/library", {
    params: { query: { phase: ["IN_PROGRESS"], limit: 10 } },
    });
    if (error) throw new Error(error.code ?? error.message);
    for (const entry of data.items) console.log(entry.work.title);