openapi:generate CLI and serves the spec at /api/openapi.json. If you only want the file — generated at build time, hosted like any other static asset — turn the runtime endpoint off with serve: false.
Turn off the runtime endpoint
payload.config.ts
serve: false the plugin mounts neither the spec endpoint nor the interactive-auth endpoint.
Generate into your static assets
Write the file wherever your app serves static files —public/ in a Next.js project:
--server explicitly: a file on disk has no request to read the Host header from, so the base URL must come from you (see the CLI reference).
Now public/openapi.json is served at /openapi.json like any other static file — through Next.js, a CDN, nginx, or committed to the repo. There is no per-request work and no way to hit a stale or unauthenticated spec at runtime.
Point the docs UI at the file
The docs UI plugins load the spec from a URL, and that URL does not have to be the plugin’s own endpoint. PointspecEndpoint at your static file and the UI renders it directly:
payload.config.ts
swaggerUi(). See Docs UI for the renderer options.
Multiple languages
Generate one file per supported language with--lang all:
public/ and wire a language switcher exactly as in Internationalization — just point Scalar’s sources at the static files instead of the runtime endpoint:
payload.config.ts
See also
- Generate command — all flags, plus a CI diff example
- Docs UI — Scalar and Swagger UI options
- Caching — what the default runtime endpoint actually costs