Skip to content

Commit 06190d4

Browse files
authored
Update json-endpoint.mdx
custom models
1 parent 7215940 commit 06190d4

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

src/content/docs/browser-rendering/rest-api/json-endpoint.mdx

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ sidebar:
77

88
import { Tabs, TabItem } from "~/components";
99

10-
The `/json` endpoint extracts structured data from a webpage. You can specify the expected output using either a `prompt` or a `response_format` parameter which accepts a JSON schema. The endpoint returns the extracted data in JSON format.
10+
The `/json` endpoint extracts structured data from a webpage. You can specify the expected output using either a `prompt` or a `response_format` parameter which accepts a JSON schema. The endpoint returns the extracted data in JSON format. By default, this endpoint leverages [Workers AI](/workers-ai/). If you would like to specify your own AI model for the extraction, you can use the `custom_ai` parameter.
1111

1212
:::note[Note]
1313

14-
The `/json` endpoint leverages [Workers AI](/workers-ai/) for data extraction. Using this endpoint incurs usage on Workers AI, which you can monitor usage through the Workers AI Dashboard.
14+
By default, the `/json` endpoint leverages [Workers AI](/workers-ai/) for data extraction. Using this endpoint incurs usage on Workers AI, which you can monitor usage through the Workers AI Dashboard.
1515

1616
:::
1717

@@ -243,3 +243,79 @@ console.log(json);
243243
```
244244

245245
</TabItem> </Tabs>
246+
247+
## Advanced Usage
248+
249+
<Tabs syncKey="workersExamples"> <TabItem label="curl">
250+
251+
### Using a custom model (BYO API Key)
252+
253+
Browser Rendering can use a custom model for which you supply credentials. List the model(s) in the `custom_ai` array:
254+
255+
- `model` should be formed as `<provider>/<model_name>` and the provider must be one of these [supported providers](/ai-gateway/chat-completion/#supported-providers).
256+
- `authorization` is the bearer token or API key that allows Browser Rendering to call the provider on your behalf.
257+
258+
This example uses the `custom_ai` parameter to instruct Browser Rendering to use a custom Anthropic model. The prompt asks the model to extract the main <h1> and <h2> headings from the target URL and return them in a structured JSON object.
259+
260+
```bash
261+
curl --request POST \
262+
--url https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json \
263+
--header 'authorization: Bearer CF_API_TOKEN' \
264+
--header 'content-type: application/json' \
265+
--data '{
266+
"url": "http://demoto.xyz/headings",
267+
"prompt": "Get the heading from the page in the form of an object like h1, h2. If there are many headings of the same kind then grab the first one.",
268+
"response_format": {
269+
"type": "json_schema",
270+
"json_schema": {
271+
"type": "object",
272+
"properties": {
273+
"h1": {
274+
"type": "string"
275+
},
276+
"h2": {
277+
"type": "string"
278+
}
279+
},
280+
"required": [
281+
"h1"
282+
]
283+
}
284+
},
285+
"custom_ai": [
286+
{
287+
"model": "anthropic/claude-sonnet-4-20250514",
288+
"authorization": "Bearer <ANTHROPIC_API_KEY>"
289+
}
290+
]
291+
}
292+
```
293+
294+
```json output
295+
{
296+
"success": true,
297+
"result": {
298+
"h1": "Heading 1",
299+
"h2": "Heading 2"
300+
}
301+
}
302+
```
303+
304+
### Using a custom model with fallbacks
305+
306+
You may specify multiple models to provide automatic failover. Browser Rendering will attempt the models in order until one succeeds. To add failover, list additional models.
307+
308+
In this example, Browser Rendering first calls claude-sonnet-4-20250514. If that request returns an error, it automatically retries with gpt-4o.
309+
310+
```
311+
"custom_ai": [
312+
{
313+
"model": "anthropic/claude-sonnet-4-20250514",
314+
"authorization": "Bearer <ANTHROPIC_API_KEY>"
315+
},
316+
{
317+
"model": "openai/gpt-4o",
318+
"authorization": "Bearer <OPENAI_API_KEY>"
319+
}
320+
]
321+
```

0 commit comments

Comments
 (0)