Skip to main content
The Cloudflare SDK provides flexible configuration options for customizing client behavior, authentication, network settings, and more.

Basic initialization

Create a new Cloudflare client with your API token:
The SDK automatically reads the CLOUDFLARE_API_TOKEN environment variable if no apiToken is provided.

Authentication methods

The SDK supports multiple authentication methods:

Configuration options

The ClientOptions interface provides comprehensive configuration:
string
API token for authentication (reads from CLOUDFLARE_API_TOKEN by default)
string
Global API key for legacy authentication
string
Email address used with Global API key
string
Service key for Origin CA certificates API
string
default:"https://api.cloudflare.com/client/v4"
Override the default base URL for the API
string
Define the API version to target for requests (e.g., “2025-01-01”)
number
default:"60000"
Maximum time in milliseconds to wait for a response (default: 1 minute)
number
default:"2"
Maximum number of retry attempts for failed requests
Agent
Custom HTTP(S) agent for managing connections
Fetch
Custom fetch function implementation
Headers
Default headers included with every request
DefaultQuery
Default query parameters included with every request

Custom base URL

Override the API endpoint for testing or alternative environments:
You can also use the CLOUDFLARE_BASE_URL environment variable:

HTTP agent configuration

Configure a custom HTTP agent for proxy support or connection pooling:
By default, the SDK uses a stable agent to reuse TCP connections, eliminating handshakes and improving performance.

Custom fetch implementation

Provide a custom fetch function for logging, middleware, or alternative implementations:

Fetch shims

The SDK uses node-fetch in Node.js by default. To use the global web-standards fetch:
To explicitly use Node.js polyfills:

Default headers and query parameters

Add custom headers or query parameters to all requests:
You can remove default headers in individual requests by setting them to undefined or null.

Debug logging

Enable automatic request/response logging:
Debug logging is intended for development only and may change without notice.