# Cloudflare Workers AI

[Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/) provides serverless inference for models hosted on Cloudflare's network. AISIX gives applications an OpenAI-compatible API for those models while keeping the Cloudflare token, caller access, rate limits, and usage accounting at the gateway.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Before starting, prepare the following:

* One AISIX setup:

  <!-- -->

  * For AISIX Enterprise or AISIX Cloud, an environment with an attached gateway and a write-scoped admin token. For AISIX Enterprise, follow the [AISIX Enterprise getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/aisix-cloud-quickstart.md). To request AISIX Cloud access, [contact API7](https://api7.ai/contact).
  * For the open-source AISIX gateway, prepare either a local AISIX installation or the Docker setup from the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Configure the gateway to load a declarative resources file.

* A Cloudflare account ID and a Workers AI API token. In the Cloudflare dashboard, open the Workers AI page and select **Use REST API** to create the token and copy the account ID, as described in [Get started with the REST API](https://developers.cloudflare.com/workers-ai/get-started/rest-api/).

* `curl` and `jq`.

## Configure with AISIX Enterprise or AISIX Cloud[​](#configure-with-aisix-enterprise-or-aisix-cloud "Direct link to Configure with AISIX Enterprise or AISIX Cloud")

Export the control-plane connection details:

```
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash

# The local AISIX Enterprise quickstart uses http://localhost:8080/api

export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"

export AISIX_TOKEN="YOUR_ADMIN_TOKEN"

export ENV_ID="YOUR_ENVIRONMENT_ID"
```

Create a provider key, model alias, and caller API key for Workers AI-backed Chat Completions and native Responses.

Cloudflare Workers AI is a community catalog provider. AISIX accepts `cloudflare-workers-ai` as the provider value and selects the `openai` adapter with bearer authentication. AISIX does not supply a curated base URL or provider-specific request and response rewrites, so you must configure the account-scoped `api_base`.

The dashboard labels this provider as a community entry whose wire format is unverified.

### Create a Provider Key[​](#create-a-provider-key "Direct link to Create a Provider Key")

Create the provider key that stores the Cloudflare credential and the account-scoped API root:

```
# Replace with your values

export CLOUDFLARE_API_TOKEN="YOUR_PROVIDER_API_KEY"

export CLOUDFLARE_ACCOUNT_ID="YOUR_CLOUDFLARE_ACCOUNT_ID"



PROVIDER_KEY_ID=$(curl -sS -X POST "$AISIX_CP/provider_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "cloudflare-workers-ai-prod",

    "provider": "cloudflare-workers-ai",

    "api_key": "'"${CLOUDFLARE_API_TOKEN}"'",

    "api_base": "https://api.cloudflare.com/client/v4/accounts/'"${CLOUDFLARE_ACCOUNT_ID}"'/ai/v1",

    "apis": {

      "responses": {}

    },

    "allowed_environments": ["'"${ENV_ID}"'"]

  }' | jq -r '.provider_key.id')



echo "$PROVIDER_KEY_ID"
```

❶ `provider` is `cloudflare-workers-ai`, the catalog ID. The AISIX Cloud Admin API derives the adapter from the catalog provider; the `adapter` field is only accepted on BYO provider keys, so do not set it here.

❷ `api_key` stores the Workers AI API token. Cloudflare authenticates the REST API with an `Authorization: Bearer` header, which is what the `openai` adapter already sends. The value follows the credential-handling behavior in [Provider Keys](https://docs.api7.ai/ai-gateway/models/provider-keys.md#credential-handling).

❸ `api_base` is the account-scoped root `https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/ai/v1`. Cloudflare documents the full OpenAI-compatible endpoint as `https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions` in [OpenAI compatible API endpoints](https://developers.cloudflare.com/workers-ai/configuration/open-ai-compatibility/). AISIX appends the endpoint path such as `/chat/completions` to `api_base`, so the value must stop at `/ai/v1`. If you paste the full endpoint URL by mistake, AISIX strips the recognized suffix and the trailing slash, but the shorter root is the value to store.

❹ `apis.responses` declares that Workers AI serves the Responses API at the same account-scoped root. AISIX then uses Cloudflare's native format instead of translating the request through Chat Completions.

caution

Always set `api_base` on a Cloudflare Workers AI provider key.

For a community catalog provider, AISIX falls back to the base URL published in the public model catalog when you omit `api_base`. For Cloudflare Workers AI, that published value is `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1` — a template, not a resolved URL, because every Cloudflare account has its own endpoint. AISIX does not fill in a template. A create request without `api_base` is refused with `400` and the message `models.dev does not publish a default api_base for this provider — set api_base explicitly`. Clearing `api_base` on an existing key is refused the same way. A key that 1.7.0 or earlier created without `api_base` stored the template as its root, so every request through it fails at the upstream. Edit such a key and set the real account-scoped root.

The command captures the returned provider key ID in `PROVIDER_KEY_ID`.

### Create a Model[​](#create-a-model "Direct link to Create a Model")

Workers AI model IDs always begin with `@cf/`, followed by the publisher and the model name: `@cf/<publisher>/<model>`. Carry the entire string into `model_name`, including the `@cf/` prefix and any precision or variant suffix such as `-fp8-fast`. Dropping the prefix, or reusing a bare ID that another host publishes for the same weights, produces an upstream model error.

The following IDs are current in the Cloudflare model catalog:

| Cloudflare model ID                                                                                                                | Notes                                                                                            |
| ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [`@cf/openai/gpt-oss-120b`](https://developers.cloudflare.com/workers-ai/models/gpt-oss-120b/)                                     | Responses and Chat Completions example used in this guide.                                       |
| [`@cf/meta/llama-3.3-70b-instruct-fp8-fast`](https://developers.cloudflare.com/workers-ai/models/llama-3.3-70b-instruct-fp8-fast/) | Chat Completions model; Cloudflare does not currently document Responses support for this model. |
| [`@cf/qwen/qwen3-30b-a3b-fp8`](https://developers.cloudflare.com/workers-ai/models/qwen3-30b-a3b-fp8/)                             | Chat Completions model; Cloudflare does not currently document Responses support for this model. |

Check the [Workers AI model catalog](https://developers.cloudflare.com/workers-ai/models/) for the current list before you create an alias. Cloudflare currently documents GPT-OSS for both Responses and Chat Completions; treat other text-generation models as Chat Completions options unless their documentation explicitly adds Responses support.

Create the model alias callers will send in requests:

```
MODEL_ID=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/models" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "cloudflare-gptoss-prod",

    "model_name": "@cf/openai/gpt-oss-120b",

    "provider_key_id": "'"${PROVIDER_KEY_ID}"'"

  }' | jq -r '.model.id')



echo "$MODEL_ID"
```

❶ `display_name` is the alias callers send in `model`.

❷ `model_name` is the full Workers AI model ID, for example `@cf/openai/gpt-oss-120b`.

❸ `provider_key_id` attaches the alias to the Cloudflare Workers AI provider key.

To attach cost metadata for budget accounting and usage reports, see [Model Aliases](https://docs.api7.ai/ai-gateway/models/model-aliases.md#cost-metadata).

### Create a Caller API Key[​](#create-a-caller-api-key "Direct link to Create a Caller API Key")

Create the caller API key that can access the model alias. The plaintext key is server-generated and returned once in the create response, so capture it now:

```
AISIX_API_KEY=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "cloudflare-caller",

    "allowed_models": ["'"${MODEL_ID}"'"]

  }' | jq -r '.plaintext')



echo "$AISIX_API_KEY"
```

The `allowed_models` value must reference the model ID captured in the previous step. After the write, the configuration projects to attached gateways automatically.

## Configure with AISIX OSS[​](#configure-with-aisix-oss "Direct link to Configure with AISIX OSS")

Export the upstream credential and choose the caller API key that applications will send to the gateway:

```
export CLOUDFLARE_API_TOKEN="YOUR_PROVIDER_API_KEY"

export CLOUDFLARE_ACCOUNT_ID="YOUR_CLOUDFLARE_ACCOUNT_ID"

export CALLER_API_KEY="YOUR_CALLER_API_KEY"

export CALLER_API_KEY_SHA256="$(printf '%s' "$CALLER_API_KEY" | sha256sum | cut -d ' ' -f 1)"
```

For a new gateway, use this complete resources file. For an existing gateway, merge the entries into its [current file](https://docs.api7.ai/ai-gateway/reference/resources-file.md#apply-resource-examples-safely), preserving its other resources:

resources.yaml

```
_format_version: "2"



provider_keys:

  - id: 3cc9ed79-d221-48d6-ab18-6f142027d8f6

    display_name: "cloudflare-workers-ai-prod"

    provider: "cloudflare-workers-ai"

    adapter: "openai"

    api_key: ${CLOUDFLARE_API_TOKEN}

    api_base: "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1"

    apis:

      responses: {}



models:

  - id: 7caa729b-3b38-4a6d-b139-b24e6473b820

    display_name: "cloudflare-gptoss-prod"

    provider: "cloudflare-workers-ai"

    model_name: "@cf/openai/gpt-oss-120b"

    provider_key_id: 3cc9ed79-d221-48d6-ab18-6f142027d8f6



api_keys:

  - id: 23479b6b-311f-459f-acab-631c4d6d0cad

    display_name: "cloudflare-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "cloudflare-gptoss-prod"
```

If AISIX is installed locally, validate the file before loading it:

```
aisix validate --resources resources.yaml
```

After validation, start the gateway with the referenced environment variables in its process environment. Reload an existing gateway only if those variables are already available to the process; otherwise, restart it with the updated environment.

If you use Docker, adapt the validation and startup commands in the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Mount this `resources.yaml` file and pass every environment variable it references with `-e` in both commands. After the resources load, prepare the shared verification request below:

```
export AISIX_API_KEY="$CALLER_API_KEY"
```

## Verify the Provider Connection[​](#verify-the-provider-connection "Direct link to Verify the Provider Connection")

Export the AISIX gateway origin:

```
# AISIX_PROXY has no trailing slash or endpoint path

# The local quickstarts use http://127.0.0.1:3000

export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
```

Send a Responses request through the AISIX proxy:

```
curl -sS -X POST "$AISIX_PROXY/v1/responses" \

  -H "Authorization: Bearer ${AISIX_API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "model": "cloudflare-gptoss-prod",

    "input": "Say hello from Cloudflare Workers AI."

  }'
```

AISIX sends the request to Cloudflare's native Responses endpoint, replaces the alias with the Workers AI model ID upstream, and restores the alias in the response.

If the request fails, work through the three causes in order:

1. An upstream authentication failure points at the `api_key` value or at a token that lacks Workers AI permissions.
2. An upstream route or account error points at `api_base`. Confirm that the account ID segment is a real account ID and that the value ends at `/ai/v1`.
3. An upstream model error points at `model_name`. Confirm that the ID still carries the `@cf/` prefix.

## Supply What the Community Catalog Does Not[​](#supply-what-the-community-catalog-does-not "Direct link to Supply What the Community Catalog Does Not")

Providers with an AISIX-curated adapter mapping ship request and response adjustments alongside the adapter. A caller-facing parameter that the upstream spells differently is renamed before it leaves the gateway. Cloudflare Workers AI has no such mapping, so **no parameter rename and no reasoning-field mapping are registered for it**. AISIX sends the caller's chat-completions body to the `/ai/v1` root with the field names the caller used, and reads the reply as standard OpenAI chat-completions JSON.

That default is correct as long as the Cloudflare surface matches the OpenAI shape. When it does not, configure the difference explicitly on the provider key rather than reshaping every client:

```
{

  "request": {

    "param_renames": {

      "max_completion_tokens": "max_tokens"

    }

  },

  "response": {

    "reasoning_field": "delta.reasoning"

  }

}
```

* `request.param_renames` renames a top-level parameter on the way out. Use it when a Workers AI model rejects the name your clients already send. If a request carries both names, AISIX uses the value from the original caller-facing name.
* `response.reasoning_field` maps reasoning from a nonstandard streaming `delta` path onto the canonical `delta.reasoning_content` field. Use it when a model streams its reasoning somewhere other than `reasoning_content`.

An override applies to every model that references the provider key, so validate it against a non-production alias first. See [Provider-Specific Overrides](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides) for the full field catalog.

AISIX does not strip top-level parameters it does not model natively. A parameter that Cloudflare supports and AISIX has no typed field for still reaches the upstream unchanged. A rename is therefore needed only when the parameter name differs, not when the parameter is simply unfamiliar to the gateway.

## Control Reasoning Effort[​](#control-reasoning-effort "Direct link to Control Reasoning Effort")

The `@cf/openai/gpt-oss-120b` model exposes a reasoning-effort control that accepts `low`, `medium`, and `high`. Because unrecognized top-level parameters pass through, send it at the top level of the chat-completions body:

```
{

  "model": "cloudflare-gptoss-prod",

  "messages": [

    {

      "role": "user",

      "content": "Plan a three-step migration."

    }

  ],

  "reasoning_effort": "low"

}
```

Reasoning support is per model on Workers AI, and several models expose no reasoning control at all. Confirm the parameter on the [model page](https://developers.cloudflare.com/workers-ai/models/) for the specific model before you send it, because a model that does not accept the parameter can reject the request.

## Endpoint Coverage[​](#endpoint-coverage "Direct link to Endpoint Coverage")

Cloudflare Workers AI serves text generation and text embeddings over its OpenAI-compatible root, so only part of the AISIX proxy surface applies to a Workers AI-backed alias.

| Route                                  | Behavior with a Cloudflare Workers AI alias                                                                                                                                                                                                                                                                                                                                                                     |
| -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/v1/chat/completions`                 | Supported, including `stream: true`.                                                                                                                                                                                                                                                                                                                                                                            |
| `/v1/embeddings`                       | Supported. Cloudflare implements OpenAI-compatible embeddings under the same `/ai/v1` root, so create a second alias on the same provider key whose `model_name` is an embedding model such as `@cf/baai/bge-m3`. See [Embeddings](https://docs.api7.ai/ai-gateway/endpoints/embeddings.md).                                                                                                                    |
| `/v1/responses`                        | Sent to Cloudflare's native Responses API because this guide declares `apis.responses`. Without the declaration, AISIX uses the [Responses bridge](https://docs.api7.ai/ai-gateway/endpoints/responses-api.md).                                                                                                                                                                                                 |
| `/v1/messages`                         | Supported for Anthropic-shaped callers through translation. Token counting at `/v1/messages/count_tokens` requires an Anthropic-backed model.                                                                                                                                                                                                                                                                   |
| `/v1/images/generations`               | Rejected. The route accepts only models whose provider is `openai` or whose provider key uses the `azure-openai` adapter (see [Provider Requirement](https://docs.api7.ai/ai-gateway/endpoints/image-generation.md#provider-requirement)).                                                                                                                                                                      |
| `/v1/rerank`                           | Rejected. The route accepts only the `openai`, `cohere`, and `jina` provider values.                                                                                                                                                                                                                                                                                                                            |
| `/v1/videos`                           | Returns a not-implemented error. The route dispatches on a fixed provider set that does not include `cloudflare-workers-ai`.                                                                                                                                                                                                                                                                                    |
| `/passthrough/cloudflare-workers-ai/*` | Available through a configured [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) claiming this prefix with the account-scoped `/ai/v1` root as its `target_url`; grant the route on the caller key's `allowed_routes`. Such a route reaches paths under `/ai/v1`, so Cloudflare's native `/ai/run/@cf/...` endpoint sits outside the root and is not reachable through it. |

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have now connected AISIX to Cloudflare Workers AI and verified the model alias. Continue with these guides:

* [Model Aliases](https://docs.api7.ai/ai-gateway/models/model-aliases.md): configure routing, retry behavior, or cost metadata for this alias.
* [Routing and Failover](https://docs.api7.ai/ai-gateway/routing/routing-and-failover.md): fail over between Cloudflare Workers AI and a second provider.
* [Provider-Specific Overrides](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides): adapt request and response shapes when an upstream API differs from its adapter.
* [Provider Compatibility](https://docs.api7.ai/ai-gateway/providers/compatibility.md): review supported proxy endpoints and provider-specific boundaries.
