--- name: cloudflare description: Turn any web page into clean Markdown, render pages, and make quick images with Workers AI on Cloudflare. Use when the user wants to read or save a page as Markdown, needs a page that only renders with JavaScript, or wants a fast, nearly free image. Needs CLOUDFLARE_API_KEY (an API token). --- # Cloudflare Key: `CLOUDFLARE_API_KEY`, an API token from https://dash.cloudflare.com/profile/api-tokens with **Browser Rendering - Edit** and **Workers AI - Read/Edit**. Examples pipe JSON through `jq`. Without it, read the JSON and take the field named in each step. ## Account id Every call has the account id in its path. Use `CLOUDFLARE_ACCOUNT_ID` if it's set. Otherwise look it up, from the account list or, for tokens that can't read it, from a zone: ```bash curl -s https://api.cloudflare.com/client/v4/accounts -H "Authorization: Bearer $CLOUDFLARE_API_KEY" | jq -r '.result[0].id' curl -s "https://api.cloudflare.com/client/v4/zones?per_page=1" -H "Authorization: Bearer $CLOUDFLARE_API_KEY" | jq -r '.result[0].account.id' ``` It's also the long hex string in the dashboard's URL. ## A page as Markdown ```bash curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/browser-run/markdown" \ -H "Authorization: Bearer $CLOUDFLARE_API_KEY" -H "Content-Type: application/json" \ -d '{"url":"https://example.com","gotoOptions":{"waitUntil":"networkidle2"}}' \ | jq -r '.result' ``` `/browser-run/content` returns the rendered HTML instead. ## A quick image ```bash curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/run/@cf/black-forest-labs/flux-1-schnell" \ -H "Authorization: Bearer $CLOUDFLARE_API_KEY" -H "Content-Type: application/json" \ -d '{"prompt":"A paper boat on a puddle, golden hour","steps":8}' \ | jq -r '.result.image' | base64 --decode > image.jpg ``` ## Notes - A 401 "Authentication error" on one call but not another means the token is missing that permission. Edit the token and add it. - The free plan includes 10 minutes of browser time and 10,000 Workers AI neurons a day. - More image models: https://developers.cloudflare.com/workers-ai/models/