Skip to main content
The Decart provider can be configured with various options to customize its behavior. This guide covers all available configuration options for the createDecart() function.

Default Provider Instance

The simplest way to use the Decart provider is with the default instance:
This instance uses default settings and reads the API key from the DECART_API_KEY environment variable.

Custom Provider Configuration

For advanced use cases, you can create a custom provider instance with createDecart():

Configuration Options

All configuration options are optional and passed as properties of the settings object.

apiKey

string
API key for authenticating with the Decart API. If not provided, the provider will attempt to read from the DECART_API_KEY environment variable.
Example:
The API key is sent using the X-API-KEY header in all requests.

baseURL

string
default:"https://api.decart.ai"
Custom base URL for API requests. Useful for routing requests through a proxy server or using a different API endpoint.
Example:
Trailing slashes are automatically removed from the base URL.

headers

Record<string, string>
Additional HTTP headers to include in all API requests. These headers are merged with the default headers.
Example:
Custom headers will be merged with default headers. If you provide headers that conflict with default headers (like X-API-KEY), your custom values will take precedence.

fetch

FetchFunction
Custom fetch implementation to use for HTTP requests. This allows you to intercept requests, add middleware, or provide a custom fetch implementation for testing.
Type definition:
Example - Request Interceptor:
Example - Testing with Mock Fetch:

Complete Configuration Example

Here’s a complete example showing all configuration options together:

Environment Variables

The Decart provider automatically reads from environment variables: Example .env file:

User Agent

The provider automatically adds a User-Agent header to all requests with the format:
This helps Decart track SDK usage and version information.