API client
Generated TypeScript client and runtime configuration.
@zitadel/api is the typed TypeScript client for the Zitadel API. It is generated from the OpenAPI source under apps/api/api/openapi/, so it covers every operation.
It exposes:
- generated endpoint functions
- generated models
- Zod schemas
- MSW helpers
- runtime helpers for base URL and auth
Prerequisites
- A Zitadel project from
zitadel setup. Start the local runtime withnpx @zitadel/cli@latest start, then runnpx @zitadel/cli@latest setup --server localin your app's directory. See the Quickstart. - The server URL, the project ID and the project secret. Setup writes them to
.env.localasZITADEL_URL,ZITADEL_PROJECT_IDandZITADEL_PROJECT_SECRET, and the secret also to.zitadel/secret. Authentication explains the secret. Keep it on a server, out of source control and out of the browser.
Install the package
pnpm add @zitadel/api@latestMake an authenticated call
Call the API from server-side code. This script creates a client with the project secret and reads your project:
import { createZitadelApi, ZitadelClient } from "@zitadel/api/client";
const api = createZitadelApi(
new ZitadelClient({
baseUrl: process.env.ZITADEL_URL ?? "http://localhost:8080",
token: process.env.ZITADEL_PROJECT_SECRET!, // server-side only
}),
);
const project = await api.getProject(process.env.ZITADEL_PROJECT_ID!);A ZitadelClient is one immutable connection: the base URL, the token, and any deadline (timeoutMs), abort signal, userAgent or fetch to send through. client.with({ ... }) returns a changed copy. Its onRequest runs before every request with the operation's name, URL and request, and throwing from it stops the request before anything is sent.
baseUrl is the server's origin: the client calls the API under /api/v1 there, and keeps a single prefix when the origin already ends in it. Every operation in the API reference shows its call through this client, beside its request and response shapes. The method is named after the operation and takes its path parameters, its body, then its query parameters; an optional body comes after required query parameters.
getProject sends GET /projects/{project_id} with the secret as a bearer token. It resolves to the project, with fields such as id, name and origins. Run the script with the variables from .env.local in its environment.
If the secret is missing or wrong, the server answers 401 and the call throws an ApiError. If the project ID names no project, the server answers 404 and the call throws the same error.
Entry points
The package has no root export; import from its subpaths:
@zitadel/api/client—ZitadelClient, one connection, andcreateZitadelApi, every operation bound to one client; andpagedFunctions, which says for each paged function where a page's items and cursor are, and builds the arguments that fetch the page a cursor names.@zitadel/api/config—configureZitadel,getApiandgetClient, the shared browser configuration the components read. Every SDK except Angular uses it; the Angular SDK has its ownconfigureZitadel.@zitadel/api/generated/model— request and response types.@zitadel/api/generated/endpoints/zitadelNextGen— the endpoint functions behind the client, each taking itsZitadelClientfirst (getProject(client, projectId)), with.zodand.mswvariants for the Zod schemas and MSW handlers. Import the few you call to keep the rest out of a bundle. The MSW handlers need the optional peersmswand@faker-js/faker.@zitadel/api/runtime/fetch—ApiErrorandNetworkError, which a call throws when the request fails.@zitadel/api/runtime/paging—Paging, which reads a page of one list and walks its pages (walk()) or gathers them (collect()), for a request the client does not make.Paging.byField()builds one for a list known only by the names of its fields.@zitadel/api/runtime/client—ZitadelClientalone, for code that imports only the endpoint functions it calls.@zitadel/api/runtime/base-url—API_PREFIXandapiBaseUrl, which put/api/v1after a base.
Page through lists
A paged list method returns one page and its next_page_token. Each one also carries items(), pages() and all(), which take the same arguments and follow the cursor for you:
for await (const deployment of api.listDeployments.items({ project_id })) {
if (deployment.status === "live") break; // later pages are never fetched
}
const schemas = await api.listSchemas.all({ project_id, limit: 100 });items() and pages() fetch the next page only when the loop reaches it, so a loop that stops early reads nothing more. limit sets the page size, and a page_token among the arguments is where the walk starts. To change what every call returns, each page included, pass onResponse or onError to createZitadelApi.
Edit the OpenAPI source
Do not hand-edit generated API package output. Update apps/api/api/openapi/** and regenerate through the repo tasks.
API reference
Generated endpoint docs grouped by OpenAPI tags.
Sessions
Session lifecycle and session-token endpoints.
Auth attempts
Ephemeral authentication state machine endpoints.
See also
- API reference: every endpoint, generated from the same OpenAPI source.
@zitadel/apisource and the OpenAPI spec.
Was this helpful?