getWorkOS returns a singleton instance of the WorkOS SDK client, pre-configured with your API key and environment settings. This is useful for accessing WorkOS APIs directly for advanced use cases.
Usage
Signature
Parameters
This function takes no parameters.Returns
The configured WorkOS SDK instance with access to all WorkOS APIs.
Examples
Listing organizations
Creating a new user
Sending a magic link
Getting organization details
Managing organization memberships
Updating user metadata
Custom email verification
Querying directory sync data
Creating audit log events
Checking SSO connection
Configuration
The WorkOS instance is configured using environment variables:WORKOS_API_KEY- Your WorkOS API key (required)WORKOS_API_HOSTNAME- Custom API hostname (optional, defaults toapi.workos.com)WORKOS_API_HTTPS- Whether to use HTTPS (optional, defaults totrue)WORKOS_API_PORT- Custom port (optional)
Notes
- The WorkOS instance is created lazily and cached as a singleton
- The same instance is reused across all calls to
getWorkOS() - The instance includes app info headers identifying it as
authkit/nextjs - All WorkOS SDK methods are available through this instance
- Use this for advanced use cases not covered by helper functions like
withAuth,handleAuth, etc. - The full WorkOS Node SDK documentation is available at workos.com/docs