> ## Documentation Index
> Fetch the complete documentation index at: https://sferadev.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# cloudflare-api-js

> Type-safe Cloudflare API client

A type-safe API client for the [Cloudflare API](https://developers.cloudflare.com/api/), auto-generated from the official OpenAPI specification with full TypeScript support.

## Features

* **Type-Safe** - Full TypeScript support with auto-generated types from OpenAPI spec
* **Complete API Coverage** - All Cloudflare API endpoints supported
* **Auto-Updated** - Daily regeneration from upstream OpenAPI specs

## Installation

<CodeGroup>
  ```bash pnpm theme={null}
  pnpm add cloudflare-api-js
  ```

  ```bash npm theme={null}
  npm install cloudflare-api-js
  ```

  ```bash yarn theme={null}
  yarn add cloudflare-api-js
  ```
</CodeGroup>

## Usage

### Basic Usage

```typescript theme={null}
import { createClient } from "cloudflare-api-js";

const client = createClient({
  baseUrl: "https://api.cloudflare.com/client/v4",
  headers: {
    Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`,
  },
});

// List zones
const zones = await client.listZones();

// Get DNS records for a zone
const records = await client.listDnsRecords({
  zoneId: "your-zone-id",
});

// Create a DNS record
const newRecord = await client.createDnsRecord({
  zoneId: "your-zone-id",
  body: {
    type: "A",
    name: "example.com",
    content: "192.0.2.1",
  },
});
```

### With API Key Authentication

```typescript theme={null}
import { createClient } from "cloudflare-api-js";

const client = createClient({
  baseUrl: "https://api.cloudflare.com/client/v4",
  headers: {
    "X-Auth-Email": "your-email@example.com",
    "X-Auth-Key": process.env.CLOUDFLARE_API_KEY,
  },
});
```

### Type Exports

```typescript theme={null}
import type { Types } from "cloudflare-api-js";

// Use TypeScript types
type Zone = Types.Zone;
type DnsRecord = Types.DnsRecord;
```

## API Reference

The client exposes all Cloudflare API endpoints including:

* **Zones** - Manage DNS zones
* **DNS Records** - Create, update, and delete DNS records
* **Workers** - Deploy and manage Cloudflare Workers
* **Pages** - Cloudflare Pages projects and deployments
* **R2** - Object storage management
* **KV** - Key-Value storage operations
* **D1** - SQL database operations
* **Firewall Rules** - Security and firewall configuration
* **Load Balancers** - Traffic management
* **And more...**

For the complete API reference, see the [Cloudflare API documentation](https://developers.cloudflare.com/api/).
