Skip to content

Update json-endpoint.mdx #23653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: production
Choose a base branch
from
Open
Changes from all commits
Commits
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
80 changes: 78 additions & 2 deletions src/content/docs/browser-rendering/rest-api/json-endpoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ sidebar:

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

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.
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.

:::note[Note]

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.
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.

:::

Expand Down Expand Up @@ -243,3 +243,79 @@ console.log(json);
```

</TabItem> </Tabs>

## Advanced Usage

<Tabs syncKey="workersExamples"> <TabItem label="curl">

### Using a custom model (BYO API Key)

Browser Rendering can use a custom model for which you supply credentials. List the model(s) in the `custom_ai` array:

- `model` should be formed as `<provider>/<model_name>` and the provider must be one of these [supported providers](/ai-gateway/chat-completion/#supported-providers).
- `authorization` is the bearer token or API key that allows Browser Rendering to call the provider on your behalf.

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.

```bash
curl --request POST \
--url https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json \
--header 'authorization: Bearer CF_API_TOKEN' \
--header 'content-type: application/json' \
--data '{
"url": "http://demoto.xyz/headings",
"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.",
"response_format": {
"type": "json_schema",
"json_schema": {
"type": "object",
"properties": {
"h1": {
"type": "string"
},
"h2": {
"type": "string"
}
},
"required": [
"h1"
]
}
},
"custom_ai": [
{
"model": "anthropic/claude-sonnet-4-20250514",
"authorization": "Bearer <ANTHROPIC_API_KEY>"
}
]
}
```

```json output
{
"success": true,
"result": {
"h1": "Heading 1",
"h2": "Heading 2"
}
}
```

### Using a custom model with fallbacks

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 this example, Browser Rendering first calls claude-sonnet-4-20250514. If that request returns an error, it automatically retries with gpt-4o.

```
"custom_ai": [
{
"model": "anthropic/claude-sonnet-4-20250514",
"authorization": "Bearer <ANTHROPIC_API_KEY>"
},
{
"model": "openai/gpt-4o",
"authorization": "Bearer <OPENAI_API_KEY>"
}
]
```
Loading