Overview
TheDecartClientOptions type defines configuration options for creating a Decart API client. It supports two mutually exclusive modes: proxy mode and direct mode.
Type Definition
Configuration Modes
Proxy Mode
Use proxy mode when you want to route API requests through your own server. This is ideal for client-side applications where you don’t want to expose your API key. Key characteristics:proxyis requiredapiKeycannot be set (mutually exclusive)- Requests for process, queue, and tokens are routed through the proxy
- Realtime (WebRTC) connections still require direct API access
Direct Mode
Use direct mode for server-side applications or when you have secure API key management. Key characteristics:apiKeycan be provided (or usesDECART_API_KEYenvironment variable)proxycannot be set (mutually exclusive)- All requests go directly to Decart API servers
Fields
Proxy mode only. URL or path of the proxy server. Can be:
- Full URL:
https://your-server.com/api/decart - Relative path:
/api/decart
apiKey cannot be provided.Proxy mode only affects HTTP endpoints (process, queue, tokens). Realtime WebRTC connections always require direct API access with an API key.
Direct mode only. API key for authentication. Cannot be used with
proxy.If not provided, the client attempts to read from the DECART_API_KEY environment variable. In direct mode, an API key is required (either via this option or the environment variable).Override the default API base URL for HTTP endpoints (process, queue, tokens).In proxy mode, this field is ignored and the
proxy value is used as the base URL.Must be a valid URL string.Override the default WebSocket base URL for realtime connections.This is used for WebRTC signaling and must be a valid WebSocket URL (starting with
ws:// or wss://).Optional integration identifier for tracking and analytics purposes.This value is included in request headers and can be used to identify traffic from specific integrations or applications.
Custom logger instance for debugging and monitoring.You can use:
createConsoleLogger(level)- Built-in console logger with log levelsnoopLogger- No-op logger (default)- Custom implementation of the
Loggerinterface
Enable or disable telemetry reporting.Set to
false to opt out of sending anonymous usage data. Telemetry helps improve the SDK but is optional.Example:Examples
Proxy Mode Configuration
Direct Mode Configuration
Advanced Configuration
Validation
The SDK validates options using a Zod schema and enforces:- Mutual Exclusivity: Cannot provide both
proxyandapiKey - URL Format:
baseUrl,realtimeBaseUrl, andproxy(when full URL) must be valid URLs - Proxy Format:
proxycan be either a valid URL or a relative path starting with/ - API Key Requirement: In direct mode, either
apiKeymust be provided orDECART_API_KEYenvironment variable must be set
Error Examples
Proxy Mode vs Direct Mode Comparison
| Feature | Proxy Mode | Direct Mode |
|---|---|---|
| API Key Required | No | Yes (option or env var) |
| Process API | Via proxy | Direct to API |
| Queue API | Via proxy | Direct to API |
| Tokens API | Via proxy | Direct to API |
| Realtime API | Direct to API* | Direct to API |
| Use Case | Client-side apps | Server-side apps |
| Security | API key hidden | API key must be secure |
*Realtime WebRTC connections always require direct API access even in proxy mode, because WebRTC signaling happens over WebSocket connections that cannot be proxied in the same way as HTTP requests.
See Also
- createDecartClient() - Factory function reference
- Logger - Logger interface and utilities
- Error Codes - SDK error codes and handling