A backend server is required when you need to:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tkhq/sdk/llms.txt
Use this file to discover all available pages before exploring further.
- Keep your organization’s API keys off the client
- Perform admin operations (creating sub-organizations, sending OTPs, validating sessions)
- Gate which Turnkey API methods the browser can call
Setting up the Turnkey server client
Install@turnkey/sdk-server:
terminal
Turnkey class with your organization credentials:
server/turnkey.ts
apiClient() on the instance to get a fully typed client that signs requests with your API key:
Environment variables
The following variables are required by@turnkey/sdk-server:
.env
Proxy handlers
The proxy handlers let the browser call Turnkey API methods through your server without exposing your API key. The server signs the request before forwarding it to Turnkey.Express
server/express.ts
Next.js API routes
pages/api/proxy.ts
allowedMethods configuration
The allowedMethods array in TurnkeyProxyHandlerConfig restricts which Turnkey API method names the proxy will forward. Any method not in this list receives a 401 Unauthorized response.
Default allowed methods when allowedMethods is omitted:
Server actions reference
Theserver object exported from @turnkey/sdk-server provides high-level actions that wrap common Turnkey API calls. These are designed for use in Next.js Server Actions ("use server").
createSuborg
createSuborg
Creates a new sub-organization (user account) with an associated wallet.The default wallet includes one Ethereum account (
DEFAULT_ETHEREUM_ACCOUNTS) and one Solana account (DEFAULT_SOLANA_ACCOUNTS). Override this with customAccounts.sendOtp
sendOtp
Sends an OTP to an email address or phone number.
verifyOtp
verifyOtp
Verifies an OTP code and returns a
verificationToken.oauthLogin
oauthLogin
Exchanges an OIDC token for a Turnkey session.
getSuborgs
getSuborgs
Looks up sub-organization IDs by a filter (email, phone, OIDC token, or public key).
getOrCreateSuborg
getOrCreateSuborg
Looks up a sub-organization and creates one if it does not exist. Useful for sign-up / log-in flows that require a single call.
How the proxy works
Browser sends a request
The
@turnkey/react-wallet-kit client sends a POST request to your proxy endpoint with a { methodName, params } body.Server validates the method
expressProxyHandler or nextProxyHandler checks that methodName is in allowedMethods. Unlisted methods are rejected with 401 Unauthorized.Server signs and forwards
The handler calls
apiClient()[methodName](...params), which stamps the request with your organization’s API key and sends it to https://api.turnkey.com.