AI Automation
Asynchronous Human Approval Patterns for AI Workflows Using Cloudflare Workers AI and n8n
TL;DR: Use Cloudflare Workers AI to run the AI step, push the result to an n8n queue, let a human approve or reject via a simple web UI, and let n8n continue the pipeline only after the decision. This pattern keeps latency low, isolates human work, and provides an auditable log without stalling the entire workflow.
Why asynchronous human approval matters for small teams
Human‑in‑the‑loop (HITL) checks are essential when AI makes decisions that affect customers, finances, or compliance. A synchronous block—waiting for a person before the AI step finishes—creates a bottleneck that can stall the entire pipeline, especially when the team is lean. Asynchronous approval decouples the AI execution from the human review, allowing the AI to continue processing new inputs while pending items sit in a queue.
How to set up an async approval queue with Cloudflare Workers AI
Cloudflare Workers AI lets you call a model directly from a serverless edge function. The function can return the raw AI output and a task_id that uniquely identifies the request. Store the task_id and the output in a durable store (e.g., Cloudflare KV or R2) and push a reference to an n8n webhook.
export default {
async fetch(request) {
const { prompt } = await request.json();
const aiResult = await AI.run({ model: "@cf/meta/llama-2-7b-chat", prompt });
const taskId = crypto.randomUUID();
await KV.put(taskId, JSON.stringify(aiResult));
await fetch("https://n8n.example.com/webhook/approval", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ taskId })
});
return new Response(JSON.stringify({ taskId }), { status: 202 });
}
};
This snippet shows the core idea: the AI call returns immediately (HTTP 202), while the downstream approval is handled by n8n.
Integrating n8n as the orchestration layer
n8n provides a visual workflow editor that can receive the webhook, fetch the stored AI result, and present it to a human via a simple UI node (e.g., the built‑in Form node or a custom HTML page hosted on Cloudflare Pages). The workflow looks like this:
- Webhook trigger receives
taskId. - HTTP Request node reads the AI result from KV.
- Set‑Variable node formats the data for display.
- Form node shows the result and two buttons: Approve or Reject.
- Based on the choice, route the flow to either the continue branch (e.g., send the result to a downstream API) or the reject branch (e.g., log the event and notify the owner).
Because n8n runs on a regular VM or Docker container, the human can take minutes or hours to respond without affecting the edge‑function latency.
Ensuring security and auditability
Both Cloudflare Workers and n8n support fine‑grained access controls. Follow these steps:
- Restrict the KV namespace to the Worker’s service token only.
- Protect the n8n webhook with a short‑lived HMAC token (see the n8n documentation).
- Log every approval decision with a timestamp, user ID, and the original
taskId. Store logs in an immutable bucket (e.g., Cloudflare R2 with versioning enabled). - Apply the OWASP Top 10 for LLM applications recommendations, especially Prompt Injection and Data Exposure, by sanitizing any user‑generated content before it reaches the model.
Monitoring and alerting for bottlenecks
Even with an async queue, a backlog can indicate a staffing issue or a mis‑configured timeout. Set up the following metrics in your observability stack (e.g., Cloudflare Analytics + Grafana):
- Number of pending approvals per hour.
- Average time from
taskIdcreation to human decision. - Failure rate of KV reads or webhook deliveries.
Configure alerts (e.g., Slack webhook) when pending approvals exceed a threshold or when the average decision time grows beyond a service‑level target.
Step‑by‑step checklist
- Deploy a Cloudflare Workers AI script that returns a
taskIdand stores the result in KV. - Create an n8n workflow with a webhook trigger that receives the
taskId. - Add an HTTP Request node to fetch the AI output from KV.
- Design a simple approval UI (Form node or custom page) that shows the AI result and captures the decision.
- Branch the workflow based on the decision: forward approved data, or log and notify on rejection.
- Secure the webhook with an HMAC token and limit KV access to the Worker’s service token.
- Log every decision to an immutable storage bucket for audit purposes.
- Instrument metrics for pending approvals, decision latency, and error rates.
- Set up alerts for backlog growth or error spikes.
- Run a dry‑run with a test user, verify that the end‑to‑end latency stays under your target (e.g., < 2 seconds for the AI call, < 5 seconds for queue insertion).
FAQ
Can I use a different no‑code platform instead of n8n?
Yes. The pattern works with any tool that can receive a webhook, fetch data, and present a UI for approval. Zapier, Make, or even a custom lightweight Flask app can replace n8n, but n8n offers the most flexibility without vendor lock‑in.
What if the human never approves a task?
Implement a timeout node in n8n that automatically routes stale tasks to a “needs escalation” branch after a configurable period (e.g., 24 hours). This prevents indefinite buildup.
Is the AI output stored in clear text safe?
Store the raw output in an encrypted KV namespace or R2 bucket. Cloudflare KV supports encryption at rest, and you can add an additional layer by encrypting the payload before storage using a per‑tenant key.
Do I need to worry about prompt‑injection attacks in this flow?
Yes. Validate any user‑provided prompt before sending it to the model. The OWASP LLM Top 10 recommends a whitelist of allowed tokens or a sanitization step that strips potentially malicious commands.
How does this pattern affect cost?
Edge AI calls are billed per token, and KV storage is cheap. The main cost driver is the n8n runtime; running it on a modest VPS or a managed n8n.cloud plan typically stays under $20 / month for low‑volume use.
Want this kind of automation built for your workflow?
AISecAll designs, builds, deploys, and maintains focused AI automations for small companies and independent entrepreneurs.