Why proxy?
When using Client Credentials authentication, the token is a service-account token with access to all data within the same API Client. Exposing it in a browser means any user could access any other user’s data. Best practice: use the SDK on the backend only, and call your own backend endpoints from the frontend. If you need the SDK in the browser, proxy through your server so credentials never leave the backend.Proxy with baseUrl
The baseUrl option redirects all SDK traffic to your proxy. The SDK keeps its types, endpoint paths, and serialization logic — only the host changes.
Example
JavaScript
Proxy with custom environment URLs
For fine-grained control, provide a full environment object that specifies where each type of request should go:JavaScript
Example
JavaScript
What your proxy needs to do
- Forward requests to the corresponding Corti API endpoints
- Handle authentication — add tokens, validate permissions
- Implement access control — filter data based on the current user
- Return responses unchanged — the SDK expects the same response shape as the Corti API
WebSocket proxy with CortiWebSocketProxyClient
For WebSocket-only proxy scenarios (no REST), the SDK provides a lightweight client that skips environment and auth configuration entirely.
Proxy options
| Option | Type | Required | Description |
|---|---|---|---|
url | string | Yes | WebSocket URL of your proxy |
protocols | string[] or object | No | WebSocket subprotocols. Arrays are passed as-is; objects are encoded as header pairs |
queryParameters | Record<string, string> | No | Query parameters appended to the WebSocket URL |
Benefits
- Configuration handshake handled automatically (
CONFIG_ACCEPTEDwait) - Built-in reconnection with configurable backoff
- Full TypeScript types for all message events
- No environment, tenant, or auth configuration required
Encoding headers as WebSocket protocols
When using the sameCortiClient for both REST and WebSocket through a proxy, browsers cannot send custom HTTP headers on the WebSocket handshake. The encodeHeadersAsWsProtocols option encodes your client headers as WebSocket subprotocol pairs instead:
JavaScript
Sec-WebSocket-Protocol, splits by comma, and pairs consecutive values as header name/value.
If you only use WebSocket through a proxy (e.g. with
CortiWebSocketProxyClient) or don’t need the same headers on WebSocket, pass protocols directly in the proxy option instead.Scoped tokens
If proxying is not an option, you can issue scoped tokens that restrict frontend access to specific WebSocket endpoints. See the Scoped Tokens section in the Authentication Guide for details.Resources
- Proxy example — working proxy implementation
- Authentication Guide — all SDK auth flows
- Security best practices — credential management guidance
For support or questions, reach out through help.corti.app