Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/api/configuration.md
1# Configuration23## Environment Variables45### Set Variables67| Platform | Command |8|----------|---------|9| Linux/macOS | `export CLOUDFLARE_API_TOKEN='token'` |10| PowerShell | `$env:CLOUDFLARE_API_TOKEN = 'token'` |11| Windows CMD | `set CLOUDFLARE_API_TOKEN=token` |1213**Security:** Never commit tokens. Use `.env` files (gitignored) or secret managers.1415### .env File Pattern1617```bash18# .env (add to .gitignore)19CLOUDFLARE_API_TOKEN=your-token-here20CLOUDFLARE_ACCOUNT_ID=your-account-id21```2223```typescript24// TypeScript25import 'dotenv/config';2627const client = new Cloudflare({28apiToken: process.env.CLOUDFLARE_API_TOKEN,29});30```3132```python33# Python34from dotenv import load_dotenv35load_dotenv()3637client = Cloudflare(api_token=os.environ["CLOUDFLARE_API_TOKEN"])38```3940## SDK Configuration4142### TypeScript4344```typescript45const client = new Cloudflare({46apiToken: process.env.CLOUDFLARE_API_TOKEN,47timeout: 120000, // 2 min (default 60s), in milliseconds48maxRetries: 5, // default 249baseURL: 'https://...', // proxy (rare)50});5152// Per-request overrides53await client.zones.get(54{ zone_id: 'zone-id' },55{ timeout: 5000, maxRetries: 0 }56);57```5859### Python6061```python62client = Cloudflare(63api_token=os.environ["CLOUDFLARE_API_TOKEN"],64timeout=120, # seconds (default 60)65max_retries=5, # default 266base_url="https://...", # proxy (rare)67)6869# Per-request overrides70client.with_options(timeout=5, max_retries=0).zones.get(zone_id="zone-id")71```7273### Go7475```go76client := cloudflare.NewClient(77option.WithAPIToken(os.Getenv("CLOUDFLARE_API_TOKEN")),78option.WithMaxRetries(5), // default 10 (higher than TS/Python)79option.WithRequestTimeout(2 * time.Minute), // default 60s80option.WithBaseURL("https://..."), // proxy (rare)81)8283// Per-request overrides84client.Zones.Get(ctx, "zone-id", option.WithMaxRetries(0))85```8687## Configuration Options8889| Option | TypeScript | Python | Go | Default |90|--------|-----------|--------|-----|---------|91| Timeout | `timeout` (ms) | `timeout` (s) | `WithRequestTimeout` | 60s |92| Retries | `maxRetries` | `max_retries` | `WithMaxRetries` | 2 (Go: 10) |93| Base URL | `baseURL` | `base_url` | `WithBaseURL` | api.cloudflare.com |9495**Note:** Go SDK has higher default retries (10) than TypeScript/Python (2).9697## Timeout Configuration9899**When to increase:**100- Large zone transfers101- Bulk DNS operations102- Worker script uploads103104```typescript105const client = new Cloudflare({106timeout: 300000, // 5 minutes107});108```109110## Retry Configuration111112**When to increase:** Rate-limit-heavy workflows, flaky network113114**When to decrease:** Fast-fail requirements, user-facing requests115116```typescript117// Increase retries for batch operations118const client = new Cloudflare({ maxRetries: 10 });119120// Disable retries for fast-fail121const fastClient = new Cloudflare({ maxRetries: 0 });122```123124## Wrangler CLI Integration125126```bash127# Configure authentication128wrangler login129# Or130export CLOUDFLARE_API_TOKEN='token'131132# Common commands that use API133wrangler deploy # Uploads worker via API134wrangler kv:key put # KV operations135wrangler r2 bucket create # R2 operations136wrangler d1 execute # D1 operations137wrangler pages deploy # Pages operations138139# Get API configuration140wrangler whoami # Shows authenticated user141```142143### wrangler.toml144145```toml146name = "my-worker"147main = "src/index.ts"148compatibility_date = "2024-01-01"149account_id = "your-account-id"150151# Can also use env vars:152# CLOUDFLARE_ACCOUNT_ID153# CLOUDFLARE_API_TOKEN154```155156## See Also157158- [api.md](./api.md) - Client initialization, authentication159- [gotchas.md](./gotchas.md) - Rate limits, timeout errors160- [Wrangler Reference](../wrangler/) - CLI tool details161