Skip to content

providers: add Cloudflare AI Gateway as a catalog row - #316

Merged
FMXExpress merged 3 commits into
mainfrom
claude/cloudflare-ai-gateway
Jun 21, 2026
Merged

FMXExpress merged 3 commits into
mainfrom
claude/cloudflare-ai-gateway

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Adds Cloudflare AI Gateway as a new pfOpenAI catalog row. The gateway exposes an OpenAI Chat Completions compatible surface for both Workers AI direct and the AI Gateway proxy (which adds caching, rate limiting, analytics, and provider fallback in front of upstream OpenAI / Anthropic / Mistral / Workers AI / etc.).

One-row catalog change — no new provider unit needed. The existing TOpenAIProvider already handles every entry in the pfOpenAI family transparently once Kind / DefaultBase / Auth / ChatPath are wired up.

URL shapes operators paste into api_base

Both OpenAI-shaped, both expect Authorization: Bearer <CLOUDFLARE_API_TOKEN>:

Mode api_base Full chat URL
Workers AI direct (no gateway features) https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/v1 …/ai/v1/chat/completions
AI Gateway proxy (caching, rate limits, analytics, fallback) https://gateway.ai.cloudflare.com/v1/{ACCOUNT_ID}/{GATEWAY_ID}/compat …/{GATEWAY_ID}/compat/chat/completions

Catalog row

