Connect Cloudflare to AI Agents: Automate Zones & Team Access
A technical guide to connecting Cloudflare to AI agents using Truto's /tools endpoint. Learn how to automate zone management, firewall rules, and team access workflows.
Managing a sprawling Cloudflare environment via the dashboard is acceptable for a handful of sites. But when managing hundreds of zones, granular firewall rules, and complex team access, manual clicks do not scale. AI agents are the natural solution to automate these tasks, but giving an LLM reliable access to Cloudflare's API introduces a host of engineering challenges.
This article is part of a series on automating infrastructure with AI. If your team uses ChatGPT, check out our guide on connecting Cloudflare to ChatGPT, or if you prefer Anthropic, read about connecting Cloudflare to Claude.
In this guide, we will walk through exactly how to connect Cloudflare to autonomous AI agents using Truto's Proxy APIs and /tools endpoint. We will cover the specific quirks of the Cloudflare API, map out the essential tool inventory, and build a multi-step workflow using LangChain.
The Engineering Reality of the Cloudflare API
Connecting an AI agent to an infrastructure platform is never just a matter of pasting in an API key. To architect a reliable agentic workflow, you need to understand the underlying API behavior. For Cloudflare, there are three specific hurdles your implementation must overcome:
1. The Account vs. Zone Dichotomy
Cloudflare's API architecture strictly divides resources between the Account level and the Zone level. An LLM tasked with checking a firewall rule will inherently assume it can just query a global "firewall rules" endpoint. It cannot. The agent must first understand that to list firewall rules, it needs a zone_id, but to list members or audit logs, it needs an account_id. Your agent prompt and tool descriptions must clearly enforce this prerequisite chain, or the LLM will constantly fail with missing parameter errors.
2. Evolving Rulesets and WAF Overrides
Cloudflare has transitioned from its legacy Managed Rules to the newer Rulesets API. This creates a split brain in how rules are queried and applied. If an agent tries to list WAF overrides using legacy parameters, it will fail on newer zones. Tools must explicitly document that overrides apply only to previous WAF managed rules versions, requiring the agent to conditionally check rulesets via the newer list_all_cloudflare_rule_sets method.
3. Strict Rate Limiting and Required Backoff
Cloudflare heavily rate-limits its API. A common mistake is expecting an integration layer to absorb these limits. Factual note on rate limits: Truto does not retry, throttle, or apply backoff on rate limit errors. When Cloudflare returns an HTTP 429, Truto passes that error directly to the caller. Truto normalizes the upstream rate limit info into standardized headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset) per the IETF spec. The caller - meaning your agent's execution loop - is strictly responsible for implementing retry logic and backoff. You must build your agent executor to catch HTTP 429s, read the ratelimit-reset header, pause, and try again.
Cloudflare Tool Inventory for AI Agents
Truto exposes Cloudflare integration resources as proxy APIs. By calling Truto's /integrated-account/<id>/tools endpoint, you instantly provide LLMs with a predefined, validated set of tools.
Below is the two-tier structure of available tools.
Hero Tools
These are the 5 core tools your agent will use to execute the majority of its daily infrastructure tasks.
list_all_cloudflare_zones
Before an agent can touch DNS or firewall rules, it needs to find the correct zone_id. This tool lists all zones in the account.
- Usage Notes: Always encourage the agent to use the
namequery parameter to filter by domain name rather than retrieving the entire list. - Example Prompt: "Find the zone ID for example.com."
list_all_cloudflare_audit_logs
Provides a detailed trail of changes across the account. Essential for security audits and tracking down who modified a specific rule.
- Usage Notes: Requires the
account_id. The agent should be instructed to use theactorandactionquery parameters to isolate specific events. - Example Prompt: "Check the audit logs to see who created an API token in the last 24 hours."
list_all_cloudflare_members
Fetches all team members assigned to a Cloudflare account.
- Usage Notes: Useful for identity and access management (IAM) audits. Returns member IDs, roles, and status.
- Example Prompt: "List all active members in our primary Cloudflare account."
list_all_cloudflare_firewall_rules
Retrieves the firewall rules currently active on a specific zone.
- Usage Notes: The agent must be explicitly instructed to fetch the
zone_idfirst usinglist_all_cloudflare_zones, as this tool always requires the ID of the Zone. - Example Prompt: "Show me the active firewall rules for the production zone."
list_all_cloudflare_rule_sets
Lists the rulesets (the modern WAF and firewall architecture) for a specific zone.
- Usage Notes: Requires
zone_id. Returns phase, version, and descriptions, allowing the agent to analyze active WAF configurations. - Example Prompt: "List all the WAF rulesets currently enabled on the staging domain."
For the complete tool inventory and full schema details, visit the Cloudflare integration page.
Workflows in Action
By exposing these proxy APIs to an agent framework, you unlock entirely autonomous operational workflows. Here are two concrete examples of how DevOps and IT personas utilize these capabilities.
Scenario 1: The Automated Security Auditor
Security engineers often need to investigate anomalous behavior or verify compliance configurations.
Prompt: "Investigate the 'payment-gateway.com' zone. I need to know the current active firewall rules, and then check the audit logs to see if anyone modified a WAF override or ruleset in the past 48 hours."
Step-by-Step Execution:
- Agent calls
list_all_cloudflare_zoneswith thenameparameter set to "payment-gateway.com" to retrieve thezone_idand the associatedaccount_id. - Agent calls
list_all_cloudflare_firewall_rulesusing the retrievedzone_idto gather current firewall configurations. - Agent calls
list_all_cloudflare_rule_setsusing thezone_idto get the modern WAF state. - Agent calls
list_all_cloudflare_audit_logsusing theaccount_id, applying date filters and looking for WAF/firewall modification actions.
Result: The engineer receives a synthesized summary of the current firewall state, accompanied by a parsed timeline of recent changes, highlighting exactly who modified the rules and when.
Scenario 2: The Access Review Bot
IT admins perform regular User Access Reviews (UAR) to ensure least-privilege access is maintained across infrastructure.
Prompt: "Audit our Cloudflare account access. List all the current roles available, then retrieve all active members. Cross-reference the members to tell me who has 'Administrator' access."
Step-by-Step Execution:
- Agent calls
list_all_cloudflare_accountsto determine the primaryaccount_id. - Agent calls
list_all_cloudflare_rolesusing theaccount_idto fetch the exact ID and description of the "Administrator" role. - Agent calls
list_all_cloudflare_membersto retrieve the list of all users and their assigned role IDs. - The agent processes the JSON response in context, filtering the members against the Administrator role ID.
Result: The IT admin gets a clean Markdown table of all users holding Administrator privileges, without having to manually export CSVs from the Cloudflare dashboard.
Building Multi-Step Workflows
To build a multi-step workflow, you need an orchestration framework like LangChain, LangGraph, or the Vercel AI SDK. Truto is framework-agnostic; it simply provides a standard REST API that returns tools with fully hydrated JSON schemas.
If you want to read more about the architectural theory behind this, refer to our guide on /architecting-ai-agents-langgraph-langchain-and-the-saas-integration-bottleneck/.
To see this in code, you can use the truto-langchainjs-toolset. The first step is to fetch the tools available for the specific Cloudflare integrated account.
import { TrutoToolManager } from 'truto-langchainjs-toolset';
import { ChatOpenAI } from '@langchain/openai';
import { AgentExecutor, createOpenAIToolsAgent } from 'langchain/agents';
// 1. Initialize the Truto Tool Manager with your Cloudflare Integrated Account ID
const toolManager = new TrutoToolManager({
trutoApiKey: process.env.TRUTO_API_KEY,
integratedAccountId: 'cloudflare_acct_12345',
});
// 2. Fetch the tools from the Truto API
const tools = await toolManager.getTools();
// 3. Initialize your LLM
const llm = new ChatOpenAI({
modelName: 'gpt-4o',
temperature: 0,
});
// 4. Bind the tools to the LLM
const llmWithTools = llm.bindTools(tools);Handling Rate Limits in the Agent Loop
When creating your agent executor, you must account for Cloudflare's strict rate limits. Because Truto strictly acts as a proxy and passes standard ratelimit-* headers to the caller upon HTTP 429, your loop needs a retry mechanism.
graph TD
A[User Prompt] --> B[LLM Generates Tool Call]
B --> C[Agent Executor Invokes Truto Proxy API]
C --> D{Response HTTP 429?}
D -->|Yes| E[Read ratelimit-reset Header]
E --> F[Pause Execution]
F --> C
D -->|No| G[Return Data to Context]
G --> H{Task Complete?}
H -->|No| B
H -->|Yes| I[Return Final Output]If your agent makes concurrent calls to fetch firewall rules across 50 zones simultaneously, it will hit a 429. Your executor layer must wrap the tool invocation in a try/catch block that specifically looks for a 429 Too Many Requests response. When caught, read the ratelimit-reset header, wait the requested number of seconds, and retry the exact tool call before returning the result to the LLM context window.
By handling the retry logic natively in your code, you ensure the AI agent operates reliably regardless of how aggressive Cloudflare's underlying limits are on your specific tier.
FAQ
- How does Truto handle Cloudflare rate limits for AI agents?
- Truto does not retry, throttle, or apply backoff on rate limit errors. When Cloudflare returns an HTTP 429, Truto passes that error to the caller and normalizes upstream rate limit info into standardized headers (ratelimit-limit, ratelimit-remaining, ratelimit-reset). Your agent execution loop must handle the retry and backoff.
- Do I need to build custom MCP servers for Cloudflare?
- No. By using Truto's /integrated-account/
/tools endpoint, all resources and methods mapped to your Cloudflare integration are automatically served as tools with fully hydrated JSON schemas ready for LLM consumption. - Can I filter Cloudflare tools provided by Truto?
- Yes. The Truto /tools endpoint accepts query parameters like 'methods'. You can filter the tools based on method type, ensuring your agent only has access to read-only capabilities if desired.