Skip to content

feat!: call the API under /api/v1 - #2359

Merged
fforootd merged 11 commits into
claude/api-v1-serverfrom
claude/api-v1-clients
Nov 1, 2026
Merged

fforootd merged 11 commits into
claude/api-v1-serverfrom
claude/api-v1-clients

Conversation

@fforootd

@fforootd fforootd commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

Every first-party client calls the resource API under /api/v1. The server keeps answering the root paths, deprecated, until 1.0.0.

  • @zitadel/api. The generated operations call getApiBaseUrl(): the proxy path or server URL, then API_PREFIX. apiBaseUrl(base) strips trailing slashes and keeps a single prefix when the base already ends in it. customFetch says, on a 404 req.not_found, that a server older than the client does not serve the API under /api/v1. Through createZitadelClient / configureZitadel this moves the components, the SDKs' browser calls, the CLI, the test kit, the docs samples and Storybook.
  • Hand-built calls.
    • @zitadel/sdk-core: the opaque-session check, the shared-session retire probe and its revoke; the check's log names a req.not_found answer.
    • @zitadel/sdk-next: getSession() reads {proxyPath}/api/v1/sessions/me, with the same hint.
    • CLI: the local admin's session exchange.
    • @zitadel/testing: the flow calls of seedSession().
    • The console's dev-real scripts and the journey lane's session read.
    • The root probes the CLI and the test kit wait on stay at the root.
  • CLI. zitadel api builds <server>/api/v1/<spec path> (also for --dry-run and --curl), takes a path typed with the prefix, and its req.not_found hint names a server from before the move. The v2 dev-proxy migration from feat: accept /api/v1 paths in the SDK and dev-proxy gates #2357 becomes infrastructure wiring, Vite and Angular alike: from this release a v2 proxy breaks sign-in, so zitadel doctor fails on it until zitadel doctor --fix. SKILL.md says where the API lives and how zitadel api treats the prefix.
  • Console. The API base is "" under the dev server too, as in the build. The Vite proxy forwards /api/v1 unchanged instead of stripping /api. A VITE_CONSOLE_API_BASE still goes in front of the /api/v1, and the proxy strips it. Specs and MSW handlers use /api/v1, and the shared MSW server still fails any request no handler answers. The embedded e2e lane's "never an /api prefix" test becomes "every API call is under /api/v1", restricted to same-origin fetch/XHR, since the root still answers and only this would notice a call there. AGENTS.md, README, console ADR 0002/0003 and the e2e README follow.
  • Cloud. The cloud functions read /users/me and /users/me/teams under the prefix. The console's cloud add-on points the sign-in widget at /cloud/zitadel, so the widget calls /cloud/zitadel/api/v1/…, which the functions forward unchanged; feat: accept /api/v1 paths in the SDK and dev-proxy gates #2357 makes their bot check read both spellings.
  • @zitadel/api-mock. Its Express routes (session exchange, session read and revoke, CSRF read, claim completion) answer both spellings, like the server; the MSW handlers were */… already. The conformance spec calls the prefix and checks the root spelling still answers.
  • Tests that pin URLs move to the prefix: CLI (resources, sign-in, claim-as-admin, origin, rollback, env, call/curl/request/api, api-coverage, setup's fake server), the components' session, logout and SSO specs, the six server SDKs' session paths, sdk-next's auth() and getSession(), sdk-nuxt, sdk-tanstack-start, sdk-qwik, the test kit's unit tests. The CLI docs test bans a bare /v1/ but allows /api/v1/.
  • Docs. The SDK proxy page (browser paths, an SPA's production proxy, doctor now failing on an older dev proxy), the API client page, @zitadel/api's and sdk-next's READMEs and sdk-next's SKILL.md. ADR 077 is Implemented, and the glossary, the API design guide and the resource map say the prefix shipped.

Validation

On this branch with the whole stack and main merged in (566d43e, and 4adc6b1 before #2358's docs fix):

  • moon ci :lint :typecheck :build :test: everything passes except server:test-postgres, which needs Docker (feat: serve the API under /api/v1 and deprecate the root paths #2358 ran the Postgres lane another way). Before 4adc6b1 it also failed on fixtures main added at the root paths and on CLI suites timing out under the load; after the fix, moon run of the failed tasks passes: sdk-next 254, sdk-nuxt 233, sdk-sveltekit 134, sdk-solid-start 135, sdk-qwik-router 134, sdk-tanstack-start 156, console 493 and lint, cloud-functions 67, and the 16 CLI suites (all pass when run alone).
  • Self-hosted: moon run e2e:journey -- --ci, against tarballs packed from this branch and installed from a local registry: all 13 lanes pass (next, nuxt, react, vue, angular, solid, svelte and qwik fresh apps, passkey, pre-existing next and nuxt, the test kit, remote https), and the cli:test it runs passes 5167 tests. The React lane, run again with --keep, left its local server's log: every API request is under /api/v1 (the CLI's setup, deploy and claim, the app's sign-up and sign-in, the console's claim page), and only /readyz at the root.
  • The binary: moon run server:build (console embedded), started with nothing but an address, a public base and a data directory. /api/v1/users/me answers 401 without Deprecation, /users/me 401 with Deprecation: @1792886400 and Link, /livez, /readyz and /api/v1/livez 200 without it, /api/v1, /api/v1/nope and /nope ADR 076's 404, and the embedded console's first API call is GET /api/v1/sessions/me.
  • Cloud: this branch's preview at 4adc6b1. The deployment checks cli (Preview), console (Preview) and schemas (Preview) pass; docs (Preview) failed on the playground tests main added, which feat: serve the API under /api/v1 and deprecate the root paths #2358 fixes (6a27e50, merged here). The preview's request log over the checks shows every first-party API call under /api/v1: the CLI suite's setup, deploy, variables, origins, rollback and claim, the cloud console's sign-up widget through /cloud/zitadel/api/v1/…, and the cloud functions' reads of /users/me and /users/me/teams. The only root-path calls are the probes of my own spot check. CI's full-pr passed at 4adc6b1.
  • Not run: the Spanner lane.

Release notes / changeset

  • Changeset: .changeset/clients-call-api-v1.md — @zitadel/api, @zitadel/cli, @zitadel/sdk-core, @zitadel/sdk-next, @zitadel/server (the console ships in it), @zitadel/testing minor. The SDKs, the components, the console and the CLI call the API under /api/v1. Breaking: upgrade a self-hosted server before its apps; run zitadel doctor --fix in an SPA an earlier setup scaffolded; a hand-written SPA production proxy must add the project secret to POST /api/v1/sessions/exchange; the root paths answer with Deprecation until 1.0.0.

Notes

  • After a review (2026-11-01): the console's dev proxy stripped the whole VITE_CONSOLE_API_BASE, so a base ending in /api/v1 (/api/v1, /gateway/api/v1) sent /api/v1/users/me to the server as /users/me, which only the deprecated root alias answered. devApiRoute (vite.config.ts) now reads the base with the client's apiBaseUrl and strips only what comes before the prefix; api-base.spec.ts pins five bases and a look-alike. The cloud functions' directory imports API_PREFIX too. Checked: moon run console:test console:lint console:typecheck api:test cloud-functions:test cloud-functions:typecheck cloud-functions:lint cli:typecheck cli:lint docs:typecheck (console: 499 passed) and the CLI's patcher and doctor tests.
  • @zitadel/api's published MSW handlers stay */…, so they match either spelling through 0.x.
  • The plan's opt-in guard in @zitadel/api-mock (fail a test whose API call is not under /api/v1) is not built. Every first-party call now goes through apiBaseUrl() or the generated client. The console's MSW server fails unhandled requests, the other suites pin exact URLs, and the embedded e2e lane checks the console in a real browser, so a missed call site fails a test today. Say if you still want the guard.
  • At GA (not here): remove the alias once its metric is near zero, drop the old spelling from the gates with a doctor migration, and revisit ADR 076's name-based routing.

🤖 Generated with Claude Code

fforootd and others added 2 commits October 26, 2026 00:16
Checking the proposal against the code showed that more moves than the
mount and the client base URL. The project secret, the SDKs' session-cookie
handling, the dev proxies the CLI writes and the production proxies the docs
describe all decide by exact path; so do the session no-store rule and the
audit's route fallback in the server.

The amendment keeps the probes in the spec and at the root for good, gives
the root alias a Deprecation header and a measure of its traffic, has every
path check accept both spellings until 1.0.0 (with a doctor --fix migration
for scaffolded proxies), and orders the rollout so every mix of versions
keeps working. The design docs say the prefix is accepted but not shipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every first-party client now calls the resource API under /api/v1
(ADR 077), which the server serves; the root paths keep answering,
deprecated, until 1.0.0.

- @zitadel/api: the generated operations call getApiBaseUrl(), the proxy
  path or server URL followed by API_PREFIX; apiBaseUrl() keeps a single
  prefix when a base already ends in it. A 404 req.not_found says the
  server may predate the prefix.
- Hand-built calls follow: sdk-core's session check, retire probe and
  revoke, sdk-next's getSession(), the CLI's local sign-in, the testing
  kit's flow calls and the console's dev-real scripts.
- CLI: zitadel api builds URLs with the prefix and accepts a path typed
  with it; the v2 dev-proxy migration becomes infrastructure wiring, so
  zitadel doctor fails on a v2 proxy until doctor --fix moves it to v3.
- Console: the API base is "" under the dev server too; the Vite proxy
  forwards /api/v1 unchanged. The embedded e2e lane now asserts every
  API call goes under /api/v1.
- api-mock answers its custom routes on both spellings, like the server.
- Tests that pin URLs, docs, SKILL.md and the console ADRs follow; ADR 077
  is Implemented and the design docs say the prefix shipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Nov 1, 2026 3:44am UTC

Request Review

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 160c81d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@zitadel/api Minor
@zitadel/cli Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/server Minor
@zitadel/testing Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-darwin-arm64 Minor
@zitadel/server-win32-x64 Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

fforootd and others added 2 commits October 26, 2026 09:52
The base of #2359: the client move needs both the path gates (#2357) and a server that serves /api/v1 (#2358). Re-merge either branch here when it changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2358's server, so CI and this branch's Vercel preview run against a server that serves /api/v1. The PR's base is that branch, so its diff is unchanged. When #2357 and #2358 have merged, rebase with: git rebase --onto origin/main claude/api-v1-gates-and-server

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd changed the base branch from claude/api-v1-path-gates to claude/api-v1-gates-and-server October 26, 2026 16:52
fforootd and others added 2 commits October 31, 2026 15:35
Stacks this PR on #2358 instead of the merge branch of #2357 and #2358,
and brings in main through them. Conflicts:

- ADR 077, its README row and the design docs keep this PR's
  "Implemented" and "shipped" wording, with #2356's new section 5 text
  and main's other edits to the resource map.
- The console's Vite config is main's, restructured for the cloud's
  add-on, with this PR's proxy for /api/v1; the test base moved to
  vitest.config.ts, which now names the origin. The console's specs that
  main added or changed call /api/v1, as the rest do.
- sdk-core's revokeSession (ADR 083, main) asks for the CSRF token and
  revokes under the prefix; its tests and the six server SDKs' tests take
  main's cookie names and this PR's prefixed URLs.
- The scaffold guidance, sdk-next's docs, the CLI's SKILL.md, the
  console README and src/api/zitadel.ts take main's text with this PR's
  /api/v1 paths. The CLI's local-server tests and console-real's
  response match take main's cases on the prefixed paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code main added since this PR was written still called the root paths:

- The hosted cloud's functions read /users/me and /users/me/teams
  from the server; they now read them under the prefix. The sign-in
  widget the console's cloud add-on points at them calls
  /cloud/zitadel/api/v1/..., which they forward unchanged, and #2357's
  bot check reads both spellings.
- Tests main added mock the server at the root: the CLI's policy,
  rollback, env add, preview list, setup deploy and issuer-origin
  tests, the console's releases and deployments specs, and the server
  SDKs' CSRF read before a sign-out revoke. They mock the prefix now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd changed the base branch from claude/api-v1-gates-and-server to claude/api-v1-server October 31, 2026 22:42
@fforootd
fforootd added this pull request to stack #2564 October 31, 2026 22:42
Brings in #2358's fix for the docs playground's session reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd marked this pull request as ready for review October 31, 2026 23:55
Copilot AI balanced review requested due to automatic review settings October 31, 2026 23:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-31T23:58:34.718441Z 566d43e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The breaking API migration spans roughly 70 files and hinges on runtime cross-package behavior and upgrade ordering that cannot be confirmed through static review alone.

No open issues 🎉

What changed in this PR

This is the final PR in a stacked series (#2356 → #2357 → #2358 → this) implementing ADR 077: every first-party client now calls the resource API under /api/v1, matching where the server (shipped in #2358) serves it. The server continues answering the old root paths, deprecated, until 1.0.0, so mixed client/server versions keep working (a self-hosted server must be upgraded before its apps). The change centers on a new apiBaseUrl()/getApiBaseUrl() helper in @zitadel/api that the generated client and every hand-built call now use; the rest is coordinated propagation through the SDKs, components, console, CLI, cloud functions, docs, ADRs, and a large set of pinned-URL tests.

Changes:

  • Add apiBaseUrl(base)/getApiBaseUrl() in @zitadel/api (strip trailing slashes, keep a single /api/v1) and wire the orval client, hand-built SDK/CLI/testing calls, and console/cloud-functions through it.
  • Surface a req.not_found hint ("server older than this client/SDK") in customFetch, sdk-core, sdk-next, and the CLI error/SKILL guidance; turn the scaffolded v2 dev-proxy from a doctor warning into a failure.
  • Flip the console dev proxy to forward /api/v1 unchanged (base now "" in dev too), update all MSW/e2e/test URLs, and mark ADR 077 Implemented across docs; add the @zitadel/* changeset.

Review notes: I verified the migration is complete (no non-test source still hand-builds a root API URL), the proxy/base/dual-serving logic is internally consistent, and the changeset correctly omits private packages (@zitadel/cloud-functions, @zitadel/api-mock). No blocking issues found. Correctness of the end-to-end wiring ultimately rests on the integration/e2e suites described in the PR, which can't be run here.

File Description
packages/​api/​src/​runtime/​base-url.ts New apiBaseUrl()/getApiBaseUrl() prefix helpers
packages/​api/​src/​runtime/​base-url.spec.ts Tests the prefix-once behavior across base shapes
packages/​api/​src/​runtime/​fetch.ts req.not_found 404 message naming the prefix
packages/​api/​src/​runtime/​fetch.spec.ts Tests the new 404 messaging
packages/​api/​orval.config.ts Generated client base switched to getApiBaseUrl()
packages/​api/​README.md Documents /api/v1 base and apiBaseUrl()
packages/​sdk-next/​src/​session.ts getSession() reads {proxyPath}/api/v1/sessions/me + hint
packages/​sdk-next/​src/​__tests__/​*, README.md, SKILL.md Prefix in tests/docs
packages/​sdk-core/​src/​middleware.ts Hand-built session probe/revoke use apiBaseUrl(); req.not_found undecided
packages/​sdk-core/​src/​middleware.spec.ts Prefix + older-server coverage
packages/​sdk-{nuxt,sveltekit,solid-start,qwik,qwik-router,tanstack-start}/​** Proxy test URLs moved to /api/v1 (source proxies forward unchanged)
packages/​components/​src/​orchestrator/​*.spec.ts Session/logout/SSO MSW URLs under /api/v1
packages/​testing/​src/​session.ts + tests flowFetch uses apiBaseUrl(); seed/bootstrap test URLs
packages/​api-mock/​src/​server.ts Express custom routes answer both spellings via apiPaths()
apps/​console/​vite.config.ts, src/​api/​zitadel.ts, api-base.spec.ts, vite-env.d.ts, vitest.config.ts, test-setup.ts, test/​msw.ts Base "", proxy forwards /api/v1 unchanged
apps/​console/​src/​routes/​**, components/​** specs MSW handler URLs moved to /api/v1
apps/​console/​scripts/​dev-real*.mts Dev-real seeding uses apiBaseUrl()
apps/​console/​README.md, AGENTS.md, docs/​adrs/​0002,0003 Console docs/ADRs updated
apps/​cloud-functions/​src/​zitadel.ts, sign-in.ts + specs API_PREFIX defined in zitadel.ts, directory reads under prefix
apps/​cli/​src/​lib/​api/​request.ts, operations.ts urlOf uses apiBaseUrl(); resolveTarget accepts prefixed paths
apps/​cli/​src/​lib/​local-server/​sign-in.ts, errors.ts Session exchange prefixed; error hint updated
apps/​cli/​src/​lib/​orca/​patchers/​rule/​{vite-support,angular}*, guidance*, react/​index.ts v2 proxy now infrastructure (doctor fails); guidance prefixed
apps/​cli/​tests/​unit/​** CLI test URLs, docs regex (?<!\/api)\/v1\/, doctor warn→fail
apps/​cli/​skills/​zitadel-cli/​SKILL.md Documents prefix handling for zitadel api
apps/​docs/​content/​docs/​sdks/​{proxy,api-client}.mdx SDK docs describe /api/v1
docs/​design/​{glossary,api/​*}.md, docs/​adrs/​README.md, 077-api-path-prefix.md ADR 077 marked Implemented/shipped
e2e/​console/​**, e2e/​journey/​src/​claim.spec.ts E2e assertions/probes under /api/v1
.changeset/​clients-call-api-v1.md Minor changeset for the affected published packages

Review effort: Balanced

fforootd and others added 2 commits October 31, 2026 17:53
Brings in #2358's spec checks and #2357's shared prefix. The cloud
functions' sign-in forwarder and directory both import API_PREFIX from
@zitadel/api now, so the constant this branch had added to zitadel.ts
goes; base-url.spec.ts keeps this branch's imports beside the new test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With VITE_CONSOLE_API_BASE=/api/v1 (or /gateway/api/v1) the client keeps a
single prefix, but the dev proxy stripped the whole configured base, so
/api/v1/users/me reached the server as /users/me: the deprecated root
alias answered, and would stop at 1.0.0. The proxy's route now reads the
base with the client's own apiBaseUrl and strips only what comes before
the prefix; the API-base spec pins it for five bases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fforootd added a commit that referenced this pull request Nov 1, 2026
Brings in the stack's shared API prefix, the spec checks and #2359's
console dev-proxy fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2357's build edge for the cloud functions' tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd added this pull request to the merge queue Nov 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue because a pull request earlier in the stack was removed Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit eb363f0 Nov 1, 2026
25 of 33 checks passed
@fforootd
fforootd deleted the claude/api-v1-clients branch November 1, 2026 03:58
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Nov 1, 2026
fforootd added a commit that referenced this pull request Nov 1, 2026
…-catalog-mock

Main serves the API under /api/v1 and routes only the server's own paths
to it in the cloud (#2356 to #2359, #2566):

- buildHTTPMux takes main's api.Servers and keeps this branch's cron
  triggers; a job no trigger runs leaves its path to the root alias.
- vercel.json and the cloud runbook route /cron/usage to the server, as
  /cron/events-retention, or the usage cron would reach the website.
- The functions' and the console's usage specs answer under /api/v1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fforootd added a commit that referenced this pull request Nov 5, 2026
Since #2359 the widget calls /cloud/zitadel/api/v1/flow…, but BotID's
client still marked /cloud/zitadel/flow…. The functions' checkBotId()
read every unmarked flow write as a bot and answered 403
auth.bot_suspected, so sign-in and sign-up failed on every cloud preview
before the first step loaded.

The paths now live in @zitadel/cloud-functions/contract, built with
apiBaseUrl(), the function the widget's client uses, and a test checks
that every path the client marks is one the functions check. Production
is unchanged: it still starts no BotID client and skips the hop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 160c81db Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants