Skip to content

feat: Read API host from WORKOS_API_HOSTNAME, WORKOS_API_PORT and WORKOS_API_HTTPS - #1767

Open
xgp wants to merge 2 commits into
workos:mainfrom
xgp:feat/api-host-env-vars
Open

xgp wants to merge 2 commits into
workos:mainfrom
xgp:feat/api-host-env-vars

Conversation

@xgp

@xgp xgp commented Nov 16, 2026

Copy link
Copy Markdown

Description

Closes #1766.

When the apiHostname, port and https options are not passed, the constructor now falls back to WORKOS_API_HOSTNAME, WORKOS_API_PORT and WORKOS_API_HTTPS, the same variables @workos-inc/authkit-nextjs reads, parsed the same way:

  • WORKOS_API_HTTPS: https only when the value is "true"; unset keeps the https default.
  • WORKOS_API_PORT: parseInt; unset means no port.

Constructor options still take precedence, and with none of the variables set the base URL is unchanged (https://api.workos.com). This lets an existing app, e.g. one that calls new WorkOS(process.env.WORKOS_API_KEY, { clientId }), run against @workos/emulate or a mock server by configuration alone.

Changes:

  • src/workos.ts: environment fallback for the three options.
  • src/workos.spec.ts: tests for the variables, precedence of constructor options, and the unset default.
  • README.md: a short note under Configuration.

npm run prettier, typecheck, lint on the changed files, test (1418 passed) and build all pass.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

…KOS_API_HTTPS

Falls back to the same environment variables @workos-inc/authkit-nextjs
reads when the apiHostname, port and https options are not passed, so an
app can be pointed at @workos/emulate or a mock server without code
changes. Constructor options still take precedence.

Closes workos#1766
@xgp
xgp requested review from a team as code owners November 16, 2026 21:55
@xgp
xgp requested a review from awolfden November 16, 2026 21:55
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous test-isolation issue is fixed.

Summary

The PR lets WorkOS read its API address from environment variables when constructor options are absent.

  • WorkOS clients can read their API destination from environment variables.

Reviews (2) · Last reviewed commit: "test: Clear API host environment variabl..." · Reviewed by Greptile

Comment thread src/workos.spec.ts Resolved
@xgp

xgp commented Nov 25, 2026

Copy link
Copy Markdown
Author

@awolfden Is this ready to go? This would be helpful to get in so that CI against a simulator doesn't need a code change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Read WORKOS_API_HOSTNAME / WORKOS_API_PORT / WORKOS_API_HTTPS from the environment, like authkit-nextjs

1 participant