Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
16d5d9e
Guardails docs
daisyfaithauma Feb 21, 2025
8e7de6b
Merge branch 'production' of https://github.com/cloudflare/cloudflare…
daisyfaithauma Feb 21, 2025
1deed6d
Merge branch 'production' of https://github.com/cloudflare/cloudflare…
daisyfaithauma Feb 24, 2025
b9b204a
Merge branch 'production' of https://github.com/cloudflare/cloudflare…
daisyfaithauma Feb 24, 2025
912be66
Initial commit
daisyfaithauma Feb 24, 2025
9bc1e3d
quick actions endpoints
daisyfaithauma Feb 24, 2025
7a32d66
Fix
kodster28 Feb 24, 2025
33e5fa8
change to bullets
daisyfaithauma Feb 25, 2025
0e582ac
moved get started to a file
daisyfaithauma Feb 26, 2025
1ac96e4
summary
daisyfaithauma Feb 26, 2025
963a7f3
summar of endpoints
daisyfaithauma Feb 26, 2025
80549ce
fixed merge conflict
kodster28 Feb 26, 2025
423edaa
code samples
daisyfaithauma Feb 26, 2025
17c3b53
Merge branch 'rendering-quick-actions' of https://github.com/cloudfla…
daisyfaithauma Feb 26, 2025
7f85bbc
code samples and title change
daisyfaithauma Feb 26, 2025
888f77b
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 26, 2025
13fbe0b
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 26, 2025
8a9346d
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 26, 2025
412e75e
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 26, 2025
08f7fe5
director listing
daisyfaithauma Feb 26, 2025
26957d9
Merge branch 'rendering-quick-actions' of https://github.com/cloudfla…
daisyfaithauma Feb 26, 2025
1e91167
added code sample
daisyfaithauma Feb 26, 2025
864b0ee
index descriptions
daisyfaithauma Feb 26, 2025
7159abb
redirects
daisyfaithauma Feb 26, 2025
f01f28d
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 26, 2025
7602ec4
delete custom css
daisyfaithauma Feb 26, 2025
e162f5a
Merge branch 'rendering-quick-actions' of https://github.com/cloudfla…
daisyfaithauma Feb 26, 2025
daa44b8
fixes from responses
daisyfaithauma Feb 26, 2025
17a6931
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 26, 2025
10d25f4
code fixes
daisyfaithauma Feb 26, 2025
105a878
parameters added
daisyfaithauma Feb 26, 2025
d17637a
Update get-started.mdx
kathayl Feb 26, 2025
7863d7c
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
b5bb84f
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
e90f198
Update src/content/docs/browser-rendering/quick-actions-rest-api/inde…
daisyfaithauma Feb 27, 2025
43ba4b1
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
8afb47e
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
41a5fc8
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
b8655d5
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
93bff6e
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
581c2d3
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 27, 2025
3109164
Update src/content/docs/browser-rendering/quick-actions-rest-api/scra…
daisyfaithauma Feb 27, 2025
8ee92dd
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
161492d
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
5335a26
minor fixes
daisyfaithauma Feb 27, 2025
e5fe663
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
3db0a71
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
048a6e2
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
5371bdf
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
d6b0ad7
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
0de2ee8
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
51803f9
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
69f7a8d
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
5adf461
Update src/content/docs/browser-rendering/quick-actions-rest-api/inde…
daisyfaithauma Feb 27, 2025
9225637
Update src/content/docs/browser-rendering/quick-actions-rest-api/inde…
daisyfaithauma Feb 27, 2025
21bb019
Update src/content/docs/browser-rendering/workers-binding-api/index.mdx
daisyfaithauma Feb 27, 2025
a4d75c9
Update src/content/docs/browser-rendering/quick-actions-rest-api/snap…
daisyfaithauma Feb 27, 2025
b68d7e6
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
35e2abd
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
6fb4b3b
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
a80e9c8
Update src/content/docs/browser-rendering/quick-actions-rest-api/cont…
daisyfaithauma Feb 27, 2025
ad050ce
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
11c235f
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
4653fd5
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
96fe9a2
Update src/content/docs/browser-rendering/quick-actions-rest-api/pdf-…
daisyfaithauma Feb 27, 2025
e0d8002
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
048a8b1
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
d567aaf
Update src/content/docs/browser-rendering/quick-actions-rest-api/scre…
daisyfaithauma Feb 27, 2025
eff3d93
minor fixes
daisyfaithauma Feb 27, 2025
e31c9ad
links fix
daisyfaithauma Feb 27, 2025
227b7b1
Update src/content/docs/browser-rendering/workers-binding-api/reuse-s…
daisyfaithauma Feb 27, 2025
ffd76d6
code fix
daisyfaithauma Feb 27, 2025
d4c37ca
removed link
daisyfaithauma Feb 27, 2025
bd711a5
Fix error
kodster28 Feb 27, 2025
0540b69
Added beta badge
kodster28 Feb 27, 2025
7034b6e
Update public/_redirects
kodster28 Feb 27, 2025
84accea
Small edit
kodster28 Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/content/docs/ai-gateway/guardrails/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Guardrails in AI Gateway
pcx_content_type: navigation
order: 1
sidebar:
order: 8
group:
badge: Beta
---

Guardrails help you deploy AI applications safely by intercepting and evaluating both user prompts and model responses for harmful content. Acting as a proxy between your application and [model providers](/ai-gateway/providers)(such as OpenAI, Anthropic, DeepSeek, and others), Guardrails ensures a consistent and secure experience across your entire AI ecosystem.

Guardrails proactively monitor interactions between users and AI models, allowing you to:

