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:- API Token (Recommended)
- Global API Key
- User Service Key
Configuration options
TheClientOptions 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 implementationHeaders
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: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 customfetch function for logging, middleware, or alternative implementations:
Fetch shims
The SDK usesnode-fetch in Node.js by default. To use the global web-standards fetch:
Default headers and query parameters
Add custom headers or query parameters to all requests:undefined or null.