pi-cloudflare 0.10.2 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -180
- package/package.json +7 -42
- package/plugin.json +3 -3
- package/skills/agents-sdk/SKILL.md +17 -36
- package/skills/agents-sdk/references/client-sdk.md +7 -106
- package/skills/agents-sdk/references/human-in-the-loop.md +6 -63
- package/skills/agents-sdk/references/mcp.md +9 -184
- package/skills/agents-sdk/references/queue-retries.md +12 -73
- package/skills/agents-sdk/references/server-driven-messages.md +4 -60
- package/skills/agents-sdk/references/state-scheduling.md +10 -166
- package/skills/agents-sdk/references/streaming-chat.md +11 -193
- package/skills/agents-sdk/references/webhooks-push.md +2 -2
- package/skills/agents-sdk/references/workflows.md +14 -125
- package/skills/cloudflare/SKILL.md +135 -248
- package/skills/cloudflare/references/ai-gateway/README.md +17 -165
- package/skills/cloudflare/references/ai-gateway/configuration.md +14 -107
- package/skills/cloudflare/references/ai-gateway/dynamic-routing.md +12 -79
- package/skills/cloudflare/references/ai-gateway/features.md +22 -96
- package/skills/cloudflare/references/ai-gateway/sdk-integration.md +17 -112
- package/skills/cloudflare/references/ai-gateway/troubleshooting.md +14 -86
- package/skills/cloudflare/references/ai-search/README.md +17 -130
- package/skills/cloudflare/references/ai-search/api.md +10 -84
- package/skills/cloudflare/references/ai-search/configuration.md +16 -88
- package/skills/cloudflare/references/ai-search/gotchas.md +13 -81
- package/skills/cloudflare/references/ai-search/patterns.md +12 -82
- package/skills/cloudflare/references/analytics-engine/api.md +1 -1
- package/skills/cloudflare/references/api/README.md +2 -2
- package/skills/cloudflare/references/api/configuration.md +1 -1
- package/skills/cloudflare/references/bindings/README.md +11 -117
- package/skills/cloudflare/references/bindings/api.md +17 -201
- package/skills/cloudflare/references/bindings/configuration.md +20 -188
- package/skills/cloudflare/references/bindings/gotchas.md +16 -206
- package/skills/cloudflare/references/bindings/patterns.md +15 -195
- package/skills/cloudflare/references/bot-management/README.md +1 -1
- package/skills/cloudflare/references/browser-rendering/README.md +13 -73
- package/skills/cloudflare/references/browser-rendering/api.md +9 -105
- package/skills/cloudflare/references/browser-rendering/configuration.md +9 -75
- package/skills/cloudflare/references/browser-rendering/gotchas.md +12 -85
- package/skills/cloudflare/references/browser-rendering/patterns.md +9 -88
- package/skills/cloudflare/references/c3/README.md +6 -5
- package/skills/cloudflare/references/c3/api.md +3 -4
- package/skills/cloudflare/references/c3/patterns.md +4 -6
- package/skills/cloudflare/references/cache-reserve/README.md +1 -1
- package/skills/cloudflare/references/containers/README.md +15 -77
- package/skills/cloudflare/references/containers/api.md +13 -187
- package/skills/cloudflare/references/containers/configuration.md +15 -188
- package/skills/cloudflare/references/containers/gotchas.md +16 -178
- package/skills/cloudflare/references/containers/patterns.md +14 -198
- package/skills/cloudflare/references/cron-triggers/README.md +13 -92
- package/skills/cloudflare/references/cron-triggers/api.md +11 -191
- package/skills/cloudflare/references/cron-triggers/configuration.md +11 -175
- package/skills/cloudflare/references/cron-triggers/gotchas.md +13 -195
- package/skills/cloudflare/references/cron-triggers/patterns.md +12 -184
- package/skills/cloudflare/references/d1/README.md +9 -127
- package/skills/cloudflare/references/d1/api.md +16 -194
- package/skills/cloudflare/references/d1/configuration.md +16 -189
- package/skills/cloudflare/references/d1/gotchas.md +16 -96
- package/skills/cloudflare/references/d1/patterns.md +14 -183
- package/skills/cloudflare/references/do-storage/README.md +11 -70
- package/skills/cloudflare/references/do-storage/api.md +11 -99
- package/skills/cloudflare/references/do-storage/configuration.md +11 -107
- package/skills/cloudflare/references/do-storage/gotchas.md +12 -147
- package/skills/cloudflare/references/do-storage/patterns.md +11 -190
- package/skills/cloudflare/references/do-storage/testing.md +8 -178
- package/skills/cloudflare/references/email-routing/README.md +14 -84
- package/skills/cloudflare/references/email-routing/api.md +10 -192
- package/skills/cloudflare/references/email-routing/configuration.md +13 -186
- package/skills/cloudflare/references/email-routing/gotchas.md +12 -193
- package/skills/cloudflare/references/email-routing/patterns.md +10 -226
- package/skills/cloudflare/references/email-workers/README.md +13 -146
- package/skills/cloudflare/references/email-workers/api.md +12 -234
- package/skills/cloudflare/references/email-workers/configuration.md +14 -110
- package/skills/cloudflare/references/email-workers/gotchas.md +15 -125
- package/skills/cloudflare/references/email-workers/patterns.md +14 -100
- package/skills/cloudflare/references/flagship/README.md +2 -2
- package/skills/cloudflare/references/hyperdrive/README.md +17 -72
- package/skills/cloudflare/references/hyperdrive/api.md +19 -136
- package/skills/cloudflare/references/hyperdrive/configuration.md +27 -159
- package/skills/cloudflare/references/hyperdrive/gotchas.md +15 -72
- package/skills/cloudflare/references/hyperdrive/patterns.md +12 -187
- package/skills/cloudflare/references/images/README.md +9 -58
- package/skills/cloudflare/references/images/api.md +13 -96
- package/skills/cloudflare/references/images/configuration.md +17 -211
- package/skills/cloudflare/references/images/gotchas.md +16 -99
- package/skills/cloudflare/references/images/patterns.md +16 -115
- package/skills/cloudflare/references/kv/README.md +9 -83
- package/skills/cloudflare/references/kv/api.md +12 -154
- package/skills/cloudflare/references/kv/configuration.md +11 -139
- package/skills/cloudflare/references/kv/gotchas.md +15 -129
- package/skills/cloudflare/references/kv/patterns.md +15 -190
- package/skills/cloudflare/references/miniflare/README.md +15 -98
- package/skills/cloudflare/references/miniflare/api.md +16 -187
- package/skills/cloudflare/references/miniflare/configuration.md +12 -169
- package/skills/cloudflare/references/miniflare/gotchas.md +15 -160
- package/skills/cloudflare/references/miniflare/patterns.md +15 -177
- package/skills/cloudflare/references/network-interconnect/README.md +1 -1
- package/skills/cloudflare/references/network-interconnect/gotchas.md +1 -1
- package/skills/cloudflare/references/network-interconnect/patterns.md +1 -1
- package/skills/cloudflare/references/observability/README.md +20 -81
- package/skills/cloudflare/references/observability/api.md +20 -164
- package/skills/cloudflare/references/observability/configuration.md +18 -164
- package/skills/cloudflare/references/observability/gotchas.md +19 -109
- package/skills/cloudflare/references/observability/patterns.md +12 -103
- package/skills/cloudflare/references/pages/README.md +13 -81
- package/skills/cloudflare/references/pages/api.md +10 -201
- package/skills/cloudflare/references/pages/configuration.md +16 -201
- package/skills/cloudflare/references/pages/gotchas.md +13 -197
- package/skills/cloudflare/references/pages/patterns.md +11 -200
- package/skills/cloudflare/references/pages-functions/README.md +13 -91
- package/skills/cloudflare/references/pages-functions/api.md +10 -140
- package/skills/cloudflare/references/pages-functions/configuration.md +11 -119
- package/skills/cloudflare/references/pages-functions/gotchas.md +17 -94
- package/skills/cloudflare/references/pages-functions/patterns.md +12 -133
- package/skills/cloudflare/references/pipelines/README.md +1 -1
- package/skills/cloudflare/references/pulumi/README.md +2 -2
- package/skills/cloudflare/references/queues/README.md +15 -87
- package/skills/cloudflare/references/queues/api.md +10 -200
- package/skills/cloudflare/references/queues/configuration.md +18 -142
- package/skills/cloudflare/references/queues/gotchas.md +16 -204
- package/skills/cloudflare/references/queues/patterns.md +19 -218
- package/skills/cloudflare/references/r2/README.md +17 -86
- package/skills/cloudflare/references/r2/api.md +14 -198
- package/skills/cloudflare/references/r2/configuration.md +17 -163
- package/skills/cloudflare/references/r2/gotchas.md +15 -188
- package/skills/cloudflare/references/r2/patterns.md +16 -191
- package/skills/cloudflare/references/r2-data-catalog/README.md +11 -70
- package/skills/cloudflare/references/r2-data-catalog/api.md +14 -89
- package/skills/cloudflare/references/r2-data-catalog/configuration.md +15 -96
- package/skills/cloudflare/references/r2-data-catalog/gotchas.md +14 -51
- package/skills/cloudflare/references/r2-data-catalog/patterns.md +11 -116
- package/skills/cloudflare/references/realtime-sfu/README.md +1 -1
- package/skills/cloudflare/references/realtimekit/README.md +1 -1
- package/skills/cloudflare/references/secrets-store/README.md +14 -66
- package/skills/cloudflare/references/secrets-store/api.md +14 -193
- package/skills/cloudflare/references/secrets-store/configuration.md +16 -176
- package/skills/cloudflare/references/secrets-store/gotchas.md +14 -92
- package/skills/cloudflare/references/secrets-store/patterns.md +14 -194
- package/skills/cloudflare/references/smart-placement/README.md +2 -2
- package/skills/cloudflare/references/static-assets/README.md +15 -59
- package/skills/cloudflare/references/static-assets/api.md +12 -195
- package/skills/cloudflare/references/static-assets/configuration.md +16 -186
- package/skills/cloudflare/references/static-assets/gotchas.md +18 -162
- package/skills/cloudflare/references/static-assets/patterns.md +13 -185
- package/skills/cloudflare/references/stream/README.md +15 -107
- package/skills/cloudflare/references/stream/api-live.md +16 -193
- package/skills/cloudflare/references/stream/api.md +19 -197
- package/skills/cloudflare/references/stream/configuration.md +16 -139
- package/skills/cloudflare/references/stream/gotchas.md +16 -128
- package/skills/cloudflare/references/stream/patterns.md +20 -182
- package/skills/cloudflare/references/tail-workers/README.md +14 -82
- package/skills/cloudflare/references/tail-workers/api.md +10 -197
- package/skills/cloudflare/references/tail-workers/configuration.md +13 -174
- package/skills/cloudflare/references/tail-workers/gotchas.md +12 -188
- package/skills/cloudflare/references/tail-workers/patterns.md +11 -176
- package/skills/cloudflare/references/terraform/README.md +2 -2
- package/skills/cloudflare/references/tunnel/README.md +13 -122
- package/skills/cloudflare/references/tunnel/api.md +11 -190
- package/skills/cloudflare/references/tunnel/configuration.md +12 -155
- package/skills/cloudflare/references/tunnel/gotchas.md +12 -144
- package/skills/cloudflare/references/tunnel/networking.md +12 -166
- package/skills/cloudflare/references/tunnel/patterns.md +12 -189
- package/skills/cloudflare/references/vectorize/README.md +15 -126
- package/skills/cloudflare/references/vectorize/api.md +14 -84
- package/skills/cloudflare/references/vectorize/configuration.md +14 -83
- package/skills/cloudflare/references/vectorize/gotchas.md +12 -73
- package/skills/cloudflare/references/vectorize/patterns.md +17 -83
- package/skills/cloudflare/references/waf/README.md +15 -107
- package/skills/cloudflare/references/waf/api.md +17 -202
- package/skills/cloudflare/references/waf/configuration.md +14 -199
- package/skills/cloudflare/references/waf/gotchas.md +15 -200
- package/skills/cloudflare/references/waf/patterns.md +13 -193
- package/skills/cloudflare/references/workerd/README.md +2 -2
- package/skills/cloudflare/references/workers-ai/README.md +14 -187
- package/skills/cloudflare/references/workers-ai/api.md +10 -109
- package/skills/cloudflare/references/workers-ai/configuration.md +11 -92
- package/skills/cloudflare/references/workers-ai/gotchas.md +12 -111
- package/skills/cloudflare/references/workers-ai/patterns.md +9 -115
- package/skills/cloudflare/references/workers-for-platforms/README.md +3 -3
- package/skills/cloudflare/references/workers-vpc/README.md +1 -1
- package/skills/cloudflare/references/workflows/README.md +15 -69
- package/skills/cloudflare/references/workflows/api.md +12 -213
- package/skills/cloudflare/references/workflows/configuration.md +16 -150
- package/skills/cloudflare/references/workflows/gotchas.md +17 -88
- package/skills/cloudflare/references/workflows/patterns.md +19 -164
- package/skills/cloudflare-api-token/SKILL.md +1 -1
- package/skills/cloudflare-cf-cli/SKILL.md +44 -13
- package/skills/cloudflare-email-service/SKILL.md +6 -36
- package/skills/cloudflare-email-service/references/rest-api.md +12 -179
- package/skills/cloudflare-email-service/references/sending.md +17 -250
- package/skills/cloudflare-one/SKILL.md +4 -2
- package/skills/cloudflare-one-migrations/SKILL.md +1 -1
- package/skills/cloudflare-token-roll/SKILL.md +2 -5
- package/skills/durable-objects/SKILL.md +10 -16
- package/skills/durable-objects/references/rules.md +17 -293
- package/skills/durable-objects/references/testing.md +16 -257
- package/skills/nextjs-on-cloudflare/SKILL.md +33 -0
- package/skills/sandbox-migrate-to-next/SKILL.md +2 -2
- package/skills/sandbox-next/SKILL.md +3 -2
- package/skills/sandbox-next/references/api-quick-ref.md +15 -90
- package/skills/sandbox-stable/SKILL.md +1 -1
- package/skills/turnstile-spin/SKILL.md +14 -8
- package/skills/workers-best-practices/SKILL.md +36 -103
- package/skills/workers-best-practices/references/configuration.md +139 -0
- package/skills/workers-best-practices/references/platform-apis.md +51 -0
- package/skills/workers-best-practices/references/{rules.md → runtime-patterns.md} +9 -134
- package/skills/wrangler/SKILL.md +48 -901
- package/bin/setup.mjs +0 -119
- package/dist/api-token.d.ts +0 -12
- package/dist/api-token.d.ts.map +0 -1
- package/dist/api-token.js +0 -23
- package/dist/api-token.js.map +0 -1
- package/dist/auth-flow.d.ts +0 -15
- package/dist/auth-flow.d.ts.map +0 -1
- package/dist/auth-flow.js +0 -90
- package/dist/auth-flow.js.map +0 -1
- package/dist/client.d.ts +0 -18
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -47
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -20
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -10
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -22
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -65
- package/dist/index.js.map +0 -1
- package/dist/mcp-server.d.ts +0 -2
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js +0 -106
- package/dist/mcp-server.js.map +0 -1
- package/dist/oauth.d.ts +0 -44
- package/dist/oauth.d.ts.map +0 -1
- package/dist/oauth.js +0 -135
- package/dist/oauth.js.map +0 -1
- package/dist/proxy.d.ts +0 -30
- package/dist/proxy.d.ts.map +0 -1
- package/dist/proxy.js +0 -41
- package/dist/proxy.js.map +0 -1
- package/dist/result-caps.d.ts +0 -23
- package/dist/result-caps.d.ts.map +0 -1
- package/dist/result-caps.js +0 -75
- package/dist/result-caps.js.map +0 -1
- package/dist/runtime.d.ts +0 -72
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -249
- package/dist/runtime.js.map +0 -1
- package/dist/servers.d.ts +0 -19
- package/dist/servers.d.ts.map +0 -1
- package/dist/servers.js +0 -40
- package/dist/servers.js.map +0 -1
- package/dist/token-store.d.ts +0 -32
- package/dist/token-store.d.ts.map +0 -1
- package/dist/token-store.js +0 -61
- package/dist/token-store.js.map +0 -1
- package/dist/tool-cache.d.ts +0 -25
- package/dist/tool-cache.d.ts.map +0 -1
- package/dist/tool-cache.js +0 -43
- package/dist/tool-cache.js.map +0 -1
- package/mcp.json +0 -15
- package/skills/cloudflare/references/agents-sdk/README.md +0 -89
- package/skills/cloudflare/references/agents-sdk/api.md +0 -190
- package/skills/cloudflare/references/agents-sdk/configuration.md +0 -182
- package/skills/cloudflare/references/agents-sdk/gotchas.md +0 -158
- package/skills/cloudflare/references/agents-sdk/patterns.md +0 -192
- package/skills/cloudflare/references/durable-objects/README.md +0 -185
- package/skills/cloudflare/references/durable-objects/api.md +0 -187
- package/skills/cloudflare/references/durable-objects/configuration.md +0 -160
- package/skills/cloudflare/references/durable-objects/gotchas.md +0 -197
- package/skills/cloudflare/references/durable-objects/patterns.md +0 -201
- package/skills/cloudflare/references/sandbox/README.md +0 -96
- package/skills/cloudflare/references/sandbox/api.md +0 -198
- package/skills/cloudflare/references/sandbox/configuration.md +0 -143
- package/skills/cloudflare/references/sandbox/gotchas.md +0 -194
- package/skills/cloudflare/references/sandbox/patterns.md +0 -201
- package/skills/cloudflare/references/turnstile/README.md +0 -99
- package/skills/cloudflare/references/turnstile/api.md +0 -240
- package/skills/cloudflare/references/turnstile/configuration.md +0 -222
- package/skills/cloudflare/references/turnstile/gotchas.md +0 -218
- package/skills/cloudflare/references/turnstile/patterns.md +0 -193
- package/skills/cloudflare/references/workers/README.md +0 -108
- package/skills/cloudflare/references/workers/api.md +0 -195
- package/skills/cloudflare/references/workers/configuration.md +0 -185
- package/skills/cloudflare/references/workers/frameworks.md +0 -197
- package/skills/cloudflare/references/workers/gotchas.md +0 -137
- package/skills/cloudflare/references/workers/patterns.md +0 -198
- package/skills/cloudflare/references/wrangler/README.md +0 -135
- package/skills/cloudflare/references/wrangler/api.md +0 -188
- package/skills/cloudflare/references/wrangler/configuration.md +0 -197
- package/skills/cloudflare/references/wrangler/gotchas.md +0 -197
- package/skills/cloudflare/references/wrangler/patterns.md +0 -209
- package/skills/cloudflare-auth-setup/SKILL.md +0 -59
- package/skills/workers-best-practices/references/review.md +0 -174
|
@@ -1,175 +1,30 @@
|
|
|
1
1
|
# Workflow Patterns
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Design Decisions
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
export class ImageProcessingWorkflow extends WorkflowEntrypoint<Env, Params> {
|
|
7
|
-
async run(event, step) {
|
|
8
|
-
const imageData = await step.do('fetch', async () => (await this.env.BUCKET.get(event.payload.imageKey)).arrayBuffer());
|
|
9
|
-
const description = await step.do('generate description', async () =>
|
|
10
|
-
await this.env.AI.run('@cf/llava-hf/llava-1.5-7b-hf', {image: Array.from(new Uint8Array(imageData)), prompt: 'Describe this image', max_tokens: 50})
|
|
11
|
-
);
|
|
12
|
-
await step.waitForEvent('await approval', { type: 'approved', timeout: '24h' });
|
|
13
|
-
await step.do('publish', async () => await this.env.BUCKET.put(`public/${event.payload.imageKey}`, imageData));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
```
|
|
5
|
+
Read [Rules of Workflows](https://developers.cloudflare.com/workflows/build/rules-of-workflows/) before choosing step boundaries or concurrency patterns.
|
|
17
6
|
|
|
18
|
-
|
|
7
|
+
- Separate work into steps that can be retried independently. Persist results through step returns and keep side effects inside steps.
|
|
8
|
+
- Make side effects safe to repeat. A retry can happen after an external write succeeds; use the destination's idempotency mechanism or atomic deduplication. A separate check followed by a write does not itself guarantee idempotency.
|
|
9
|
+
- Base step names, loops, and branches on stable input or persisted results. In-memory state and fresh time/random values cannot serve as durable replay state.
|
|
10
|
+
- Await step operations, and check the documented replay behavior before combining steps in parallel or racing them.
|
|
11
|
+
- Keep large data in external storage when appropriate and pass references between steps; consult current return-type and size constraints.
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
export class UserLifecycleWorkflow extends WorkflowEntrypoint<Env, Params> {
|
|
22
|
-
async run(event, step) {
|
|
23
|
-
await step.do('welcome email', async () => await sendEmail(event.payload.email, 'Welcome!'));
|
|
24
|
-
await step.sleep('trial period', '7 days');
|
|
25
|
-
const hasConverted = await step.do('check conversion', async () => {
|
|
26
|
-
const user = await this.env.DB.prepare('SELECT subscription_status FROM users WHERE id = ?').bind(event.payload.userId).first();
|
|
27
|
-
return user.subscription_status === 'active';
|
|
28
|
-
});
|
|
29
|
-
if (!hasConverted) await step.do('trial expiration email', async () => await sendEmail(event.payload.email, 'Trial ending'));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
```
|
|
13
|
+
## Examples and Orchestration
|
|
33
14
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return res.json();
|
|
43
|
-
});
|
|
44
|
-
const transformed = await step.do('transform', async () =>
|
|
45
|
-
rawData.map(item => ({ id: item.id, normalized: normalizeData(item) }))
|
|
46
|
-
);
|
|
47
|
-
const dataRef = await step.do('store', async () => {
|
|
48
|
-
const key = `processed/${Date.now()}.json`;
|
|
49
|
-
await this.env.BUCKET.put(key, JSON.stringify(transformed));
|
|
50
|
-
return { key };
|
|
51
|
-
});
|
|
52
|
-
await step.do('load', async () => {
|
|
53
|
-
const data = await (await this.env.BUCKET.get(dataRef.key)).json();
|
|
54
|
-
for (let i = 0; i < data.length; i += 100) {
|
|
55
|
-
await this.env.DB.batch(data.slice(i, i + 100).map(item =>
|
|
56
|
-
this.env.DB.prepare('INSERT INTO records VALUES (?, ?)').bind(item.id, item.normalized)
|
|
57
|
-
));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Human-in-the-Loop Approval
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
export class ApprovalWorkflow extends WorkflowEntrypoint<Env, Params> {
|
|
68
|
-
async run(event, step) {
|
|
69
|
-
await step.do('create approval', async () => await this.env.DB.prepare('INSERT INTO approvals (id, user_id, status) VALUES (?, ?, ?)').bind(event.instanceId, event.payload.userId, 'pending').run());
|
|
70
|
-
try {
|
|
71
|
-
const approval = await step.waitForEvent<{ approved: boolean }>('wait for approval', { type: 'approval-response', timeout: '48h' });
|
|
72
|
-
if (approval.approved) { await step.do('process approval', async () => {}); }
|
|
73
|
-
else { await step.do('handle rejection', async () => {}); }
|
|
74
|
-
} catch (e) {
|
|
75
|
-
await step.do('auto reject', async () => await this.env.DB.prepare('UPDATE approvals SET status = ? WHERE id = ?').bind('auto-rejected', event.instanceId).run());
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
```
|
|
15
|
+
| Task | Documentation |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| Process images with human approval; handle approval events and timeouts | [Human-in-the-loop image tagging](https://developers.cloudflare.com/workflows/examples/wait-for-event/) |
|
|
18
|
+
| Implement a payment and notification sequence | [Pay cart and send invoice](https://developers.cloudflare.com/workflows/examples/send-invoices/) |
|
|
19
|
+
| Export data to object storage | [Export and save D1 database](https://developers.cloudflare.com/workflows/examples/backup-d1/) |
|
|
20
|
+
| Delay lifecycle follow-ups or retry transient failures | [Sleeping and retrying](https://developers.cloudflare.com/workflows/build/sleeping-and-retrying/) |
|
|
21
|
+
| Schedule jobs or start child Workflows | [Trigger Workflows](https://developers.cloudflare.com/workflows/build/trigger-workflows/) |
|
|
22
|
+
| Design parallel work, races, conditional steps, and batch creation | [Rules of Workflows](https://developers.cloudflare.com/workflows/build/rules-of-workflows/) |
|
|
80
23
|
|
|
81
24
|
## Testing Workflows
|
|
82
25
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
// vitest.config.ts
|
|
87
|
-
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
|
|
88
|
-
|
|
89
|
-
export default defineWorkersConfig({
|
|
90
|
-
test: {
|
|
91
|
-
poolOptions: {
|
|
92
|
-
workers: {
|
|
93
|
-
wrangler: { configPath: './wrangler.jsonc' }
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Introspection API
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
import { introspectWorkflowInstance } from 'cloudflare:test';
|
|
104
|
-
|
|
105
|
-
const instance = await env.MY_WORKFLOW.create({ params: { userId: '123' } });
|
|
106
|
-
const introspector = await introspectWorkflowInstance(env.MY_WORKFLOW, instance.id);
|
|
107
|
-
|
|
108
|
-
// Wait for step completion
|
|
109
|
-
const result = await introspector.waitForStepResult({ name: 'fetch user', index: 0 });
|
|
110
|
-
|
|
111
|
-
// Mock step behavior
|
|
112
|
-
await introspector.modify(async (m) => {
|
|
113
|
-
await m.mockStepResult({ name: 'api call' }, { mocked: true });
|
|
114
|
-
});
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Best Practices
|
|
118
|
-
|
|
119
|
-
### ✅ DO
|
|
120
|
-
|
|
121
|
-
1. **Granular steps**: One API call per step (unless proving idempotency)
|
|
122
|
-
2. **Idempotency**: Check-then-execute; use idempotency keys
|
|
123
|
-
3. **Deterministic names**: Use static or step-output-based names
|
|
124
|
-
4. **Return state**: Persist via step returns, not variables
|
|
125
|
-
5. **Always await**: `await step.do()`, avoid dangling promises
|
|
126
|
-
6. **Deterministic conditionals**: Base on `event.payload` or step outputs
|
|
127
|
-
7. **Store large data externally**: R2/KV for data exceeding step return limit, return refs
|
|
128
|
-
8. **Batch creation**: `createBatch()` for multiple instances
|
|
129
|
-
|
|
130
|
-
### ❌ DON'T
|
|
131
|
-
|
|
132
|
-
1. **One giant step**: Breaks durability & retry control
|
|
133
|
-
2. **State outside steps**: Lost on hibernation
|
|
134
|
-
3. **Mutate events**: Events immutable, return new state
|
|
135
|
-
4. **Non-deterministic logic outside steps**: `Math.random()`, `Date.now()` must be in steps
|
|
136
|
-
5. **Side effects outside steps**: May duplicate on restart
|
|
137
|
-
6. **Non-deterministic step names**: Prevents caching
|
|
138
|
-
7. **Ignore timeouts**: `waitForEvent` throws, use try-catch
|
|
139
|
-
8. **Reuse instance IDs**: Must be unique within retention
|
|
140
|
-
|
|
141
|
-
## Orchestration Patterns
|
|
142
|
-
|
|
143
|
-
### Fan-Out (Parallel Processing)
|
|
144
|
-
```typescript
|
|
145
|
-
const files = await step.do('list', async () => this.env.BUCKET.list());
|
|
146
|
-
await Promise.all(files.objects.map((file, i) => step.do(`process ${i}`, async () => processFile(await (await this.env.BUCKET.get(file.key)).arrayBuffer()))));
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Parent-Child Workflows
|
|
150
|
-
```typescript
|
|
151
|
-
const child = await step.do('start child', async () => await this.env.CHILD_WORKFLOW.create({id: `child-${event.instanceId}`, params: { data: result.data }}));
|
|
152
|
-
await step.do('other work', async () => console.log(`Child started: ${child.id}`));
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Race Pattern
|
|
156
|
-
```typescript
|
|
157
|
-
const winner = await Promise.race([
|
|
158
|
-
step.do('option A', async () => slowOperation()),
|
|
159
|
-
step.do('option B', async () => fastOperation())
|
|
160
|
-
]);
|
|
161
|
-
```
|
|
26
|
+
Fetch [Vitest setup](https://developers.cloudflare.com/workers/testing/vitest-integration/write-your-first-test/) for current dependencies and configuration, then use the [Workflow test APIs](https://developers.cloudflare.com/workers/testing/vitest-integration/test-apis/#workflows) for introspection, step/event mocks, sleep controls, and cleanup.
|
|
162
27
|
|
|
163
|
-
|
|
164
|
-
```typescript
|
|
165
|
-
export default { async scheduled(event, env) { await env.DAILY_WORKFLOW.create({id: `daily-${event.scheduledTime}`, params: { timestamp: event.scheduledTime }}); }};
|
|
166
|
-
export class DailyWorkflow extends WorkflowEntrypoint<Env, Params> {
|
|
167
|
-
async run(event, step) {
|
|
168
|
-
await step.do('daily task', async () => {});
|
|
169
|
-
await step.sleep('wait 7 days', '7 days');
|
|
170
|
-
await step.do('weekly followup', async () => {});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
```
|
|
28
|
+
Test retry behavior, event arrival and timeout paths, and duplicate external effects. Use documented introspection waits to observe completion rather than assuming a newly created instance has finished.
|
|
174
29
|
|
|
175
|
-
See
|
|
30
|
+
See [configuration.md](./configuration.md), [api.md](./api.md), and [gotchas.md](./gotchas.md).
|
|
@@ -97,7 +97,7 @@ Two traps make this fail in ways that look like a permissions bug:
|
|
|
97
97
|
- Full audit set (live-proven 2026-09-11, one bulk PUT, all 137 groups verified stored and exercised): the merge-safe probe set is one read per new domain — `GET /zones/:id/settings` (Zone Settings), `/zones/:id/pagerules` (Page Rules), `/zones/:id/snippets` (Snippets), `/zones/:id/healthchecks` (Health Checks), `/zones/:id/waiting_rooms`, `/zones/:id/bot_management`, `/zones/:id/page_shield/scripts`, `/accounts/:id/rulesets` (Account Rulesets), `/accounts/:id/security-center/insights` (Security Center Insights), `/accounts/:id/dns_settings`, `/accounts/:id/images/v1`, `/accounts/:id/ai/models/search`, `/accounts/:id/vectorize/v2/indexes`, `/accounts/:id/pages/projects`, `/accounts/:id/access/groups`, `/accounts/:id/gateway`, `/accounts/:id/devices/posture`, `/accounts/:id/logpush/jobs`. **`Logs Write` unlocks `GET /accounts/:id/logpush/jobs`** — the earlier "Logpush 401s, dashboard only" note in this file was wrong; it was a missing group, not a missing surface.
|
|
98
98
|
- Disambiguate plan gates from scope gaps by replaying the failing call with the **full dashboard session** (no token). If the session also fails, it is entitlement, not scope. Confirmed entitlement-only surfaces (2026-09-11): Containers (`401`, Workers Paid), Workers for Platforms dispatch (`403 10121`), Spectrum (`403 10007`), Argo Smart Routing (`401 1015`), SSL for SaaS custom hostnames (`403 1404`, no quota), Stream (`403`). Also sunset for everyone: the Zone Analytics REST API (`404 1015` — use GraphQL).
|
|
99
99
|
- Operator entitlements are plan-gated and fail with an explicit message, not a silent no-match: `matches` (regex) needs a Business or WAF Advanced plan (`not entitled: the use of operator Matches is not allowed`), while `in`, `eq`, `starts_with`, `extension`, `len`, and `substring` work on Free. Prefer those when authoring rules for a free zone.
|
|
100
|
-
- Known non-gaps, do not chase: `GET /user/tokens/:id` returns `9109` by design (tokens cannot manage tokens); zone-analytics `10000` without the Zone Analytics group is correct least privilege (observability rollups
|
|
100
|
+
- Known non-gaps, do not chase: `GET /user/tokens/:id` returns `9109` by design (tokens cannot manage tokens); zone-analytics `10000` without the Zone Analytics group is correct least privilege (observability rollups use the GraphQL Analytics API, not this token); Workers Tail needs a websocket (group presence + dashboard UI is the check); Logpush **datasets** (`404 10001`) and Zone versions (`404 10001`) expose no API-token surface. Workers custom-domain endpoints (`/accounts/{id}/workers/domains`) answer `405 Method not allowed for this authentication scheme` for both API tokens and the wrangler OAuth token — manage custom domains through `wrangler deploy` routes, not this endpoint.
|
|
101
101
|
- Workers Builds (live-proven 2026-09-07): `GET /accounts/{id}/builds/builds/{uuid}` plus `/logs` read; trigger PATCH and build-token DELETE verified with the Edit level.
|
|
102
102
|
- Template drift is real: the dashboard template grows over time (Builds/Agents/Containers/Observability/Pages appeared after the doc was written). Enumerate required groups per task from `docs/api-token.md`; never assume the template equals the need.
|
|
103
103
|
- A 403 naming a missing group later means extend-then-verify, not a new token: same flow, one more row.
|
|
@@ -6,9 +6,9 @@ description: Use the Cloudflare cf CLI for estate-wide Cloudflare operations fro
|
|
|
6
6
|
# Cloudflare cf CLI
|
|
7
7
|
|
|
8
8
|
`cf` is Cloudflare's agent-first CLI: the full API as typed commands, JSON
|
|
9
|
-
output by default, and intent-based command discovery. It
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
output by default, and intent-based command discovery. It is the default
|
|
10
|
+
interface for Cloudflare work in a shell. Wrangler survives only as the
|
|
11
|
+
per-project dev-server implementation cf delegates to.
|
|
12
12
|
|
|
13
13
|
## Install and auth
|
|
14
14
|
|
|
@@ -22,7 +22,7 @@ estate's API token is present, and the CLI inherits whatever scope that token
|
|
|
22
22
|
has:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
export CLOUDFLARE_API_TOKEN=... #
|
|
25
|
+
export CLOUDFLARE_API_TOKEN=... # the estate's API token
|
|
26
26
|
cf auth whoami # authSource: "CLOUDFLARE_API_TOKEN environment variable"
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -52,7 +52,7 @@ overrides `CLOUDFLARE_ZONE_ID`), `--profile` (auth profile), `--local`
|
|
|
52
52
|
| Workers deploys for migrated projects | `cf deploy` |
|
|
53
53
|
| **Local dev** (`cf dev`, `cf build`) | **delegates to the project's dev server** — see below |
|
|
54
54
|
| `wrangler tail` | `wrangler` (cf has no tail command) |
|
|
55
|
-
| Docs lookup, primitives guidance | `
|
|
55
|
+
| Docs lookup, primitives guidance | developers.cloudflare.com; `workers-best-practices` / `durable-objects` skills |
|
|
56
56
|
|
|
57
57
|
## Delegation: why wrangler is still a dependency
|
|
58
58
|
|
|
@@ -105,12 +105,43 @@ cannot be deployed by cf at all — wrangler still deploys a bare `index.js` +
|
|
|
105
105
|
`cloudflare.config.ts` automatically. Do it per project, in that project's
|
|
106
106
|
repo — not estate-wide from outside.
|
|
107
107
|
|
|
108
|
-
##
|
|
108
|
+
## Deploying without the framework autoconfig trap
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
Plain `cf deploy` (no flags) runs the **framework-detected build** from
|
|
111
|
+
autoconfig, then uploads whatever Build Output exists. In a monorepo project
|
|
112
|
+
whose build does not emit the Build Output itself, that combination re-runs
|
|
113
|
+
the wrong build and uploads a **stale Build Output** — the deploy succeeds
|
|
114
|
+
while shipping the previous build. The reliable chain for every project:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
bun run build # the project's real build (turbo/npm script)
|
|
118
|
+
cf-wrangler build # refresh .cloudflare/output/v0 from the config pair
|
|
119
|
+
cf deploy --prebuilt # upload the existing Build Output without rebuilding
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Three rules that make the chain work, all live-verified:
|
|
123
|
+
|
|
124
|
+
- **cf discovers its delegate from the nearest `package.json`.** In a
|
|
125
|
+
workspace, the app package must declare `cf` and `wrangler` in its own
|
|
126
|
+
devDependencies — root-only placement makes cf fall back to autoconfig
|
|
127
|
+
(runner `npx`, wrong build command), which under Bun `devEngines` fails
|
|
128
|
+
with `EBADDEVENGINES`. Declaring `packageManager: "bun@<version>"` in the
|
|
129
|
+
app manifest fixes the runner.
|
|
130
|
+
- **wrangler ≥ 4.143 understands cf's `defineConfig` marker.** Older
|
|
131
|
+
wrangler rejects a `cloudflare.config.ts` default export with
|
|
132
|
+
"not a supported export type" — upgrade wrangler, don't restructure the
|
|
133
|
+
config.
|
|
134
|
+
- **Multi-module builds need the ESModule rules in `wrangler.config.ts`.**
|
|
135
|
+
Vite-plugin output (additional `start-assets/` modules) and Nitro's chunk
|
|
136
|
+
layout only ship when `rules: [{type: "ESModule", globs: ["**/*.js",
|
|
137
|
+
"**/*.mjs"]}]` is present alongside `noBundle: true`; without them the
|
|
138
|
+
deploy fails validation with `No such module` (10021).
|
|
139
|
+
|
|
140
|
+
## Relationship to wrangler and the old MCP servers
|
|
141
|
+
|
|
142
|
+
cf is a subprocess with JSON output; the former pi-cloudflare MCP servers
|
|
143
|
+
(`cf_api_*`, `cf_docs_*`, `cf_bindings_*`, `cf_builds_*`, `cf_obs_*`) were
|
|
144
|
+
removed — cf's ~3,000 typed commands plus `cf builds` and `cf
|
|
145
|
+
observability` cover their surfaces, and docs/primitives knowledge lives in
|
|
146
|
+
the vendored Cloudflare skills. Wrangler stays a per-project devDependency
|
|
147
|
+
only as cf's dev-server delegate (see above).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cloudflare-email-service
|
|
3
|
-
description:
|
|
3
|
+
description: Implement or troubleshoot Cloudflare Email Sending and Email Routing integrations and their delivery configuration.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Cloudflare Email Service
|
|
@@ -18,7 +18,7 @@ Cloudflare Email Service lets you send transactional emails and route incoming e
|
|
|
18
18
|
| Cloudflare docs | Cloudflare MCP `docs` tool or URL `https://developers.cloudflare.com/email-service/` | API reference, limits, pricing, latest features |
|
|
19
19
|
| REST API spec | `https://developers.cloudflare.com/api/resources/email_sending` | OpenAPI spec for the Email Sending REST API |
|
|
20
20
|
| Workers types | `https://www.npmjs.com/package/@cloudflare/workers-types` | Type signatures, binding shapes |
|
|
21
|
-
| Agents SDK docs |
|
|
21
|
+
| Agents SDK docs | [Email agent walkthrough](https://developers.cloudflare.com/agents/examples/email-agent/) | Email handling in Agents SDK |
|
|
22
22
|
|
|
23
23
|
## FIRST: Check Prerequisites
|
|
24
24
|
|
|
@@ -42,39 +42,9 @@ Start here. Find your situation, then follow the link for full details.
|
|
|
42
42
|
| **Set up Email Sending or Email Routing** | `wrangler email sending enable` / `wrangler email routing enable`, or Dashboard | [cli-and-mcp.md](references/cli-and-mcp.md) |
|
|
43
43
|
| **Improve deliverability, avoid spam folders** | Authentication, content, compliance | [deliverability.md](references/deliverability.md) |
|
|
44
44
|
|
|
45
|
-
##
|
|
45
|
+
## Sending Workflow
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```jsonc
|
|
50
|
-
// wrangler.jsonc
|
|
51
|
-
{ "send_email": [{ "name": "EMAIL" }] }
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
const response = await env.EMAIL.send({
|
|
56
|
-
to: "user@example.com",
|
|
57
|
-
from: { email: "welcome@yourdomain.com", name: "My App" },
|
|
58
|
-
subject: "Welcome!",
|
|
59
|
-
html: "<h1>Welcome!</h1>",
|
|
60
|
-
text: "Welcome!",
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
The binding is recommended for Workers — no API keys needed. If a user specifically requests the REST API from within a Worker (e.g., they already have an API token workflow), that works too — see [rest-api.md](references/rest-api.md).
|
|
65
|
-
|
|
66
|
-
See [sending.md](references/sending.md) for the full API, batch sends, attachments, custom headers, restricted bindings, and Agents SDK integration.
|
|
67
|
-
|
|
68
|
-
## Quick Start — REST API
|
|
69
|
-
|
|
70
|
-
For apps outside Workers, or within Workers if the user explicitly requests it. Key differences from the Workers binding:
|
|
71
|
-
|
|
72
|
-
- Endpoint: `POST https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send`
|
|
73
|
-
- `from` object uses `address` (not `email`): `{ "address": "...", "name": "..." }`
|
|
74
|
-
- `replyTo` is `reply_to` (snake_case)
|
|
75
|
-
- Response returns `{ delivered: [], permanent_bounces: [], queued: [] }` (not `messageId`)
|
|
76
|
-
|
|
77
|
-
See [rest-api.md](references/rest-api.md) for curl examples, response format, and error handling.
|
|
47
|
+
Prefer the binding for Workers; use REST for external apps or when explicitly requested. Read [sending.md](references/sending.md) or [rest-api.md](references/rest-api.md) to retrieve the documentation for the selected task before writing code. These guides cover setup, recipients, attachments, headers, limits, response handling, and errors; the Workers guide also covers Agents SDK integration and types matched to the project configuration.
|
|
78
48
|
|
|
79
49
|
## Common Mistakes
|
|
80
50
|
|
|
@@ -96,8 +66,8 @@ See [rest-api.md](references/rest-api.md) for curl examples, response format, an
|
|
|
96
66
|
|
|
97
67
|
Read the reference that matches your situation. You don't need all of them.
|
|
98
68
|
|
|
99
|
-
- **[references/sending.md](references/sending.md)** — Workers binding
|
|
100
|
-
- **[references/rest-api.md](references/rest-api.md)** —
|
|
69
|
+
- **[references/sending.md](references/sending.md)** — Documentation map for Workers binding, attachments, and Agents SDK email.
|
|
70
|
+
- **[references/rest-api.md](references/rest-api.md)** — Documentation map for HTTP sending, request schemas, responses, and errors.
|
|
101
71
|
- **[references/routing.md](references/routing.md)** — Inbound `email()` handler, forwarding, replying, parsing. For receiving emails.
|
|
102
72
|
- **[references/cli-and-mcp.md](references/cli-and-mcp.md)** — Domain setup, wrangler commands, MCP tools. For first-time setup.
|
|
103
73
|
- **[references/deliverability.md](references/deliverability.md)** — SPF/DKIM/DMARC, bounces, suppressions, best practices.
|
|
@@ -1,184 +1,17 @@
|
|
|
1
1
|
# Sending Emails — REST API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use the REST API for HTTP integrations from external applications, or when the user explicitly requests it inside a Worker. Otherwise prefer the [Workers binding](sending.md).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Read the relevant page before building the request. Keep credentials in the project's existing secret or environment-variable mechanism, and inspect the installed client SDK version if one is used.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
| Task | Read |
|
|
8
|
+
|------|------|
|
|
9
|
+
| Authenticate, send an email, or find the complete request schema | [REST API](https://developers.cloudflare.com/email-service/api/send-emails/rest-api/) and its linked Email Sending API reference |
|
|
10
|
+
| Set multiple recipients, CC/BCC, or named addresses | [Specify recipients](https://developers.cloudflare.com/email-service/examples/email-sending/recipients/) (REST examples) |
|
|
11
|
+
| Encode attachments | [REST attachments](https://developers.cloudflare.com/email-service/api/send-emails/rest-api/#attachments) |
|
|
12
|
+
| Add custom headers | [Email headers](https://developers.cloudflare.com/email-service/reference/headers/) |
|
|
13
|
+
| Check recipient, message-size, or sending quotas | [Limits](https://developers.cloudflare.com/email-service/platform/limits/) |
|
|
14
|
+
| Interpret delivery outcomes | [REST response](https://developers.cloudflare.com/email-service/api/send-emails/rest-api/#response) |
|
|
15
|
+
| Diagnose errors and decide whether to retry | [REST error handling](https://developers.cloudflare.com/email-service/api/send-emails/rest-api/#error-handling) |
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
POST https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Authentication
|
|
14
|
-
|
|
15
|
-
Authenticate with a [Cloudflare API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/) that has email sending permission:
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
Authorization: Bearer <API_TOKEN>
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Request Fields
|
|
22
|
-
|
|
23
|
-
**IMPORTANT:** The REST API uses different field names than the Workers binding in some cases.
|
|
24
|
-
|
|
25
|
-
| Field | Type | Required | Description |
|
|
26
|
-
|-------|------|----------|-------------|
|
|
27
|
-
| `to` | string or string[] | Yes | Recipient(s), max 50 combined with cc/bcc |
|
|
28
|
-
| `from` | string or `{address, name}` | Yes | Sender — **uses `address` not `email`** for object form |
|
|
29
|
-
| `subject` | string | Yes | Email subject line |
|
|
30
|
-
| `html` | string | No* | HTML body |
|
|
31
|
-
| `text` | string | No* | Plain text body |
|
|
32
|
-
| `cc` | string or string[] | No | CC recipients |
|
|
33
|
-
| `bcc` | string or string[] | No | BCC recipients |
|
|
34
|
-
| `reply_to` | string or `{address, name}` | No | **Snake_case**, not camelCase |
|
|
35
|
-
| `attachments` | array | No | File attachments and inline images |
|
|
36
|
-
| `headers` | object | No | Custom email headers |
|
|
37
|
-
|
|
38
|
-
*At least one of `html` or `text` required. Include both for best deliverability.
|
|
39
|
-
|
|
40
|
-
**Key differences from Workers binding:** `from` uses `address` (REST) vs `email` (Workers), `reply_to` (REST) vs `replyTo` (Workers), `content_id` (REST) vs `contentId` (Workers) for inline attachments, errors use numeric codes (REST) vs string `E_*` codes (Workers), and responses return delivery status (`delivered`/`permanent_bounces`/`queued`) instead of just `messageId`.
|
|
41
|
-
|
|
42
|
-
## Examples
|
|
43
|
-
|
|
44
|
-
Simple send:
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
|
|
48
|
-
--header "Authorization: Bearer <API_TOKEN>" \
|
|
49
|
-
--header "Content-Type: application/json" \
|
|
50
|
-
--data '{
|
|
51
|
-
"to": "user@example.com",
|
|
52
|
-
"from": "welcome@yourdomain.com",
|
|
53
|
-
"subject": "Welcome!",
|
|
54
|
-
"html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
|
|
55
|
-
"text": "Welcome! Thanks for signing up."
|
|
56
|
-
}'
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Multiple recipients with CC/BCC:
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
|
|
63
|
-
--header "Authorization: Bearer <API_TOKEN>" \
|
|
64
|
-
--header "Content-Type: application/json" \
|
|
65
|
-
--data '{
|
|
66
|
-
"to": ["user1@example.com", "user2@example.com"],
|
|
67
|
-
"cc": ["manager@company.com"],
|
|
68
|
-
"bcc": ["archive@company.com"],
|
|
69
|
-
"from": { "address": "orders@yourdomain.com", "name": "Orders" },
|
|
70
|
-
"reply_to": "support@yourdomain.com",
|
|
71
|
-
"subject": "Order Confirmation",
|
|
72
|
-
"html": "<h1>Your order is confirmed</h1>",
|
|
73
|
-
"text": "Your order is confirmed"
|
|
74
|
-
}'
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
With attachments:
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
|
|
81
|
-
--header "Authorization: Bearer <API_TOKEN>" \
|
|
82
|
-
--header "Content-Type: application/json" \
|
|
83
|
-
--data '{
|
|
84
|
-
"to": "customer@example.com",
|
|
85
|
-
"from": "invoices@yourdomain.com",
|
|
86
|
-
"subject": "Your Invoice",
|
|
87
|
-
"html": "<h1>Invoice attached</h1>",
|
|
88
|
-
"attachments": [
|
|
89
|
-
{
|
|
90
|
-
"content": "JVBERi0xLjQKJeLjz9MK...",
|
|
91
|
-
"filename": "invoice.pdf",
|
|
92
|
-
"type": "application/pdf",
|
|
93
|
-
"disposition": "attachment"
|
|
94
|
-
}
|
|
95
|
-
]
|
|
96
|
-
}'
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
With inline images (embedded via `cid:` URI):
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
|
|
103
|
-
--header "Authorization: Bearer <API_TOKEN>" \
|
|
104
|
-
--header "Content-Type: application/json" \
|
|
105
|
-
--data '{
|
|
106
|
-
"to": "user@example.com",
|
|
107
|
-
"from": "newsletter@yourdomain.com",
|
|
108
|
-
"subject": "Check this out",
|
|
109
|
-
"html": "<h1>Hello!</h1><img src=\"cid:logo\">",
|
|
110
|
-
"attachments": [
|
|
111
|
-
{
|
|
112
|
-
"content": "iVBORw0KGgoAAAANSUhEUg...",
|
|
113
|
-
"filename": "logo.png",
|
|
114
|
-
"type": "image/png",
|
|
115
|
-
"disposition": "inline",
|
|
116
|
-
"content_id": "logo"
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
}'
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Attachment fields differ by type:
|
|
123
|
-
- **Regular attachment**: `content` (base64), `filename`, `type` (MIME), `disposition: "attachment"`
|
|
124
|
-
- **Inline image**: `content` (base64), `filename`, `type` (MIME), `disposition: "inline"`, `content_id` (referenced in HTML as `cid:<content_id>`)
|
|
125
|
-
|
|
126
|
-
With custom headers:
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/email/sending/send" \
|
|
130
|
-
--header "Authorization: Bearer <API_TOKEN>" \
|
|
131
|
-
--header "Content-Type: application/json" \
|
|
132
|
-
--data '{
|
|
133
|
-
"to": "user@example.com",
|
|
134
|
-
"from": "notifications@yourdomain.com",
|
|
135
|
-
"subject": "Your weekly digest",
|
|
136
|
-
"html": "<h1>Weekly Digest</h1>",
|
|
137
|
-
"headers": {
|
|
138
|
-
"List-Unsubscribe": "<https://yourdomain.com/unsubscribe?id=abc123>",
|
|
139
|
-
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
|
|
140
|
-
"X-Campaign-ID": "weekly-digest-2026-03"
|
|
141
|
-
}
|
|
142
|
-
}'
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
See the [email headers reference](https://developers.cloudflare.com/email-service/reference/headers/) for the full list of allowed headers.
|
|
146
|
-
|
|
147
|
-
## Response
|
|
148
|
-
|
|
149
|
-
Success:
|
|
150
|
-
|
|
151
|
-
```json
|
|
152
|
-
{
|
|
153
|
-
"success": true,
|
|
154
|
-
"errors": [],
|
|
155
|
-
"messages": [],
|
|
156
|
-
"result": {
|
|
157
|
-
"delivered": ["recipient@example.com"],
|
|
158
|
-
"permanent_bounces": [],
|
|
159
|
-
"queued": []
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
Error (numeric codes, not `E_*` string codes like Workers):
|
|
165
|
-
|
|
166
|
-
```json
|
|
167
|
-
{
|
|
168
|
-
"success": false,
|
|
169
|
-
"errors": [{ "code": 1000, "message": "Sender domain not verified" }],
|
|
170
|
-
"result": null
|
|
171
|
-
}
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## Error Handling
|
|
175
|
-
|
|
176
|
-
| Status | Meaning | Retry? |
|
|
177
|
-
|--------|---------|--------|
|
|
178
|
-
| 200 | Success | N/A |
|
|
179
|
-
| 400 | Validation error | No — fix the request |
|
|
180
|
-
| 401 | Invalid API token | No — check your token |
|
|
181
|
-
| 429 | Rate limited | Yes — exponential backoff |
|
|
182
|
-
| 500 | Server error | Yes — exponential backoff |
|
|
183
|
-
|
|
184
|
-
Only retry on 429 and 500. Validation errors (400) won't succeed on retry.
|
|
17
|
+
Do not reuse a Workers binding payload or response parser unchanged: verify field names, attachment encoding, response shape, and error handling for the chosen API. Validate both successful responses and failures through the project's existing checks; distinguish retryable service failures from requests that need correction.
|