Field Value
Kind cloudflare
DisplayName Cloudflare AI Gateway
Family pfOpenAI
DefaultBase '' (operator supplies — URL embeds account_id, same pattern as mimo / litellm)
DefaultModel @cf/meta/llama-3.3-70b-instruct-fp8-fast (Workers AI flagship)
Auth asBearer
ChatPath /chat/completions (no /v1 — the /v1 is part of the operator's api_base prefix, same trick the Perplexity row uses)

Operators wanting a different upstream (e.g. @cf/openai/gpt-oss-120b, an OpenAI passthrough through the gateway, Mistral, etc.) override per-request via the model field.

Onboarding

PromptProvider's catalog menu reads AllProviderSpecs and sorts by DisplayName, so the new "Cloudflare AI Gateway" row appears automatically in the picker — no onboarding plumbing needed.

Test plan

  • make passes
  • make test-provider-catalog passes
  • LookupProvider('cloudflare') returns the row with the expected Family / Auth / ChatPath / DefaultBase / DefaultModel / DisplayName
  • No-/v1 ChatPath regression check (same shape as Perplexity's existing pin)
  • Case-insensitive lookup: LookupProvider('Cloudflare') works
  • Manual: real Cloudflare account + pasclaw mcp install-style workflow against a live gateway (followup; needs an operator with a Cloudflare account)

Docs referenced

Followups (not in this PR)

  • A cf-aig-gateway-id header surface so operators using the universal api.cloudflare.com/.../ai/v1 endpoint can route through a named gateway without changing api_base. Out of scope here — the existing AI Gateway URL (gateway.ai.cloudflare.com/.../compat) covers the routing case via path-based selection.
  • Separate cloudflare-anthropic / cloudflare-gemini catalog rows if operators want Anthropic-shaped or Gemini-shaped passthroughs through the gateway. Doable as additional one-row changes if there's demand.

Generated by Claude Code

Adds Cloudflare AI Gateway as a new pfOpenAI catalog entry. The
gateway exposes an OpenAI Chat Completions compatible surface for
both Workers AI direct and the AI Gateway proxy (which adds
caching, rate limiting, analytics, and provider fallback in front
of upstream OpenAI / Anthropic / Mistral / Workers AI / etc.).

The two URL shapes operators paste into api_base, both
OpenAI-shaped:

  Workers AI direct (no gateway features):
    https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/v1
    + ChatPath /chat/completions
    => POST .../ai/v1/chat/completions

  AI Gateway proxy:
    https://gateway.ai.cloudflare.com/v1/{ACCOUNT_ID}/{GATEWAY_ID}/compat
    + ChatPath /chat/completions
    => POST .../{GATEWAY_ID}/compat/chat/completions

Both expect Authorization: Bearer <CLOUDFLARE_API_TOKEN>; both
return the OpenAI-shaped response the existing TOpenAIProvider
already speaks.

Catalog row
===========

  Kind:         cloudflare
  DisplayName:  Cloudflare AI Gateway
  Family:       pfOpenAI
  DefaultBase:  '' (operator supplies -- URL embeds account_id,
                same pattern as mimo / litellm)
  DefaultModel: @cf/meta/llama-3.3-70b-instruct-fp8-fast
                (Workers AI flagship; operators wanting a
                different upstream override per-request via the
                model field)
  Auth:         asBearer
  ChatPath:     /chat/completions
                (no /v1 -- the /v1 is part of the operator's
                api_base prefix, same trick the Perplexity row
                uses for its no-/v1 URL)

No new provider unit needed -- the existing TOpenAIProvider
handles every catalog entry in the pfOpenAI family transparently
once Kind / DefaultBase / Auth / ChatPath are wired up.

Onboarding
==========

PromptProvider's catalog menu (PasClaw.Cmd.Onboard) reads
AllProviderSpecs and sorts by DisplayName, so the new "Cloudflare
AI Gateway" row appears automatically -- no onboarding plumbing
needed.

Tests
=====

src/tests/provider_catalog_tests.pas extended with assertions on
the new row:

  - LookupProvider('cloudflare') returns the row
  - Family = pfOpenAI
  - Auth.Kind = asBearer
  - DefaultBase = '' (operator-supplied)
  - DefaultModel = @cf/meta/llama-3.3-70b-instruct-fp8-fast
  - ChatPath = /chat/completions (no /v1 regression check)
  - DisplayName = 'Cloudflare AI Gateway'
  - LookupProvider is case-insensitive ('Cloudflare' works)

make passes. make test-provider-catalog passes.

Docs referenced
===============

  - https://developers.cloudflare.com/ai-gateway/
  - https://developers.cloudflare.com/workers-ai/configuration/open-ai-compatibility/

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bba08acfe7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

https://developers.cloudflare.com/workers-ai/. *)
Result[22] := MkSpec('cloudflare', 'Cloudflare AI Gateway',
pfOpenAI, '',
'@cf/meta/llama-3.3-70b-instruct-fp8-fast',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the compat model prefix for the gateway default

When api_base is the advertised https://gateway.ai.cloudflare.com/.../compat proxy, this catalog default is sent unchanged as the model, but Cloudflare's compat endpoint requires {provider}/{model} names for gateway routing (for Workers AI, e.g. workers-ai/@cf/...). The bare @cf/... default only matches the direct Workers AI api.cloudflare.com/.../ai/v1 base, so users who configure the AI Gateway proxy URL get failing default requests unless they know to override the model.

Useful? React with 👍 / 👎.

claude added 2 commits June 21, 2026 01:53
Follow-up to the cloudflare row in the previous commit. Adds two
more catalog entries so operators can use Cloudflare AI Gateway as
a caching / rate-limiting / analytics proxy in front of Anthropic
and Gemini upstreams, not just OpenAI-shaped ones.

Both work as catalog-only additions because the existing pfAnthropic
and pfGemini provider units already build URLs by appending fixed
paths to FAPIBase:

  Anthropic: <api_base>/v1/messages
  Gemini:    <api_base>/v1beta/models/<model>:generateContent

So pointing api_base at the Cloudflare gateway prefix + upstream
slug gives the right full URL for free -- no provider changes.

Rows
====

  cloudflare-anthropic  Cloudflare AI Gateway (Anthropic)
    Family       pfAnthropic
    DefaultBase  '' (operator pastes https://gateway.ai.cloudflare.com/v1/<acct>/<gw>/anthropic)
    DefaultModel claude-opus-4-7
    Auth         asHeader 'x-api-key' (forwards operator's Anthropic key)
    Full URL     .../anthropic/v1/messages

  cloudflare-gemini     Cloudflare AI Gateway (Gemini)
    Family       pfGemini
    DefaultBase  '' (operator pastes https://gateway.ai.cloudflare.com/v1/<acct>/<gw>/google-ai-studio)
    DefaultModel gemini-3.5-flash
    Auth         asHeader 'x-goog-api-key' (forwards operator's Gemini key)
    Full URL     .../google-ai-studio/v1beta/models/<model>:generateContent

The hyphenated kind names (cloudflare-anthropic / cloudflare-gemini)
break the existing no-separator catalog convention but are
substantially more readable than the alternatives ("cfanthropic",
"cloudflareanthropic"). LookupProvider's case-insensitive exact
match handles either fine.

Authenticated Gateways
======================

Operators who turned on "Authenticated Gateway" on their CF gateway
also need a cf-aig-authorization header on every request. Not
supported in V1 -- the existing TAuthScheme covers single-header
auth only. Documented as a follow-up; for now the rows assume
unauthenticated gateways (the default).

Tests
=====

src/tests/provider_catalog_tests.pas extended with assertions on
both new rows: LookupProvider, Family, Auth.Kind, Auth.HeaderName,
DefaultBase, DefaultModel, DisplayName. make clean && make passes;
make test-provider-catalog passes.

Comment-syntax gotcha
=====================

The Pascal { ... } comment delimiter terminates on the closing
brace, so a URL placeholder like {ACCOUNT_ID} inside a { } comment
ends the comment early and the rest reads as code. The catalog
uses the (* *) style around its URL examples (which doesn't have
the issue); the test file uses { } comments and refers to the
placeholders by name in prose instead.
…/<model> routing (PR #316 review fix)

Codex P2 reviewer flagged that the `cloudflare` catalog row's
DefaultModel of `@cf/meta/llama-3.3-70b-instruct-fp8-fast` only
works for the Workers AI direct path
(api.cloudflare.com/.../ai/v1). The catalog row is named
"Cloudflare AI Gateway", and operators who paste the actual AI
Gateway compat URL into api_base
(gateway.ai.cloudflare.com/v1/<acct>/<gw>/compat) get default
requests that 4xx because the compat endpoint requires
<provider>/<model> routing notation -- the gateway has to pick
which upstream to forward to.

Verified against
https://developers.cloudflare.com/ai-gateway/usage/chat-completion/:

  Workers AI:    "model": "workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast"
  OpenAI:        "model": "openai/gpt-5.2"
  Anthropic:     "model": "anthropic/claude-4-5-sonnet"
  Gemini:        "model": "google-ai-studio/gemini-2.5-flash"

The docs explicitly say "Specify the model using {provider}/{model}
format" for the compat endpoint.

Fix
===

  - DefaultModel flipped from `@cf/meta/llama-3.3-70b-instruct-fp8-fast`
    to `workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast`.

  - Notes string rewritten -- previously hedged between "Workers
    AI direct or AI Gateway proxy"; now leads with the AI Gateway
    proxy path (which the row is actually named after), spells out
    the <provider>/<model> routing format, and lists the four
    common upstream prefixes.

  - Catalog comment block reordered to put the AI Gateway compat
    URL first (it's the headline use case), demoted Workers AI
    direct to the "bypass the gateway" alternative, and explained
    the DefaultModel rationale with a pointer back to the reviewer
    comment.

  - Test pin updated to assert the new model id and the rationale.

Operator impact
===============

Operators who were using the cloudflare row for Workers AI direct
(the api.cloudflare.com universal endpoint) now need to override
the model to bare `@cf/...` in their config or per-request.
Documented in the row's Notes; expected to be a small minority of
users since the row is explicitly the "AI Gateway" entry. Workers
AI direct users with no gateway features can also use the
existing per-provider rows (openai, anthropic, gemini) with a
Cloudflare-tunneled api_base if they need the Workers AI side
specifically.

Tests
=====

make clean && make passes. make test-provider-catalog passes the
updated pin.

Comment-syntax gotcha
=====================

Hit the same Pascal { } comment issue as the previous commit on
this PR -- a literal <provider>/<model> in the test file's
explanation broke the build because { ... } is a Pascal comment
delimiter. Switched that block to (* ... *) which doesn't
terminate on a closing brace. (The catalog file's URL examples
already use (* *) so they were fine.)
@FMXExpress
FMXExpress merged commit 638bc86 into main Jun 21, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
The README + docs/changelog.md last entry was 2026-06-13 (FMXExpress#244). Five
substantial PRs (FMXExpress#314 FMXExpress#315 FMXExpress#316 FMXExpress#317 FMXExpress#318) and ten more feature PRs
between them and that entry shipped without changelog entries. This
brings both files current through today.

Twenty new entries (newest first, matching the existing style):

  2026-06-21
    FMXExpress#318  Relay pull-worker provider (queue + provider + /v1/relay/* HTTP)

  2026-06-20
    FMXExpress#317  pasclaw plan + build PLAN.md pickup + build --goal + cog mode
    FMXExpress#316  Cloudflare AI Gateway provider catalog rows
    FMXExpress#315  MCP progressive disclosure + tool_search
    FMXExpress#314  Stock defaults adopt lean-edit shape; fs_grep split-gate

  2026-06-18
    FMXExpress#312  Web UI workspace.zip export + import
    FMXExpress#310  Model-callable cron tool
    FMXExpress#309  FTS5 snippet window widened 24 -> 60
    FMXExpress#307  Windows cmd.exe quoting fix

  2026-06-17
    FMXExpress#306  cog-build honours profile=security sandbox
    FMXExpress#304  cog-build default profile = max-build
    FMXExpress#303  cog-build list[Path] outputs + Secret inputs + -q

  2026-06-16
    FMXExpress#302  cog-build optional workspace_in
    FMXExpress#300  pasclaw build cmd + cog-build/ predictor (parent feature)
    FMXExpress#299  Checkpoints zpaq backend + /redo
    FMXExpress#298  AGENTS.md + pasclaw init + /init
    FMXExpress#297  tool_choice force-a-specific-tool form
    FMXExpress#296  Delphi ExtraEnv injection fix
    FMXExpress#295  KB native PDF ingest

  2026-06-15
    FMXExpress#292  pasclaw profile diff + bench

Skipped per the changelog's stated convention ("Bug fixes and review
follow-ups are in the full git log"):

  FMXExpress#293  cmd/profile dcc64 fix
  FMXExpress#294  skills_manage gemini empty-enum fix
  FMXExpress#301  cmd.build dcc64 fix
  FMXExpress#311  cron dcc64 fix

Files updated identically (the docs/changelog.md note at the top says
"This file mirrors the changelog section at the top of the root
README.md"):

  M README.md           20 entries + 20 link refs added
  M docs/changelog.md   same

The link-ref block at the bottom of each file gained 20 [#NNN] entries
keeping the existing one-per-line / sorted-numerically format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants