You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/browser-rendering/rest-api/json-endpoint.mdx
+81-2Lines changed: 81 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ sidebar:
7
7
8
8
import { Tabs, TabItem } from"~/components";
9
9
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.
11
11
12
12
:::note[Note]
13
13
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.
15
15
16
16
:::
17
17
@@ -243,3 +243,82 @@ console.log(json);
243
243
```
244
244
245
245
</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.
"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.
0 commit comments