Tutorials

Build a Typed Cloudflare API Client from Its OpenAPI Spec

Cloudflare publishes its full OpenAPI spec at cloudflare/api-schemas — a single bundled file covering the entire Cloudflare API surface: DNS, Zones, Workers, R2, Access, and dozens more products. Cloudflare already ships official, actively maintained SDKs for TypeScript, Python, Go, and Java, so this is for a language those don't cover, an internal wrapper scoped to one product, or agent tooling.

Where the spec lives

Fact Value
Repo cloudflare/api-schemas
File openapi.yaml (also openapi.json)
Default branch main
Spec version OpenAPI 3.0.3, info.version: 4.0.0
Size ~18.1 MB (YAML) / ~24.6 MB (JSON)
Paths 2,222
License BSD-3-Clause

How to fetch it

curl -sL -o cloudflare-openapi.yaml \
  https://raw.githubusercontent.com/cloudflare/api-schemas/main/openapi.yaml

Or clone the repo, which also includes common.yaml for shared schema components:

gh repo clone cloudflare/api-schemas

The honest complication: it's larger than GitHub's spec

GitHub's bundled OpenAPI file (covered in our GitHub post) is one of the largest specs in general circulation at ~9.9 MB. Cloudflare's is bigger — measured directly:

wc -c openapi.yaml    # 19,015,050 bytes (~18.1 MB)
grep -c "^  /" openapi.yaml   # 2,222 top-level paths

At roughly double GitHub's file size and covering 2,222 distinct paths across every Cloudflare product, the practical effects are the same pattern as GitHub's, just more pronounced:

  • Local codegen runs are slow — expect several minutes, and raise Node's heap (NODE_OPTIONS=--max-old-space-size=8192) if a generator runs out of memory on the full file.
  • Editors and diff tools struggle to open the raw YAML at all; work against the JSON variant or a filtered subset in most tooling.
  • Almost no integration needs the whole surface. Cloudflare doesn't ship a built-in way to slice the spec by product, so filter with a tool like openapi-filter down to the tags you actually use (dns_records, zones, workers_scripts, r2_buckets, and so on) before generating, or expect a very large generated package if you don't.

Test on a filtered subset first — generating the full 2,222-path spec is a legitimate multi-minute wait even on capable hardware.

Generate a TypeScript client locally

npx @openapitools/openapi-generator-cli generate \
  -i cloudflare-openapi.yaml \
  -g typescript-fetch \
  -o ./generated/cloudflare-client

For types only against a spec this size, openapi-typescript is noticeably faster than a full client generator:

npx openapi-typescript cloudflare-openapi.yaml -o ./src/cloudflare-api.d.ts

Validate first — see the free OpenAPI validator and OpenAPI best practices for SDK-friendly specs for what to check before committing generator time to a file this large.

The hosted path

Sourced takes Cloudflare's OpenAPI file directly — paste the raw spec URL or connect your repo — and produces hosted docs, a TypeScript SDK preview, a Python SDK preview, and an llms.txt file in one pass, without you managing local generator memory limits against an 18 MB file. Previews are free and unlimited, with up to two hosted noindex docs sites and one hosted MCP server, no credit card required.

When this actually makes sense

  • A language Cloudflare doesn't officially cover — the official list is TypeScript, Python, Go, and Java; Rust, Ruby, and others have no first-party client.
  • Scoping to one product. Most teams touch two or three Cloudflare products (say, DNS and Workers) — filtering the spec by tag before generating avoids shipping a client with 2,000+ unused methods.
  • Internal wrappers that need Cloudflare's types without the official SDK's specific auth and retry handling.
  • Agent tooling. A generated client, or an MCP server built from a filtered subset of the spec, gives an LLM agent typed tool calls scoped to the Cloudflare products it actually needs.

If you're writing a TypeScript, Python, Go, or Java app that talks to Cloudflare, use the official SDK for that language — it's maintained by Cloudflare and already handles auth token scoping and pagination correctly, which a generated client from a 2,222-path spec won't replicate by default.

FAQ

Does Cloudflare have an official OpenAPI spec?

Yes. cloudflare/api-schemas is Cloudflare's own public repository, licensed BSD-3-Clause, and covers the full API surface documented at developers.cloudflare.com.

Is the Cloudflare OpenAPI spec OpenAPI 3.0 or 3.1?

3.0.3.

Why is the Cloudflare spec so much bigger than GitHub's?

It's not just larger in byte count — it covers 2,222 distinct paths across every Cloudflare product (DNS, Zones, Workers, R2, Access, Load Balancing, and dozens more) bundled into one file, versus GitHub's already-large single-product-family spec.

Do I need to generate the whole spec, or can I filter it?

Filter it. Cloudflare doesn't ship a built-in slicing tool, but openapi-filter (or a similar tag-based filter) lets you generate only the tags for the products you use, which cuts both generation time and the size of the resulting client.

Should I generate a client instead of using Cloudflare's official SDK?

Not for TypeScript, Python, Go, or Java — use cloudflare-typescript, cloudflare-python, or the equivalent. Generate a client only for an uncovered language, a filtered internal wrapper, or agent tooling.

Can Sourced handle a spec this large without local setup?

Yes — see "The hosted path" above; Sourced processes the full Cloudflare spec in its pipeline without you tuning local generator memory settings. Previews are free and unlimited.