- Protect users by detecting and mitigating harmful content.
- Meet compliance requirements by aligning with evolving regulatory standards.
- Optimize costs by preventing unnecessary processing of harmful requests early.
53 changes: 53 additions & 0 deletions src/content/docs/ai-gateway/guardrails/set-up-guardrail.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
pcx_content_type: how-to
title: How Guardrails works
sidebar:
order: 3
---

AI Gateway inspects all interactions in real time by evaluating content against predefined safety parameters. Below a breakdown of the process:

1. Intercepting interactions:
AI Gateway proxies requests and responses, sitting between the user and the AI model.

2. Inspecting content:

- User prompts: AI Gateway checks prompts against safety parameters (for example, violence, hate, or sexual content). Based on your settings, prompts can be flagged or blocked before reaching the model.
- Model responses: Once processed, the AI model response is inspected. If hazardous content is detected, it can be flagged or blocked before being delivered to the user.

3. Applying actions:
Depending on your configuration, flagged content is logged for review, while blocked content is prevented from proceeding.

## Supported model types

Guardrails determines the type of AI model being used and applies safety checks accordingly:

- Text generation models: Both prompts and responses are evaluated.
- Embedding models: Only the prompt is evaluated, and the response is passed directly back to the user.
- Unknown models: If the model type cannot be determined, prompts are evaluated, but responses bypass Guardrails.

If Guardrails cannot access the underlying model, requests set to "block" will result in an error, while flagged requests will proceed.

## Configuration

Within AI Gateway settings, you can customize Guardrails:

- Enable or disable content moderation.
- Choose evaluation scope: Analyze user prompts, model responses, or both.
- Define hazard categories: Select categories like violence, hate, or sexual content and assign actions (ignore, flag, or block).

## Workers AI and Guardrails

Guardrails currently uses [Llama Guard 3 8B](https://ai.meta.com/research/publications/llama-guard-llm-based-input-output-safeguard-for-human-ai-conversations/) on [Workers AI](/workers-ai/) to perform content evaluations. The underlying model may be updated in the future, and we will reflect those changes within Guardrails.

Since Guardrails runs on Workers AI, enabling it incurs usage on Workers AI. You can monitor usage through the Workers AI Dashboard.

## Additional considerations

- Latency impact: Enabling Guardrails adds some latency. Consider this when balancing safety and speed.

:::note

Llama Guard is provided as-is without any representations, warranties, or guarantees. Any rules or examples contained in blogs, developer docs, or other reference materials are provided for informational purposes only. You acknowledge and understand that you are responsible for the results and outcomes of your use of AI Gateway.

:::
4 changes: 2 additions & 2 deletions src/content/docs/browser-rendering/get-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pcx_content_type: navigation
title: Get started
sidebar:
order: 2
group:
hideIndex: true
---

import { DirectoryListing } from "~/components";

Browser rendering can be used in two ways: the [Workers Binding API](/browser-rendering/workers-binding-api) for complex scripts and the Quick Actions REST API for [simple actions](/browser-rendering/quick-actions-rest-api/).

<DirectoryListing />
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
pcx_content_type: how-to
title: Retrieve HTML content
sidebar:
order: 2
---

Retrieve the HTML content of a specified URL by sending a POST request to the `/content` endpoint.

```
curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/content' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <apiToken>' \
-d '{"url": "https://example.com"}'
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
pcx_content_type: how-to
title: Customize CSS and take a screenshot
sidebar:
order: 4
---

Customise the rendering by adding external JavaScript and CSS before capturing a screenshot.

```
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/screenshot' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"addScriptTag": [
{ "url": "https://code.jquery.com/jquery-3.7.1.min.js" },
{ "content": "document.querySelector(`h1`).innerText = `Hello World!!!`" }
],
"addStyleTag": [
{
"content": "body { background: linear-gradient(45deg, #da5a44, #a32784); }"
},
{
"url": "https://interactive-examples.mdn.mozilla.net/live-examples/css-examples/text-decoration/text-decoration-color.css"
}
]
}' \
--output "screenshot.webp"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
pcx_content_type: navigation
title: Quick Actions API
sidebar:
order: 2
---

The Quick Actions API is a RESTful interface that provides endpoints for common browser actions such as capturing screenshots, extracting HTML content, generating PDFs, and more. This API is designed to help you interact with web pages quickly and efficiently.

Before you begin, make sure to create a custom **API Token** with your Account > **Browser Rendering**> **Edit** permissions from the [Cloudflare dashboard](https://dash.cloudflare.com/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
pcx_content_type: how-to
title: Generate PDF
sidebar:
order: 5
---

```
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/pdf' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"addStyleTag": [
{ "content": "body { font-family: Arial; }" }
]
}' \
--output "output.pdf"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
pcx_content_type: how-to
title: Scrape content
sidebar:
order: 7
---

```
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/scrape' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"scrapeOptions": {
"selectors": ["h1", ".article"]
}
}'
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
pcx_content_type: how-to
title: Render HTML and capture screenshot
sidebar:
order: 3
---

Render a provided HTML string and capture a screenshot with specific options.

```
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/screenshot' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"html": "Hello World!",
"screenshotOptions": {
"type": "webp",
"omitBackground": true
}
}' \
--output "screenshot.webp"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
pcx_content_type: how-to
title: Capture snapshot
sidebar:
order: 6
---

```
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountTag>/browser-rendering/snapshot' \
-H 'Authorization: Bearer <apiToken>' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"addScriptTag": [
{ "content": "document.title = \"Snapshot Page\";" }
]
}'
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
pcx_content_type: navigation
title: Workers Binding API
sidebar:
order: 2
group:
---

import { DirectoryListing } from "~/components";

<DirectoryListing />
Loading