# @sentry/api

The official, auto-generated TypeScript client for Sentry's public REST API.

[![npm](https://img.shields.io/npm/v/@sentry/api.svg)](https://www.npmjs.com/package/@sentry/api)
[![license](https://img.shields.io/npm/l/@sentry/api.svg)](./LICENSE.md)

## Install

```bash
npm install @sentry/api
```

Installed directly, the package supports Node.js 22 and later, as `engines.node` in `package.json` declares. A consumer that bundles it into its own build, like the [Sentry CLI](https://github.com/getsentry/toolkit/tree/main/packages/cli), ships its own runtime floor and tests the bundled copy itself. The CLI's packed-runtime CI covers its copy on Node.js 20.

## Usage

Configure a client once, then call its typed operation methods:

```ts
import { createSentryClient } from "@sentry/api";

const sentry = createSentryClient({
  baseUrl: "https://sentry.io",
  headers: { Authorization: `Bearer ${process.env.SENTRY_AUTH_TOKEN}` },
});

const result = await sentry.listOrganizations();

if ("error" in result) throw result.error;
console.log(result.data);
```

Operation methods retain the generated documentation, typed arguments, and response types. Per-call options include `path`, `query`, `headers`, `signal`, and `throwOnError`. Results preserve the underlying `request` and `response`, including response headers:

```ts
const controller = new AbortController();

const { data: project, request, response } = await sentry.getProject({
  path: {
    organization_id_or_slug: "my-org",
    project_id_or_slug: "my-project",
  },
  signal: controller.signal,
  throwOnError: true,
});

console.log(project, request.url, response.headers.get("content-type"));
```

Operations always return `fields`: `{ data, request, response }` on success, or `{ error, request, response }` on failure. A failure without an HTTP response has `response: undefined`. Check `"error" in result`, since a custom error can itself be `undefined`. Received headers are in `response.headers`; outgoing headers are in `request.headers`.

Set `throwOnError: true` to reject on failures while keeping the same success fields. Methods are bound to their instance and can be safely destructured, such as `const { getProject } = sentry`. Types narrow to success when `true` is supplied **per call**; calls that inherit mutable client configuration conservatively retain the result union.

Each `createSentryClient` call creates an independent transport configuration. The root entry also exports the `SentryClient` and `Config` types; `Config` is the underlying transport's configuration type. Access that transport as `sentry.client` for interceptors, configuration updates, or low-level requests.

Supply the base URL and authentication appropriate for your deployment. See Sentry's [API authentication documentation](https://docs.sentry.io/api/auth/).

The base URL is the Sentry origin, such as `https://sentry.io` or a self-hosted `https://sentry.example.com`. Operation paths are relative to the API base path, which the client adds after the origin. It comes from the server URL in Sentry's OpenAPI spec and is exported as `API_BASE_PATH` from `@sentry/api`, `@sentry/api/client`, and `@sentry/api/operations`. Raw requests take the same relative paths, such as `sentry.client.get({ url: "/organizations/" })`.

### Standalone operations

Individual operation functions remain available as a modular alternative and accept transport configuration directly:

```ts
import { listOrganizations } from "@sentry/api";

const { data, error } = await listOrganizations({
  baseUrl: "https://sentry.io",
  headers: { Authorization: `Bearer ${process.env.SENTRY_AUTH_TOKEN}` },
});
```

They can also reuse an existing instance's configuration: `listOrganizations({ client: sentry.client })`.

### Query parameter types

Each operation's `<Operation>Data` type describes its `path`, `query`, and `body`. Enum-valued query parameters also get a named type for one value, `<Operation>Query<Parameter>`. For array parameters, that is the element type:

```ts
import type {
  ListOrganizationTraceItemAttributesQueryAttributeType,
  ListOrganizationTraceItemAttributesQueryDataset,
} from "@sentry/api";

const dataset: ListOrganizationTraceItemAttributesQueryDataset = "spans";
const types: ListOrganizationTraceItemAttributesQueryAttributeType[] = ["string", "number"];
```

### Types by path

`ApiRoutes` maps each path, as written in the spec and relative to `API_BASE_PATH`, and HTTP method to its operation's name, `data` type, and status-keyed `responses` and `errors`. Use it when you build requests from a path rather than an operation function. It is type-only:

```ts
import type { ApiRoutes } from "@sentry/api";

type ListProjects = ApiRoutes["/organizations/{organization_id_or_slug}/projects/"]["GET"];
type Projects = ListProjects["responses"][200];
type ProjectsQuery = ListProjects["data"]["query"];
```

### Query defaults

A few operations send a query parameter by default to skip expensive work most callers don't need. The operation's documentation states the default.

| Operation | Default | Effect |
| --- | --- | --- |
| `getOrganizationIssueEvent` | `collapse: ["adjacentEvents"]` | Skips the next/previous event lookups; `nextEventID` and `previousEventID` are `null` |
| `getProjectEvent` | `collapse: ["adjacentEvents"]` | Skips the next/previous event lookups; `nextEventID` and `previousEventID` are `null` |

The default applies only when the parameter is omitted or `undefined`. Any value you pass replaces it, and an empty list sends nothing:

```ts
const path = { organization_id_or_slug: "my-org", issue_id: "123", event_id: "latest" } as const;

await sentry.getOrganizationIssueEvent({ path }); // ?collapse=adjacentEvents
await sentry.getOrganizationIssueEvent({ path, query: { collapse: [] } }); // includes nextEventID/previousEventID
```

Standalone operations, bound methods, and `narrowError_*` wrappers behave the same way. The operation catalog describes the API itself, so it does not list these defaults.

### Query serialization

The client writes the query string the way `query-string@7`'s `stringify` does with its default options. Keys are sorted, `null` becomes a bare key, `undefined` is omitted, and arrays repeat the key (`field=id&field=title`). Keys and values are percent-encoded, including `!'()*`. Objects, which query-string doesn't encode, are written in `deepObject` style (`filter[status]=open`):

```ts
import { createSentryClient } from "@sentry/api";

const sentry = createSentryClient({ baseUrl: "https://sentry.example.com" });
sentry.client.buildUrl({ url: "/organizations/", query: { sortBy: "date", query: null, cursor: undefined } });
// https://sentry.example.com/api/0/organizations/?query&sortBy=date
```

Pass `querySerializer`, a function that takes the query object and returns the string after `?`, to write it some other way.

### Operation discovery

`@sentry/api/operations` exports a readonly catalog for offline discovery, without importing the client, validators, or transport:

```ts
import { operations } from "@sentry/api/operations";

const logOperations = operations.filter(operation =>
  operation.queryParameters.some(parameter =>
    parameter.name === "dataset" && parameter.enum?.includes("logs"),
  ),
);
console.log(logOperations.map(({ functionName, method, path }) => ({ functionName, method, path })));
```

Each `ApiOperation` records the actual exported `functionName`, original OpenAPI `operationId`, method, path (relative to `API_BASE_PATH`), summary, description, tags, path parameter names, query metadata, explicit deprecation flag, `experimental` flag, `idempotent` flag, `routing` declaration, and `projectScope` declaration when Sentry has one. `ApiQueryParameter` includes the name, required flag, description, type, and declared enum values (item values for arrays). Operation parameters override inherited path parameters.

`experimental` is `true` when Sentry marks the operation with the `x-sentry-experimental` OpenAPI extension, which it sets for endpoints under active development that may change. Their SDK docs also start with an **Experimental:** note. To find or reject experimental operations, for example in a lint rule or build check:

```ts
import { operations } from "@sentry/api/operations";

const experimental = new Set(
  operations.filter(operation => operation.experimental).map(operation => operation.functionName),
);
experimental.has("listOrganizationTraceMetrics"); // true
```

`routing` copies Sentry's `x-sentry-routing` declaration: `silo` is where the operation is declared available (`control`, `cell`, `both`, or `unknown`), and `organizationParameter`, when present, names the path parameter that identifies the organization. `silo` is availability, not a preferred destination or a guarantee that a gateway forwards the request, and `both` operations can return different results in each context. Consumers keep their own routing policy:

```ts
import { operations } from "@sentry/api/operations";

const listProjects = operations.find(operation => operation.functionName === "listOrganizationProjects");
listProjects?.routing; // { silo: "cell", organizationParameter: "organization_id_or_slug" }
```

`matchOperation` finds the catalog operation for a method and a concrete path, such as one a raw request or a proxy sees, with its decoded path parameters:

```ts
import { matchOperation } from "@sentry/api/operations";

const match = matchOperation("GET", "/api/0/organizations/acme/issues/?query=is:unresolved");
match?.operation.operationId; // the operation's OpenAPI identifier
match?.operation.routing; // { silo: "cell", organizationParameter: "organization_id_or_slug" }
match?.params; // { organization_id_or_slug: "acme" }
```

The path may include `API_BASE_PATH`, an origin or a query string, and a missing trailing slash still matches. Where templates overlap, a literal segment wins over a parameter at the first segment where they differ, so `/snapshots/latest-base/` is not read as a `{snapshot_id}`. Only operations in the public catalog match; `matchOperation` returns `undefined` for others. To match a filtered catalog or your own templates, build a matcher with `createOperationMatcher`, which accepts any `{ method, path }` list and throws on first use if two templates for one method differ only in parameter names.

`idempotent` tells retrying clients whether resending an identical request after a timeout or 5xx response is safe. It is always `true` for `GET`, `HEAD`, `OPTIONS`, and `TRACE`. Other methods are `true` only when Sentry marks the operation with the `x-sentry-idempotent` OpenAPI extension; `false` means not known to be idempotent, not known to be unsafe.

`projectScope` copies Sentry's `x-sentry-project-scope` declaration, which says how a request names the projects whose data it returns or changes. Clients that limit a caller to some projects read it instead of keeping their own endpoint list. `ApiProjectScope` is one of:

- `path`: the path names the project.
- `filter`: an organization endpoint that takes the `project` query parameter (numeric project IDs) and returns or changes only those projects' data.
- `org-metadata`: a read-only organization endpoint whose response holds no project's telemetry, such as settings, members, or integrations. Only on `GET`.
- `response:<pointer>`: a `GET` that looks something up by ID alone. The numeric ID of the project it belongs to is at `<pointer>` in the response body. `<pointer>` is an RFC 6901 JSON pointer in which a `*` segment matches every element of an array, such as `response:/projects/*/id`.

An operation without a declaration has no `projectScope`, which means it is not known to respect a project limit. The build fails on any other value, and on `org-metadata` or `response:` for a method other than `GET`:

```ts
import { matchOperation, type ApiProjectScope } from "@sentry/api/operations";

const scope: ApiProjectScope | undefined = matchOperation("GET", "/api/0/projects/acme/backend/")?.operation.projectScope;
scope; // "path"
```

The catalog is generated from the same schema and SDK output as each release. Consumers own search, grouping, ranking, and command aliases; the catalog does not fetch a live schema or infer undocumented API behavior.

### API reference data

`@sentry/api/docs` exports what an API reference page shows for each operation, so a docs site can render the reference from the package version it pins instead of fetching the spec:

```ts
import { API_BASE_PATH, operations, tags } from "@sentry/api/docs";

for (const operation of operations) {
  console.log(operation.method, `${API_BASE_PATH}${operation.path}`, operation.summary);
  for (const response of operation.responses) console.log(response.status, response.example);
}
```

Operation paths are relative to `API_BASE_PATH`, which comes from the spec's server URL, as in the client and `@sentry/api/operations`. Server overrides keep only their origin. A page shows an operation's full path as `${API_BASE_PATH}${operation.path}`.

`tags` lists the categories, with their sidebar names and descriptions. Each `ApiDocsOperation` has the original `operationId`, summary and description as the spec writes them, tags, deprecated and experimental flags, server overrides, security requirements, path and query parameters with their schemas, the request body's first content type with its schema and example, and every response with its schema and examples. The data comes from the same spec as the client in each release, so it is about 3.7 MB; import it only where you render the reference. Its shape follows semver: a breaking change to it is a major release.

To preview a spec that isn't released yet, such as a local `make build-api-docs` output, build the same data from it with `extractDocs`:

```ts
import { extractDocs } from "@sentry/api/docs";

const { apiBasePath, tags, operations } = extractDocs(JSON.parse(readFileSync("tests/apidocs/openapi-derefed.json", "utf8")));
```

### Build-time source analysis

`@sentry/api/source-analysis` follows references in supplied TypeScript source to discover calls to catalog operations. Install TypeScript only when using this optional build tool; the analyzer is tested with TypeScript 5.9. Its optional peer uses a wildcard so it does not constrain the compiler used by applications that only import the client.

```bash
npm install --save-dev @sentry/api typescript@^5.9
```

```ts
import { operations } from "@sentry/api/operations";
import { analyzeSourceApiUsage } from "@sentry/api/source-analysis";

const sources = new Map([
  ["features/logs.ts", `
    import { listOrganizationEvents } from "@sentry/api";
    export const readLogs = () =>
      listOrganizationEvents({
        path: { organization_id_or_slug: "example-org" },
        query: { dataset: "logs", field: ["message"] },
      });
  `],
]);
const analysis = analyzeSourceApiUsage(sources, operations, {
  queryParameters: ["dataset"],
});
console.log(analysis.exports.get("features/logs.ts")?.get("readLogs")?.operations);
// Includes listOrganizationEvents with known query context { dataset: "logs" }.
```

The analyzer parses source without executing it, following local imports, re-exports, aliases, and references. Supply sources together with the operation catalog from the installed SDK version. Run it during the consumer's build: command-to-operation relationships depend on consumer code and cannot be precomputed during SDK packaging.

Named, namespace, and default imports are supported, along with top-level functions, variable initializers, and default function/expression exports. Relative imports resolve only against the supplied sources. Extensionless paths try the exact file, `.ts`, `.tsx`, `index.ts`, then `index.tsx`; `.js` specifiers try `.ts` and `.tsx` before the exact `.js` file. Explicit `.ts`/`.tsx` specifiers use the exact file. Named re-exports can forward a default; `export *` forwards only named exports.

Consumers configure their own `boundaries` (factory names whose arguments are inspected without following the factory implementation), `requests` (raw-request wrapper argument positions), `queryParameters` (query values to retain), and `declarationFlags` (boolean markers). These options default to empty lists. Returned `boundaries` identify factory-created exports and their markers; `methods` records reachable HTTP methods, including known methods on unresolved raw requests. CLI routing, aliases, presentation, and destructive-command policy remain with the consumer.

This is static discovery, not proof of runtime execution or safety. Class/member dispatch, dynamic imports, CommonJS, and `tsconfig` path aliases are outside its scope. Missing sources and unsupported constructs can omit calls, so an empty result does not prove that no API calls exist. `unresolvedRequests` contains diagnostics for raw requests that cannot be resolved against the public catalog, not source-coverage diagnostics. Unknown query values are omitted, mutable `let` and `var` bindings are left unknown, and a related operation does not describe every request a workflow makes. The entry imports TypeScript separately and is not loaded by the root client, browser helpers, or operation catalog.

### Browser sessions

The browser helper configures session cookies and CSRF token injection:

```ts
import { createSentryClient } from "@sentry/api";
import { createBrowserSdkConfig } from "@sentry/api/browser";

const sentry = createSentryClient(
  createBrowserSdkConfig({ baseUrl: "https://sentry.example.com" }),
);

const { data, error } = await sentry.listOrganizations();
```

The CSRF token goes only on unsafe-method requests (not `GET`, `HEAD`, `OPTIONS` or `TRACE`) to the page's origin or a similar one: the same host, a parent or subdomain of it, or a sibling subdomain such as `us.sentry.io` from `acme.sentry.io`. Hosts are compared by whole DNS labels. From an `https:` page, only `https:` targets get the token; `http:` pages are not restricted by scheme. The page origin is `location.origin`; pass `origin` to set it, for example in tests. Without either, only relative URLs get the token.

### Routing requests by organization

Set `resolveBaseUrl` to pick each request's base URL before the URL is built,
such as the region that serves the organization. It receives the configured
`baseUrl` (`''` when unset) and the path and query that follow it. For a
generated operation it also receives `routing`, the operation's declaration
from `@sentry/api/operations`, and `organization`, the value of the path
parameter that `routing.organizationParameter` names. Raw requests have no
`routing`. `scope` is the organization and project read from the path
(`parseApiPathScope` from `@sentry/api/client`; absent for unscoped paths).
Its result replaces `baseUrl` for that request only; trailing slashes are
removed.

`routeCellOperations` from `@sentry/api/client` builds a resolver from a lookup
the host already has, such as cached `links.regionUrl` values from the
organization listing. It sends operations declared `cell` to the region the
lookup returns for their organization. Everything else keeps the configured
base URL: `control` and `both` operations, `unknown` operations, raw requests,
and organizations the lookup does not know. It never looks a region up itself,
and it trusts the URLs the lookup returns.

```ts
import { routeCellOperations } from "@sentry/api/client";

const sentry = createSentryClient({
  baseUrl: "https://sentry.io",
  resolveBaseUrl: routeCellOperations(organization => regionUrls.get(organization)),
});
// Sent to the organization's region, such as https://us.sentry.io.
await sentry.listOrganizationIssues({ path: { organization_id_or_slug: "acme" } });
```

Raw requests, such as `client.get` or `client.prepareRequest` with a
hand-written path, keep the configured base URL by default. Pass
`{ rawRequests: "lookup" }` to send those whose path names an organization
through the lookup too, for example when the lookup also picks the account or
server that knows the organization. Generated operations still follow their
declarations.

```ts
import { routeCellOperations } from "@sentry/api/client";

const sentry = createSentryClient({
  baseUrl: "https://sentry.io",
  resolveBaseUrl: routeCellOperations(organization => regionUrls.get(organization), {
    rawRequests: "lookup",
  }),
});
// Also sent to the organization's region.
await sentry.client.get({ url: "/organizations/acme/issues/" });
```

It runs once per request, including `prepareRequest`, after `requestValidator`
and before request interceptors. A per-call `resolveBaseUrl` replaces the
configured one. A throw rejects the request unchanged, before `fetch` is called.

### Renamed projects

A request that uses a project's old slug gets a 302 to the same URL with the new slug, and fetch follows it. `getSentryProjectRename(request, response)` reports such a rename, from the followed redirect or from the 302's `Location` when redirects are not followed. It returns `{ organization, previousSlug, slug, url }`, or `undefined` for any other response, and never redirects. Use it in a response interceptor to update stored slugs or links:

```ts
import { getSentryProjectRename } from "@sentry/api";

sentry.client.interceptors.response.use((response, request) => {
  const rename = getSentryProjectRename(request, response);
  if (rename) console.info(`Project ${rename.previousSlug} is now ${rename.slug}`);
  return response;
});
```

Browsers hide the target of an unfollowed (`redirect: "manual"`) redirect, so there only a followed redirect is reported.

### Linking to Sentry

To link to something in Sentry, use the URL the API returns instead of building one from the base URL and slugs. Those URLs account for how the deployment is set up, such as organization subdomains or a self-hosted URL prefix:

- Issues have `permalink`, the issue's page in Sentry.
- AI conversations have `webUrl`, the conversation's page in Sentry.
- Organizations have `links.organizationUrl`, the organization's base URL, and `links.regionUrl`, the base URL of its region's API. `regionUrl` is what a `resolveBaseUrl` like the one above returns.
- External issues also have a `webUrl`, but it links to the issue in the other tool, not to Sentry.

```ts
const { data: organization } = await sentry.getOrganization({
  path: { organization_id_or_slug: "my-org" },
  throwOnError: true,
});
console.log(organization.links.organizationUrl, organization.links.regionUrl);
```

### Preparing a raw request

Use `sentry.client.prepareRequest` when a consumer needs to inspect a request
or send it through its own raw transport. It shares the preparation used by
ordinary SDK requests: instance and per-call configuration, authentication,
validation, body serialization, and request interceptors.

```ts
const sentry = createSentryClient({ baseUrl: "https://example.test/sentry" });
const request = await sentry.client.prepareRequest({
  method: "GET",
  url: "/organizations/example/events/?field=id&field=title&cursor=old#view",
  query: { cursor: "opaque-next", per_page: 50 },
});
// Both field values remain; the old cursor is replaced and the fragment removed.
const response = await fetch(request);
// The consumer owns status handling and reading the raw body.
```

Preparation does not call the configured `fetch` or parse a response. Auth
providers, validators and request interceptors still run and can have side
effects; their errors reject unchanged. The returned native `Request` includes
the resolved options and request-interceptor changes. Its signal remains linked
to the caller's unless an interceptor replaces or clears it. Send it directly
with the chosen transport; calling `client.request` again would repeat preparation.
Reading `request.clone()` leaves its body available for dispatch. A custom fetch or
browser adapter can still add credentials, CSRF headers or routing at dispatch.

For endpoints with an existing query, serialized query keys replace all existing
occurrences of those keys. Explicit `null` input keys also remove existing values,
even with custom serializers; the serialized output can then add them back.
Unrelated repeated parameters and their encoding are retained, as is custom
query-serializer output. With the default serializer, `null` replaces the
original values with a bare key, while `undefined` leaves them unchanged.
Literal URL fragments are removed; encoded `%23` values are retained. These
rules also apply to ordinary requests through the same URL builder.

Use `bodySerializer: null` for an already serialized string, `FormData`, or
another native body. For `FormData`, also clear the default JSON content type
with `headers: { "Content-Type": null }` so `Request` supplies its boundary.
Otherwise the configured serializer still applies. Native
`Request` construction can add a content type for strings or form data; prepared
headers describe that request, not a consumer's earlier input or redacted preview.

Pass decoded server cursors and explicit page sizes as query parameters. The SDK
does not interpret bookmark formats, select navigation directions or store
history. Existing custom transports accepted by generated operations do not
have to implement `prepareRequest`; the factory's concrete transport adds it.

### Cancellation and custom fetch

Reuse the client and supply an `AbortSignal` for each operation. The caller owns the signal, whether it comes from a command, an MCP tool call, or a query library:

```ts
const controller = new AbortController();
const pending = sentry.listOrganizations({
  signal: controller.signal,
  throwOnError: true,
});

// When this operation is no longer needed:
controller.abort();
await pending; // Rejects with the cancellation reason by default.
```

Cancellation does not affect other calls sharing the client. Immediately before invoking `fetch`, the SDK checks the final request's signal, including changes made by request interceptors. An already-aborted signal prevents dispatch; authentication, validation, and request interceptors may still run before that check.

A configured `fetch` receives a native `Request`; its method, body, headers, and signal need not appear in a separate `init` argument. Forward the request intact and preserve native `RequestInit` override semantics when wrapping another transport:

```ts
const sentry = createSentryClient({
  baseUrl: "https://sentry.io",
  fetch: (input, init) => fetch(input, init),
});
```

Your transport must honor the signal while a request is in flight. The SDK cannot force an arbitrary custom fetch or asynchronous hook to stop, and cancellation does not undo a server mutation that has already completed.

Cancellation follows the [error handling contract](#error-handling): before dispatch the SDK uses `signal.reason`; during fetch it preserves the transport's rejection, which may differ by runtime. By default this is returned as `{ error, request, response: undefined }`, or thrown with `throwOnError: true`. Error interceptors can intentionally map it. Cancellation during response body reading rejects unchanged, even in fields mode. There is no SDK-specific cancellation error class.

### Uploading files to Objectstore

`@sentry/api/client` exports an Objectstore client for the service that upload-options endpoints such as `snapshots/upload-options/` return. `findExistingObjects` checks keys with batched HEAD requests; `putObjects` sends uploads up to 1 MB in batched multipart requests and PUTs larger ones individually. Batches hold up to 1000 operations and 25 MB, with up to 4 in flight, so large uploads stay under the per-request rate limit of the Sentry proxy. The client uses only web-standard APIs: the host supplies each file's bytes and may supply `fetch`.

```ts
import { findExistingObjects, putObjects } from "@sentry/api/client";

const existing = await findExistingObjects(objectstore, keys, { fetch });
await putObjects(
  objectstore,
  files
    .filter((file) => !existing.has(file.key))
    .map((file) => ({ key: file.key, size: file.size, read: () => readFile(file.path) })),
  { fetch },
);
```

Failures throw `ObjectstoreError`, an `ApiError` with the failing object or request `url`.

## Runtime validation

The root `@sentry/api` entry imports no other package at runtime, and neither do `@sentry/api/browser`, `@sentry/api/operations`, and `@sentry/api/docs`. It provides the API client and pure TypeScript types without installing a validation library. Only `@sentry/api/client` imports a package, `p-limit`. It is a regular dependency, so npm installs it with `@sentry/api` even when you never import `/client`.

Valibot 1 runtime schemas are available through a separate optional entry point:

```bash
npm install @sentry/api valibot
```

```ts
import * as v from "valibot";
import { vGetProjectResponse } from "@sentry/api/valibot";

const project = v.parse(vGetProjectResponse, input);
```

Zod 4 runtime schemas are available through another optional entry point:

```bash
npm install @sentry/api zod
```

```ts
import { zGetProjectResponse } from "@sentry/api/zod";

const project = zGetProjectResponse.parse(input);
```

`valibot` and `zod` are optional peer dependencies. Install neither when you only need the generated client and TypeScript types, or install the validator used by your application. The `@sentry/api/valibot` entry requires Valibot 1; its optional peer uses a wildcard because npm applies peer constraints to the whole package, including consumers that never import this entry. The `@sentry/api/zod` entry requires Zod 4.6.6 or later.

Schemas nested in a top-level schema, such as object fields, carry their OpenAPI description: read it with `v.getDescription(vDeployResponse.entries.id)` or `zDeployResponse.shape.id.description`. Top-level Valibot schemas have no description pipe, so `v.pick`, `v.omit`, `v.partial` and `v.required` accept them; their description is in their JSDoc comment.

## Error handling

HTTP failures use `SentryApiError`, whether returned in `result.error` or thrown with `throwOnError: true`. It preserves the status, parsed `body`, exact `rawBody` text, `request`, and `response` (including headers). The transport reads the error body once; consumers do not need to clone or reread the response. Error bodies without valid JSON remain strings.

```ts
import { SentryApiError } from "@sentry/api";

const result = await sentry.listOrganizations();
if ("error" in result) {
  if (result.error instanceof SentryApiError) {
    console.log(result.error.status, result.error.body, result.error.rawBody);
    console.log(result.error.response?.headers.get("retry-after"));
  }
  throw result.error;
}
```

`error` is typed as `unknown`: a custom `fetch` or error interceptor can supply its own error. Fetch rejections, including cancellation, keep their original identity and have no HTTP response. They are returned or thrown according to `throwOnError`. Exceptions from serialization, validation, interceptors, or response body reading/decoding reject unchanged, even with `throwOnError: false`; that setting does not make a request exception-free.

### Error codes

Many Sentry errors have a `{"detail": {"code", "message", "extra"}}` body. For those, `SentryApiError` and its subclasses also have `code`, `detailMessage` (the body's `message`; `message` stays the error's own), and `extra`. Some endpoints put a string `code` at the top level instead, such as Seer's 402 `{"detail", "code", "denialReason"}`. Then `code` and `detailMessage` come from the body's `code` and `detail`, `extra` is empty, and the other fields stay on `body`. Other bodies leave the three fields unset. `code` is a `SentryErrorCode`: one of the `KnownSentryErrorCode` values, or any other string the server sends. The known codes come from the spec: the `SentryApiErrorBody` component, such as `sudo-required` or `sso-required`, and the `code` values operations document in their error responses, such as `seer_out_of_credits`. Map codes to your own copy with a `switch`, and fall back for codes you don't handle:

```ts
import { isSentryErrorCode, SentryApiError } from "@sentry/api";

function describeError(error: unknown): string {
  if (!(error instanceof SentryApiError)) return "Something went wrong.";
  switch (error.code) {
    case "sudo-required":
      return "Confirm your password to continue.";
    case "2fa-required":
      return "This organization requires two-factor authentication.";
    default:
      return error.detailMessage || "The request failed.";
  }
}

function loginUrlFor(error: unknown): unknown {
  // Narrows `error` to a SentryApiError with that code, `detailMessage`, and `extra`.
  return isSentryErrorCode(error, "sso-required") ? error.extra.loginUrl : undefined;
}
```

### Auth challenges

Some 401 and 403 responses ask the user to act in Sentry: `sso-required`, `sudo-required`, `superuser-required`, `staff-required`, `2fa-required`, `member-disabled-over-limit`, and `primary-email-verification-required`. The spec marks these codes with `x-sentry-auth-challenge`, and the SDK reads them from there. `getSentryAuthChallenge(error)` returns one as data, a `SentryAuthChallenge` with its `code`, `status`, `message`, and the code's string fields (`loginUrl` and `organizationSlug` for SSO, `orgSlug` for superuser, `username` for sudo and email verification, `next` for a disabled member). It returns `undefined` for any other error.

To handle challenges where requests are sent, wrap `fetch` with `withAuthChallenges`. On a challenge it calls `onAuthChallenge(challenge, request)`. Re-authenticate however your app does, then return `"retry"` to send the request once more, or `"fail"` to keep the challenge response. The SDK opens no UI and never redirects or reloads. Without the wrapper, nothing is retried. The wrapper keeps a copy of each request body to replay.

```ts
import { createSentryClient, withAuthChallenges } from "@sentry/api";

declare function confirmPassword(username: string | undefined): Promise<boolean>;

const client = createSentryClient({
  baseUrl: "https://sentry.example.com",
  fetch: withAuthChallenges(fetch, {
    async onAuthChallenge(challenge) {
      if (challenge.code === "sudo-required") {
        return (await confirmPassword(challenge.username)) ? "retry" : "fail";
      }
      return "fail";
    },
  }),
});
```

### Custom errors

HTTP errors are normalized **before** error interceptors run. Interceptors run in registration order, each receiving the preceding interceptor's result. Their returned or thrown value is preserved by operations and pagination; there is no second normalization pass.

```ts
sentry.client.interceptors.error.use((error, response, request) => {
  if (error instanceof SentryApiError) {
    // Return your application's existing error type here, if needed.
    return new Error(`API ${error.status}: ${request.method} ${request.url}`, {
      cause: error,
    });
  }
  // No HTTP response for a rejected fetch. Preserve cancellation/custom errors.
  return error;
});
```

To keep an existing error class, map to it in the interceptor. The SDK does not import your class. `getSentryApiErrorDetails` collects what such a class usually carries: `method`, `path`, `status`, `statusText`, the parsed `responseJSON` (only when the body was JSON), `responseText`, and a `summary` such as `GET /api/0/organizations/ 404`:

```ts
import { getSentryApiErrorDetails, SentryApiError, type SentryApiErrorDetails } from "@sentry/api";

class RequestError extends Error {
  readonly status?: number;
  readonly responseJSON?: unknown;
  readonly responseText?: string;

  constructor(details: SentryApiErrorDetails, options?: ErrorOptions) {
    super(details.summary, options);
    this.name = "RequestError";
    this.status = details.status;
    this.responseJSON = details.responseJSON;
    this.responseText = details.responseText;
  }
}

sentry.client.interceptors.error.use((error, _response, request) =>
  error instanceof SentryApiError ? new RequestError(getSentryApiErrorDetails(error, request), { cause: error }) : error,
);
```

Operations then return or throw a `RequestError` for HTTP failures; cancellations and fetch rejections pass through unchanged.

### Opt-in status narrowing

Every operation with documented error responses has a generated `narrowError_<operation>` wrapper. It narrows the default HTTP `SentryApiError` to the operation's status-to-body type map, preserving its metadata. These wrappers remain standalone functions; pass `sentry.client` to reuse the client configured above:

```ts
import { narrowError_getProject } from "@sentry/api";

const result = await narrowError_getProject({
  client: sentry.client,
  path: {
    organization_id_or_slug: "my-org",
    project_id_or_slug: "my-project",
  },
});

if (!result.ok) {
  if (!result.error.documented) {
    // Unexpected HTTP status.
    throw result.error;
  }

  switch (result.error.status) {
    case 403:
    case 404:
      throw result.error;
  }
}
```

Checking `documented` first separates the operation's finite HTTP error union from unexpected statuses. Within the documented branch, checking `status` narrows `body` to that response's schema. This is a schema-based type assertion, **not runtime payload validation**. Error bodies remain `unknown` where the source OpenAPI response has no schema. Ordinary operations set `documented: false`; only these opt-in helpers know the operation's status map.

These helpers reclassify base `SentryApiError` instances belonging to the operation's response, including ones returned by an interceptor. Other errors—including custom classes/subclasses, fetch failures, cancellation, and decoding/validation exceptions—reject unchanged. They are not used implicitly by operations or pagination. Consumers that own their error model should use ordinary operations instead.

### Migrating the 0.x response contract

- `responseStyle: "data"` is no longer accepted, including at initialization, `setConfig`, and per call. JavaScript callers receive a `TypeError` before a request is sent. Read `result.data` from the stable fields result instead.
- HTTP errors previously exposed a raw body; now read `error.body` after narrowing to `SentryApiError`. `error.rawBody` retains the original text.
- Successful results omit `error`; failed results include it even when the error value is falsy. Manual result fixtures must follow that shape. Use `"error" in result` rather than a truthiness check.
- Error interceptors receive normalized HTTP errors and chain their returned values. Pagination and `unwrapResult` no longer create another error or prepend a helper-specific message; their legacy `context` argument remains accepted.
- `narrowError_*` and `callWithTypedErrors` now narrow HTTP failures only. Other failures reject unchanged instead of becoming a synthetic transport `SentryApiError`. `SentryApiTransportError` remains a deprecated type alias, but is no longer part of `NarrowedResult`.

## Pagination

Sentry uses cursor-based pagination via `Link` headers. Choose one of three helpers on your configured client:

| Task | Method | Result |
| --- | --- | --- |
| Display one page, with previous/next navigation | `sentry.fetchPage.<operation>(options, cursor?)` | `{ data, response, nextCursor?, prevCursor? }` |
| Collect up to an item limit | `sentry.paginateUpTo.<operation>(options, { limit, ... })` | `{ data, stopReason, nextCursor?, continuation? }` |
| Explicitly collect pages eagerly | `sentry.paginateAll.<operation>(options, { maxPages?, startCursor? }?)` | `{ data, stopReason, nextCursor? }` |

`fetchPage` is available for operations whose schema declares a `cursor` query parameter. Collection helpers are available only when the operation's 200 response is an array. Compound response bodies remain intact. Ordinary operation methods such as `sentry.listOrganizations()` still make just one request.

All helpers reuse the instance's configuration and interceptors and can be destructured. They manage `cursor` separately from `query`, retaining your path, filters, and `signal` while invoking the configured operation. The SDK does not own page history or a response cache: the consumer keeps cursors in its URL, query cache, or persistent storage.

Pagination reads HTTP headers from the same fields contract. Helpers always reject on failure, preserving the exact error: `SentryApiError` for default HTTP failures, or the original custom error/cancellation. This is consistent whether `throwOnError` is enabled or disabled.

Generated collection helpers pass the same signal to every page operation. If it aborts between pages, the next page is not dispatched and the collection rejects; no partial collection is returned.

### Single page

```ts
const options = {
  path: { organization_id_or_slug: "my-org" },
  query: { query: "is:unresolved", limit: 25 },
};

const page = await sentry.fetchPage.listOrganizationIssues(options);
console.log(page.data, page.response.headers.get("X-Hits"));

if (page.nextCursor !== undefined) {
  const nextPage = await sentry.fetchPage.listOrganizationIssues(options, page.nextCursor);
  // Keep nextPage.prevCursor to navigate back when the user requests it.
}
```

Each page preserves its own raw `Response`, including status and headers. The transport has already read the body; use `page.data` for the parsed result. Code that constructs a `PaginatedResponse<T>` manually, such as test fixtures, must now supply its `response` field.

`readSentryResponseHeaders` reads the other headers Sentry list endpoints send: `X-Hits` and `X-Max-Hits` as numbers (omitted when missing or malformed), `X-Sentry-Direct-Hit` as a boolean, and the raw `Link` header. `parseSentryLinks` parses `Link` by `rel`, keeping each target's `href` and `results` flag as well as its cursor:

```ts
import { parseSentryLinks, readSentryResponseHeaders } from "@sentry/api";

const page = await sentry.fetchPage.listOrganizationIssues(options);
const { link, hits, maxHits, directHit } = readSentryResponseHeaders(page.response.headers);
const links = parseSentryLinks(link ?? null);
links.previous?.results; // false on the first page
links.next?.href; // the server's URL for the next page
```

### Bounded collection

```ts
const options = { path: { organization_id_or_slug: "my-org" } };
const batch = await sentry.paginateUpTo.listOrganizationIssues(options, {
  limit: 250,
  maxPages: 5,
});
// Requests 100 + 100 + 50 when the server returns full pages.
console.log(batch.data, batch.stopReason);

if (batch.nextCursor !== undefined) {
  const next = await sentry.paginateUpTo.listOrganizationIssues(options, {
    limit: 250,
    startCursor: batch.nextCursor,
  });
}
```

Automatic sizing is deliberately limited to operations whose forward cursors have been verified to support changing page size:

| Operation | HTTP size parameter | Maximum per request |
| --- | --- | --- |
| `listOrganizationIssues`, `listProjectIssues` | `limit` | 100 |
| `listOrganizationIssueEvents` | `per_page` | 100; 10 with `full: true` |

Each request uses the smallest of the remaining item budget, the caller's requested page size (if supplied), and the verified maximum. Other operations retain their query options unchanged. In particular, **projects do not use 100 + 100 + 50**: their backend `OffsetPaginator` includes the page size in its cursor, and resizing mid-traversal can skip rows. Declaring `per_page` in the schema is not enough to enable resizing.

If a server ignores the size or an operation cannot be resized, the helper trims any excess rows and omits the unsafe server `nextCursor`. It reports `stopReason: "limit"`, even if that was the server's last page. The separate `continuation` retains a position before the pending rows.

### Resume a partially consumed page

```ts
const options = {
  path: { organization_id_or_slug: "my-org" },
  query: { per_page: 100 },
};
const batch = await sentry.paginateUpTo.listOrganizationProjects(options, { limit: 250 });
// Requests three pages of 100 and returns 250 rows.
// nextCursor is absent: the next server page would skip the remaining 50.
if (batch.continuation) {
  const next = await sentry.paginateUpTo.listOrganizationProjects(options, {
    limit: 25,
    resume: batch.continuation,
  });
  // Refetches the third page unchanged and returns its next 25 rows.
}
```

`paginateUpTo` returns a `continuation` whenever more rows remain, including on the last server page. Pass it back as `resume`; do not combine it with `startCursor`. At a page boundary it contains the next opaque server `cursor` and `offset: 0`. Within a page it contains the cursor used to fetch that page (absent for the first page), the consumed `offset`, and the original `requestBudget`. It can round-trip through JSON. Keep the same operation, filters, page-size options and fetcher configuration. The SDK does not store credentials, requests or history in it.

For standalone `paginateUpTo(fetcher, options, context)`, the callback's second argument is a request budget. It normally equals the remaining item limit. On a partial replay it repeats the original budget so a custom fetcher reconstructs the same request, even when the new batch limit is smaller. After that page, the callback receives the new remaining budget. A callback must retain its own operation-specific sizing rules; the SDK never derives them from the cursor's contents.

The standalone collector also accepts a callback returning a normalized `{ data: T[], nextCursor? }` page, including the result of `fetchPage`. Such a callback owns response/error handling and rejects on failure; `request` and `error` are reserved for SDK operation envelopes. Its explicit `nextCursor` is authoritative; the collector does not reinterpret an attached `Response`. SDK operation results retain their existing unwrapping and error behavior. The exported `BudgetedPageFetcher` type is unchanged; `CollectionPageFetcher` describes this additional composition path.

```ts
import { paginateUpTo } from "@sentry/api";

const batch = await paginateUpTo(
  cursor => sentry.fetchPage.listOrganizationProjects(options, cursor),
  { limit: 250 },
  "listOrganizationProjects",
);
```

`nextCursor` keeps its existing meaning and can still be sent directly to the API. A `continuation` is SDK state, not a server cursor. Existing single-page, custom-bookmark and infinite-query consumers can continue using ordinary operations or `fetchPage`; neither API changes.

### Consume an already fetched page

For a consumer that owns fetching, `consumePage` shares the row-consumption logic without performing I/O or requiring a `Response`:

```ts
import { consumePage } from "@sentry/api";

const page = await sentry.fetchPage.listOrganizationProjects(options, cursor);
const consumed = consumePage(page, { cursor, offset: 0 }, 25);
// Keep page.response and any consumer metadata separately.
// consumed.position identifies where to continue; absence means exhausted.
```

To resume a position, fetch its cursor with the same page options and pass that position to `consumePage`. A manual `PagePosition` describes row consumption; `paginateUpTo` additionally records the request budget in its `PaginationContinuation`. The caller owns serialization, custom filtering/bookmarks and navigation history. Neither helper snapshots data against concurrent server changes.

### Eager collection and completion

```ts
const projects = await sentry.paginateAll.listOrganizationProjects(
  { path: { organization_id_or_slug: "my-org" } },
  { maxPages: 50 },
);
console.log(projects.data, projects.stopReason);
// If stopReason is "maxPages", projects.nextCursor resumes traversal.
```

Both collection helpers return `PaginatedCollection<TItem>`. Only `paginateUpTo` supplies the additional `continuation` described above:

| `stopReason` | Meaning | `nextCursor` |
| --- | --- | --- |
| `"exhausted"` | All fetched rows were returned and the server advertises no next page | Absent |
| `"limit"` | The item budget stopped collection | Present only when no rows were discarded |
| `"maxPages"` | The request cap stopped collection while more pages exist | Present |

Only `stopReason === "exhausted"` means complete. If the final server page exactly fills the item budget, exhaustion takes precedence. A missing cursor alone does not mean complete.

`maxPages` defaults to 50 for both helpers. `limit` and `maxPages` must be positive safe integers. Resume forward from a returned `nextCursor`, keeping the same operation, filters, and page-size options; cursors stay opaque. SDK calls do not retain a history or snapshot the collection against concurrent server changes. Errors and cancellation reject the collection call, including after earlier pages succeeded.

Collection results have no single `response`: their data may come from several HTTP requests. Frontend tables and infinite queries can keep using `fetchPage` with their own URL/cache state. CLI history, MCP output budgets, and TanStack adapters remain consumer integrations tracked in [#99](https://github.com/getsentry/sentry-api-schema/issues/99).

### Migration from earlier 0.x helpers

```ts
// Before: const projects = await sentry.paginateAll.listOrganizationProjects(options);
const { data: projects, stopReason, nextCursor } =
  await sentry.paginateAll.listOrganizationProjects(options);
```

`paginateAll` now returns a collection object instead of an array, for bound, standalone, and generic helpers. `paginateUpTo` adds `stopReason` and preserves safe continuation at `maxPages`. The unsafe `keepCursorOnOvershoot` option has been removed; no cursor may skip discarded rows. Invalid item/request budgets now reject before fetching.

### Standalone pagination

All existing imports remain available and share the same implementation and result types:

```ts
import { fetchPage_listOrganizationProjects } from "@sentry/api";

const page = await fetchPage_listOrganizationProjects({
  client: sentry.client,
  path: { organization_id_or_slug: "my-org" },
});
console.log(page.response.headers.get("Link"));
```

The corresponding `paginateUpTo_<operation>` and `paginateAll_<operation>` imports remain supported. Existing helpers accept `per_page` in their query options even where the schema omits it; choose page-size parameters supported by your endpoint.

### Generic pagination helpers

The same low-level helpers used by the generated wrappers are also exported for advanced use cases:

- `parseSentryLinkHeader(header)` — `{ nextCursor?, prevCursor? }`
- `unwrapResult(sdkResult, context)` — throw-on-error data unwrap
- `unwrapPaginatedResult(sdkResult, context)` — same but with cursors
- `fetchPage`, `paginateAll`, `paginateUpTo` — generic versions taking a fetcher thunk

A generic `paginateUpTo` fetcher receives `(cursor, remaining)`. Existing cursor-only fetchers still work; use `remaining` only when your endpoint's cursor supports resizing. The generated wrappers apply the verified rules above for you.

Generic helpers delegate cancellation to your fetcher. Pass its signal through to the operation or transport it invokes; the helper cannot cancel an arbitrary callback.

## Shared client

`@sentry/api/client` is the request layer the Sentry CLI and MCP servers share, built on the generated operations. It uses only web-standard APIs (`fetch`, `Request`, `Headers`, `URL`, `AbortSignal`, `crypto.subtle`), so it runs in Node, Cloudflare Workers, and browsers. Hosts inject what differs between them:

- **Transport.** `createApiTransport` sets `Authorization` from a `CredentialProvider`, refreshes the credential once after a 401 and replays the request, times out each attempt, follows redirects only to trusted origins, serves and invalidates cached GETs, and retries failed attempts when the host passes a `retry` policy. Without one it sends each request once. `CredentialProvider.current` receives the request URL and the organization and project its path targets (`parseApiPathScope`), so a host with several logins can pick the one that can reach that organization. The host passes credentials, a `TransportCache`, a `retry` policy, the request-scoped `fresh` hook, a logger, a span hook, and its error classes.
- **Request core.** `createApiClientCore` sends `<origin><API_BASE_PATH><path>` through the transport and throws the status's `ApiError` subclass for an error response. `sdkClient` gives a generated operation a client that sends through the same path.
- **Caching and retries.** The host owns its cache and retry policy and plugs them in through `TransportCache` and `retry`. The transport calls `retry(attempt, { method, url, idempotent, signal })` once per request, after the cache lookup and credential preparation. The hook calls `attempt()` as often as its policy allows and returns the final response. Each attempt keeps the transport's timeout, body buffering, and 401 refresh, and resolves with the response, failed or not, or throws, such as `ApiTimeoutError` for the transport's own timeout. The cache store, write invalidation, `errors.rateLimited`, and `errors.timeout` apply once, to the hook's result. `@sentry/http`'s `fetchWithRetry` fits it as is. The client gives them Sentry's rules: `classifyUrl` and `FALLBACK_TTL_MS` are the fallback TTL tiers for responses without freshness headers, `computeInvalidationPrefixes` lists the cached URL prefixes a write makes stale, `parseRetryDelayMs` reads the wait from `Retry-After` or `X-Sentry-Rate-Limit-Reset`, and `createIdempotentOperationMatcher` matches the writes Sentry marks safe to replay.
- **Validation.** Endpoint wrappers validate responses with any [Standard Schema](https://standardschema.dev) validator the host passes in, such as the `@sentry/api/zod` or `@sentry/api/valibot` schemas. The client depends on neither.
- **Pagination.** `paginate` and `fetchAllPages` walk list endpoints on top of `paginateUpTo` and `consumePage`. Their cursors are Sentry cursors that also record rows already returned from a page, so a resumed walk neither repeats nor skips rows.

`@sentry/api/client/endpoints` holds endpoint wrappers by domain. Each takes an `ApiTarget` (a core and an origin) and a response schema.

Every API error the core throws (`ApiError`, `ApiNotFoundError`, `ApiRateLimitError`, and the rest) extends `SentryApiError`, so `instanceof SentryApiError` matches failures from both the generated operations and the core.

In a browser, put the session fetch under the transport to keep cookie auth and CSRF injection:

```ts
import { createBrowserFetch } from "@sentry/api/browser";
import { createApiClientCore, createApiTransport } from "@sentry/api/client";

const transport = createApiTransport({
  fetch: createBrowserFetch(),
});
const core = createApiClientCore({ transport, headers: () => ({}), logger: console });
const projects = await core.requestJson("https://sentry.example.com", "/organizations/acme/projects/");
```

## Versions and upgrades

The package follows [semver](https://semver.org) and releases from getsentry/sentry as `api@<version>` tags. Each release's notes are in [CHANGELOG.md](./CHANGELOG.md) and on its [GitHub release](https://github.com/getsentry/sentry/releases).

- A merged change to Sentry's API spec releases a minor version automatically. Minor releases add operations, parameters and fields. They can also change a type to match what the API already returns.
- A change to the package itself releases the bump its commits call for: a feature is a minor and a fix is a patch. Release a breaking change by hand, as a major, with the Release workflow.
- Removing or renaming an export, including a generated operation, is a breaking change and waits for a major release.

### Upgrading

Within a major version, upgrading keeps your calls working. Rerun your typecheck anyway: since the types follow the API, a type that now matches the server can surface a mismatch in your code. For a new major, read the CHANGELOG's Breaking Changes for every major in between.

Release candidates, when there are any, publish under the `next` tag: `npm install @sentry/api@next`. See [Release candidates](#release-candidates).

### Deprecations

When Sentry deprecates an API endpoint (`deprecated=True` in its `extend_schema`), the endpoint keeps working. Its operation function and client method get a `@deprecated` tag, so editors strike through the calls, and it has `deprecated: true` in `@sentry/api/operations` and `@sentry/api/docs`. To list the deprecated operations:

```ts
import { operations } from "@sentry/api/operations";

const deprecated = operations.filter(operation => operation.deprecated).map(operation => operation.functionName);
```

Deprecate a package export with a `@deprecated` tag that says what to use instead. Deprecated operations and exports stay until the next major release.

### Release candidates

To ship a risky change, such as a new major version, as a release candidate first:

1. Run getsentry/sentry's [Release workflow](https://github.com/getsentry/sentry/actions/workflows/release.yml) with workspace `static/packages/api` and an exact prerelease version, such as `3.0.0-rc.0`.
2. It publishes to npm under the `next` tag, so `latest` stays on the last stable release, and the GitHub release is marked as a prerelease.
3. While a prerelease is the latest `api@` release, merged spec changes don't release automatically. Cut the next candidate, such as `3.0.0-rc.1`, the same way.
4. To release the stable version, run the workflow with it, such as `3.0.0`. Automatic releases resume after that.

## Spec files

Each `api@<version>` release on [GitHub](https://github.com/getsentry/sentry/releases) has the files that version was built from as assets:

- `openapi-derefed.json`: the dereferenced OpenAPI spec.
- `api_ownership_stats_dont_modify.json`: API ownership stats per team. They are kept for ad-hoc and future use; no known consumer reads them, so a change to them alone does not cut a release, and they refresh with the next one.
- `rpc_method_schema.json`: the internal RPC method schema.

For example, `https://github.com/getsentry/sentry/releases/download/api@2.4.0/openapi-derefed.json`. They are not in the npm package.

## Development

The package lives in [`getsentry/sentry`](https://github.com/getsentry/sentry/tree/master/static/packages/api), next to the API it describes, and builds from the spec that repository generates. Schema fixes go to the endpoints in `src/sentry`; build and tooling changes go here. From the repository root:

```sh
make build-api-docs build-rpc-schema
pnpm --filter @sentry/api run build
pnpm --filter @sentry/api run typecheck
pnpm --filter @sentry/api run lint:js
pnpm --filter @sentry/api run test:vitest
```

Tests import the generated `src/`, `dist/` and `spec/` output, so build before testing. The script is `test:vitest`, not `test`, because the repository's `test-ci` and `test-all` pass Jest options to every workspace's `test` script, and these tests need the spec build.

Every `ts` example in this README is typechecked against the packed package by `test/readme.test.ts`, each as its own module. When an example uses a value it doesn't define, such as `sentry` or `options`, declare it in that test's `context`.

To check the packed package the way an outside project uses it, pack it and run `test/consumers/check.mjs` with each runtime to check. CI runs it on Node.js 22 and Bun. It installs the tarball into fresh projects from the npm registry, with no optional peers and then with each validator peer:

```sh
pnpm --filter @sentry/api pack --out /tmp/sentry-api.tgz
node static/packages/api/test/consumers/check.mjs /tmp/sentry-api.tgz
```

CI also runs `test/consumers/exports.mjs` on the same tarball. It fails when an entry point or export of the latest `@sentry/api` on npm is gone, since that breaks code written against the release. A renamed operation counts as a removed one. A breaking change, marked `type(scope)!:` in the PR title or a `BREAKING CHANGE:` footer, releases as a major, so the check lists its removals without failing.

## License

FSL-1.1-Apache-2.0. See [LICENSE.md](LICENSE.md).
