From 8c07c516d296525064bde5e72648c9d64316f485 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Mon, 18 May 2026 12:56:10 -0700 Subject: [PATCH 1/4] [AI Gateway] Add REST API changelog --- .../ai-gateway/2026-05-18-rest-api.mdx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx diff --git a/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx new file mode 100644 index 000000000000000..39329d0dd429940 --- /dev/null +++ b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx @@ -0,0 +1,31 @@ +--- +title: Call any AI model through AI Gateway's new REST API +description: Call third-party and Workers AI models through one Cloudflare REST API, with AI Gateway features applied automatically. +products: + - ai-gateway +date: 2026-05-18 +--- + +AI Gateway now has its own REST API on `api.cloudflare.com`. You can call any model — whether from OpenAI, Anthropic, Google, or hosted on Workers AI — through one unified API, using the same endpoints and authentication regardless of provider. Three endpoints are available: + +- `POST /ai/run` — universal endpoint for all models and modalities +- `POST /ai/v1/chat/completions` — OpenAI SDK compatible +- `POST /ai/v1/responses` — OpenAI Responses API compatible + +```bash +curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \ + --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + --header "Content-Type: application/json" \ + --data '{ + "model": "openai/gpt-5.5", + "messages": [{"role": "user", "content": "What is Cloudflare?"}] + }' +``` + +All AI Gateway features — logging, caching, rate limiting, and guardrails — are applied automatically. Third-party models are billed through [Unified Billing](/ai-gateway/features/unified-billing/), so you do not need to manage separate provider API keys. + +Every request through the REST API is routed through your account's default gateway, which is created automatically on first use. To route requests through a specific gateway, add the `cf-aig-gateway-id` header. + +If you are already calling Workers AI models through the existing REST API, switching is straightforward: replace `/ai/run/@cf/{model}` with `/ai/run`, and move the model name into the request body with `"provider": "cloudflare"`. + +For more details and examples, refer to the [REST API documentation](/ai-gateway/usage/rest-api/). From cec0d5e47b8e758dff4ff9aeec8a99eac3083062 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Mon, 18 May 2026 13:43:34 -0700 Subject: [PATCH 2/4] Update src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com> --- src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx index 39329d0dd429940..ae09bdc8b76ccef 100644 --- a/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx +++ b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx @@ -26,6 +26,6 @@ All AI Gateway features — logging, caching, rate limiting, and guardrails — Every request through the REST API is routed through your account's default gateway, which is created automatically on first use. To route requests through a specific gateway, add the `cf-aig-gateway-id` header. -If you are already calling Workers AI models through the existing REST API, switching is straightforward: replace `/ai/run/@cf/{model}` with `/ai/run`, and move the model name into the request body with `"provider": "cloudflare"`. +If you are already calling Workers AI models through the existing REST API, replace `/ai/run/@cf/{model}` with `/ai/run`, and move the model name into the request body with `"provider": "cloudflare"`. For more details and examples, refer to the [REST API documentation](/ai-gateway/usage/rest-api/). From 10d6bf3afb416ec1fe8cb112caae0de2dfa14e99 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Mon, 18 May 2026 14:52:06 -0700 Subject: [PATCH 3/4] [AI Gateway] Address PR feedback on REST API changelog --- src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx index ae09bdc8b76ccef..795f0a1a122efbf 100644 --- a/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx +++ b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx @@ -3,10 +3,10 @@ title: Call any AI model through AI Gateway's new REST API description: Call third-party and Workers AI models through one Cloudflare REST API, with AI Gateway features applied automatically. products: - ai-gateway -date: 2026-05-18 +date: 2026-05-19 --- -AI Gateway now has its own REST API on `api.cloudflare.com`. You can call any model — whether from OpenAI, Anthropic, Google, or hosted on Workers AI — through one unified API, using the same endpoints and authentication regardless of provider. Three endpoints are available: +AI Gateway now uses the AI REST API on `api.cloudflare.com`. You can call any model — whether from OpenAI, Anthropic, Google, or hosted on Workers AI — through one unified API, using the same endpoints and authentication regardless of provider. Three endpoints are available: - `POST /ai/run` — universal endpoint for all models and modalities - `POST /ai/v1/chat/completions` — OpenAI SDK compatible @@ -26,6 +26,6 @@ All AI Gateway features — logging, caching, rate limiting, and guardrails — Every request through the REST API is routed through your account's default gateway, which is created automatically on first use. To route requests through a specific gateway, add the `cf-aig-gateway-id` header. -If you are already calling Workers AI models through the existing REST API, replace `/ai/run/@cf/{model}` with `/ai/run`, and move the model name into the request body with `"provider": "cloudflare"`. +If you are already calling Workers AI models through the existing REST API, that path (`/ai/run/@cf/{model}`) continues to work. To call Workers AI models through AI Gateway, replace it with `/ai/run` and move the model name into the request body with `"provider": "cloudflare"`. For more details and examples, refer to the [REST API documentation](/ai-gateway/usage/rest-api/). From 28a93c4d1fcf0e524e5b1bfdcdb7fc45dc1e84e9 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Tue, 19 May 2026 10:20:19 -0700 Subject: [PATCH 4/4] [AI Gateway] Add Anthropic Messages API endpoint to REST API docs and changelog --- .../ai-gateway/2026-05-18-rest-api.mdx | 1 + .../docs/ai-gateway/usage/rest-api.mdx | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx index 795f0a1a122efbf..0bd29c50f7885d7 100644 --- a/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx +++ b/src/content/changelog/ai-gateway/2026-05-18-rest-api.mdx @@ -11,6 +11,7 @@ AI Gateway now uses the AI REST API on `api.cloudflare.com`. You can call any mo - `POST /ai/run` — universal endpoint for all models and modalities - `POST /ai/v1/chat/completions` — OpenAI SDK compatible - `POST /ai/v1/responses` — OpenAI Responses API compatible +- `POST /ai/v1/messages` — Anthropic SDK compatible ```bash curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \ diff --git a/src/content/docs/ai-gateway/usage/rest-api.mdx b/src/content/docs/ai-gateway/usage/rest-api.mdx index c948966cfa84708..c4f05d7773f604f 100644 --- a/src/content/docs/ai-gateway/usage/rest-api.mdx +++ b/src/content/docs/ai-gateway/usage/rest-api.mdx @@ -16,13 +16,14 @@ No provider SDKs or API keys are needed. Authentication and billing are handled ## Endpoints -Three endpoints are available, each suited to different use cases: +Four endpoints are available, each suited to different use cases: | Endpoint | Format | Use case | | -------- | ------ | -------- | | `POST /ai/run` | Envelope with `model`, `provider`, `input` | All models and modalities (LLM, image, TTS, ASR) | | `POST /ai/v1/chat/completions` | OpenAI chat completions | LLMs — OpenAI SDK compatible | | `POST /ai/v1/responses` | OpenAI Responses API | Agentic workflows — OpenAI SDK compatible | +| `POST /ai/v1/messages` | Anthropic Messages API | LLMs — Anthropic SDK compatible | ## Authentication @@ -178,6 +179,43 @@ const response = await openai.responses.create({ }); ``` +## `/ai/v1/messages` — Anthropic compatible + +Uses the Anthropic Messages API format. Compatible with the Anthropic SDK. + +```bash +curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/messages" \ + --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + --header "Content-Type: application/json" \ + --data '{ + "model": "anthropic/claude-sonnet-4-5", + "max_tokens": 512, + "messages": [ + { + "role": "user", + "content": "What is Cloudflare?" + } + ] + }' +``` + +Point the Anthropic SDK `baseURL` at the Cloudflare API: + +```javascript +import Anthropic from "@anthropic-ai/sdk"; + +const anthropic = new Anthropic({ + apiKey: CLOUDFLARE_API_TOKEN, + baseURL: `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/ai/v1`, +}); + +const message = await anthropic.messages.create({ + model: "anthropic/claude-sonnet-4-5", + max_tokens: 512, + messages: [{ role: "user", content: "What is Cloudflare?" }], +}); +``` + ## Specify a gateway By default, third-party model requests route through your account's default AI Gateway. To use a specific gateway, include the `cf-aig-gateway-id` header: