Skip to main content

Cloudflare TypeScript SDK

The official TypeScript library for the Cloudflare API provides convenient, type-safe access to Cloudflare’s REST API from server-side TypeScript or JavaScript applications.
This SDK requires TypeScript >= 4.5 and Node.js 18 LTS or later. It also supports Deno, Bun, Cloudflare Workers, and other modern JavaScript runtimes.

Why use this SDK?

Type-safe SDK

Full TypeScript definitions for all request parameters and response fields with autocomplete support in modern editors.

Auto-pagination

Automatically fetch all pages using for await...of syntax or manually control pagination with convenience methods.

Automatic retries

Built-in retry logic with exponential backoff for network errors and rate limits (2 retries by default).

Multiple authentication methods

Support for API tokens, API key + email, and user service keys with automatic header management.

File uploads

Upload files using multiple formats: File, fs.ReadStream, fetch Response, or the toFile helper.

Comprehensive error handling

Typed error classes for different HTTP status codes with access to status, headers, and response details.

Multi-runtime support

Works in Node.js, Deno, Bun, browsers, Cloudflare Workers, Vercel Edge Runtime, and more.

Custom middleware

Intercept requests and responses with custom fetch functions for logging, monitoring, or modifications.

Quick example

Get started with just a few lines of code:
import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'],
});

const zone = await client.zones.create({
  account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
  name: 'example.com',
  type: 'full',
});

console.log(zone.id);

Next steps

Installation

Install the SDK using npm, yarn, pnpm, or bun

Quick start

Make your first API call in under 5 minutes

Authentication

Configure API tokens and other auth methods

API Reference

Explore the full Cloudflare API documentation

Build docs developers (and LLMs) love