Skip to content

Commit dbdd965

Browse files
kathaylToriLindsayRefaerds
authored andcommitted
Update json-endpoint.mdx (#23653)
* Update json-endpoint.mdx custom models * slight error fix of <h2> tag * Update src/content/docs/browser-rendering/rest-api/json-endpoint.mdx * Update json-endpoint.mdx * Update src/content/docs/browser-rendering/rest-api/json-endpoint.mdx Co-authored-by: Maryna Iholnykova <[email protected]> --------- Co-authored-by: ToriLindsay <[email protected]> Co-authored-by: Maryna Iholnykova <[email protected]>
1 parent 32c5ccf commit dbdd965

File tree

1 file changed

+81
-2
lines changed

1 file changed

+81
-2
lines changed

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

Lines changed: 81 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,82 @@ console.log(json);
243243
```
244244

245245
</TabItem> </Tabs>
246+
247+
## Advanced Usage
248+
249+
250+
### Using a custom model (BYO API Key)
251+
252+
Browser Rendering can use a custom model for which you supply credentials. List the model(s) in the `custom_ai` array:
253+
254+
- `model` should be formed as `<provider>/<model_name>` and the provider must be one of these [supported providers](/ai-gateway/chat-completion/#supported-providers).
255+
- `authorization` is the bearer token or API key that allows Browser Rendering to call the provider on your behalf.
256+
257+
This example uses the `custom_ai` parameter to instruct Browser Rendering to use a Anthropic's Claude Sonnet 4 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.
258+
259+
```bash
260+
curl --request POST \
261+
--url https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json \
262+
--header 'authorization: Bearer CF_API_TOKEN' \
263+
--header 'content-type: application/json' \
264+
--data '{
265+
"url": "http://demoto.xyz/headings",
266+
"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.",
267+
"response_format": {
268+
"type": "json_schema",
269+
"json_schema": {
270+
"type": "object",
271+
"properties": {
272+
"h1": {
273+
"type": "string"
274+
},
275+
"h2": {
276+
"type": "string"
277+
}
278+
},
279+
"required": [
280+
"h1"
281+
]
282+
}
283+
},
284+
"custom_ai": [
285+
{
286+
"model": "anthropic/claude-sonnet-4-20250514",
287+
"authorization": "Bearer <ANTHROPIC_API_KEY>"
288+
}
289+
]
290+
}
291+
```
292+
293+
```json output
294+
{
295+
"success": true,
296+
"result": {
297+
"h1": "Heading 1",
298+
"h2": "Heading 2"
299+
}
300+
}
301+
```
302+
303+
### Using a custom model with fallbacks
304+
305+
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 in the `custom_ai` array.
306+
307+
In this example, Browser Rendering first calls Anthropic's Claude Sonnet 4 model. If that request returns an error, it automatically retries with Meta Llama 3.3 70B from [Workers AI](/workers-ai/), then OpenAI's GPT-4o.
308+
309+
```
310+
"custom_ai": [
311+
{
312+
"model": "anthropic/claude-sonnet-4-20250514",
313+
"authorization": "Bearer <ANTHROPIC_API_KEY>"
314+
},
315+
{
316+
"model": "workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast",
317+
"authorization": "Bearer <CLOUDFLARE_AUTH_TOKEN>"
318+
},
319+
{
320+
"model": "openai/gpt-4o",
321+
"authorization": "Bearer <OPENAI_API_KEY>"
322+
}
323+
]
324+
```

0 commit comments

Comments
 (0)