From 961b19fac226519218ea393606a5da562f78eeb2 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Tue, 18 Mar 2025 15:34:46 +0000 Subject: [PATCH 1/4] added release note --- src/content/release-notes/ai-gateway.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/content/release-notes/ai-gateway.yaml b/src/content/release-notes/ai-gateway.yaml index 6e51d8e0c7a95a..ced2940ca67ae1 100644 --- a/src/content/release-notes/ai-gateway.yaml +++ b/src/content/release-notes/ai-gateway.yaml @@ -5,6 +5,10 @@ productLink: "/ai-gateway/" productArea: Developer platform productAreaLink: /workers/platform/changelog/platform/ entries: + - publish_date: "2025-03-18" + title: WebSockets + description: |- + Added [WebSockets API](/ai-gateway/configuration/websockets-api/) provide a persistent connection for AI interactions, eliminating repeated handshakes and reducing latency. - publish_date: "2025-02-26" title: Guardrails description: |- From a45f272df7129b7107d3f5facd25b76c76f83573 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 19 Mar 2025 14:25:32 +0000 Subject: [PATCH 2/4] release notes --- src/content/release-notes/ai-gateway.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/release-notes/ai-gateway.yaml b/src/content/release-notes/ai-gateway.yaml index ced2940ca67ae1..ce49e59bcdbf9b 100644 --- a/src/content/release-notes/ai-gateway.yaml +++ b/src/content/release-notes/ai-gateway.yaml @@ -8,7 +8,7 @@ entries: - publish_date: "2025-03-18" title: WebSockets description: |- - Added [WebSockets API](/ai-gateway/configuration/websockets-api/) provide a persistent connection for AI interactions, eliminating repeated handshakes and reducing latency. + Added [WebSockets API](/ai-gateway/configuration/websockets-api/) to provide a persistent connection for AI interactions, eliminating repeated handshakes and reducing latency. - publish_date: "2025-02-26" title: Guardrails description: |- From e4af71181d58d150d6b01c447f935438109f9de0 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 19 Mar 2025 16:14:33 +0000 Subject: [PATCH 3/4] initial docs for json endpoint --- .../rest-api/json-endpoint.mdx | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/content/docs/browser-rendering/rest-api/json-endpoint.mdx diff --git a/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx new file mode 100644 index 00000000000000..0dbfbfa5e80c1a --- /dev/null +++ b/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx @@ -0,0 +1,135 @@ +--- +pcx_content_type: how-to +title: Capture Webpage Data in JSON Format +sidebar: + order: 9 +--- + +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. + +## Parameters + +| Parameter | Mandatory | Note | +| ------------------- | --------- | -------------------------------------------------------------------------------- | +| **url** | **yes** | The URL of the webpage to extract data from. | +| **prompt** | **no** | **Must supply one of `prompt` or `response_format`**. | +| **response_format** | **no** | **Must supply one of `prompt` or `response_format`**. May include a JSON schema. | + +## Basic Usage + +### With a Prompt and JSON Schema + +This example captures webpage data by providing both a prompt and a JSON schema. If multiple headings exist, the first occurrence of each (e.g. `h1`, `h2`) is returned. + +```bash +curl --request POST '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. If there are many then grab the first one.", + "response_format": { + "type": "json_schema", + "json_schema": { + "type": "object", + "properties": { + "h1": { + "type": "string" + }, + "h2": { + "type": "string" + } + }, + "required": [ + "h1" + ] + } + } + }' +``` + +#### JSON Response + +```json title="json response" +{ + "success": true, + "result": { + "h1": "Heading 1", + "h2": "Heading 2" + } +} +``` + +### With Only a Prompt + +In this example, only a prompt is provided. The endpoint will use the prompt to extract the heading information from the page. + +```bash +curl --request POST '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." + }' +``` + +#### JSON Response + +```json title="json response" +{ + "success": true, + "result": { + "h1": "Heading 1", + "h2": "Heading 2" + } +} +``` + +### With Only a JSON Schema (No Prompt) + +In this case, you supply a JSON schema via the `response_format` parameter. The schema defines the structure of the extracted data. + +```bash +curl --request POST '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", + "response_format": { + "type": "json_schema", + "json_schema": { + "type": "object", + "properties": { + "h1": { + "type": "string" + }, + "h2": { + "type": "string" + } + }, + "required": [ + "h1" + ] + } + } + }' +``` + +#### JSON Response + +```json title="json response" +{ + "success": true, + "result": { + "h1": "Heading 1", + "h2": "Heading 2" + } +} +``` + +## Potential Use-Cases + +1. **Extract Movie Data:** Retrieve details like name, genre, and release date for the top 10 action movies from the IMDB top 250 list by supplying the appropriate IMDB link and JSON schema. +2. **Weather Information:** Fetch current weather conditions for a location (e.g., Edinburgh) using a weather website link (like from BBC Weather). +3. **Trending News:** Extract top trending posts on Hacker News by providing the Hacker News link along with a JSON schema that includes post title and body. From aa4724663b6cdcc3de06062f6532ec5b225c2b8e Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 19 Mar 2025 16:32:28 +0000 Subject: [PATCH 4/4] minor fixes --- .../rest-api/json-endpoint.mdx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx index 0dbfbfa5e80c1a..78f329e7ba10fc 100644 --- a/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/json-endpoint.mdx @@ -1,23 +1,23 @@ --- pcx_content_type: how-to -title: Capture Webpage Data in JSON Format +title: Capture webpage data in JSON format sidebar: order: 9 --- -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. ## Parameters -| Parameter | Mandatory | Note | -| ------------------- | --------- | -------------------------------------------------------------------------------- | -| **url** | **yes** | The URL of the webpage to extract data from. | -| **prompt** | **no** | **Must supply one of `prompt` or `response_format`**. | -| **response_format** | **no** | **Must supply one of `prompt` or `response_format`**. May include a JSON schema. | +| Parameter | Mandatory | Note | +| --------------- | --------- | ---------------------------------------------------------------------------- | +| url | yes | The URL of the webpage to extract data from. | +| prompt | no | Must supply one of `prompt` or `response_format`. | +| response_format | no | Must supply one of `prompt` or `response_format`. May include a JSON schema. | -## Basic Usage +## Basic usage -### With a Prompt and JSON Schema +### With a prompt and JSON schema This example captures webpage data by providing both a prompt and a JSON schema. If multiple headings exist, the first occurrence of each (e.g. `h1`, `h2`) is returned. @@ -48,7 +48,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID }' ``` -#### JSON Response +#### JSON response ```json title="json response" { @@ -60,7 +60,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID } ``` -### With Only a Prompt +### With only a prompt In this example, only a prompt is provided. The endpoint will use the prompt to extract the heading information from the page. @@ -74,7 +74,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID }' ``` -#### JSON Response +#### JSON response ```json title="json response" { @@ -86,7 +86,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID } ``` -### With Only a JSON Schema (No Prompt) +### With only a JSON schema (no prompt) In this case, you supply a JSON schema via the `response_format` parameter. The schema defines the structure of the extracted data. @@ -116,7 +116,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID }' ``` -#### JSON Response +#### JSON response ```json title="json response" { @@ -128,7 +128,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID } ``` -## Potential Use-Cases +## Potential use-cases 1. **Extract Movie Data:** Retrieve details like name, genre, and release date for the top 10 action movies from the IMDB top 250 list by supplying the appropriate IMDB link and JSON schema. 2. **Weather Information:** Fetch current weather conditions for a location (e.g., Edinburgh) using a weather website link (like from BBC Weather).