Problem/Motivation

The Cloudflare AI Gateway provider only wired the cache_ttl of the cf-aig-* controls the gateway request value object already models. It surfaced no per-model cost, did not make Cloudflare Dynamic Routing discoverable, had no explicit test guarding the enabled-but-unconfigured state, and streamed chat fataled for Workers AI models.

Proposed resolution

  • Wire cf-aig-skip-cache and cf-aig-metadata into requests. Metadata combines an operator-configured key/value map with the AI operation type and any per-request tags, so requests are filterable in the Cloudflare dashboard. Adds matching settings-form fields and config schema. The OpenAI client is rebuilt per request so per-request metadata reflects the current call rather than pinning the first call's tags for the instance's life.
  • Add a ModelLabel helper that appends each model's owner and per-million-token cost to the autocomplete and configured-model lists, de-duplicating the label logic shared by the controller and the provider. The /compat/models catalogue prices per token for most models but per million for some legacy Workers AI entries, so the label normalizes both to a per-million figure.
  • Document dynamic/<route> models (Cloudflare Dynamic Routing) in the chat models help text, with a characterization test that they reach the compat endpoint unmangled.
  • Fix streamed chat for Workers AI models, whose compat streaming serializes a numeric token as a JSON number ({"delta":{"content":1}}) and trips openai-php's strict ?string content: a response-body stream decorator rewrites each SSE data: line's numeric content to a string in real time, without buffering the stream.
  • Add a regression test that the provider degrades without throwing when no gateway is configured, guarding the enabled-but-unconfigured settings-page fatal (core ai #3572645 class).

Remaining tasks

Review and merge.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

zach.bimson created an issue. See original summary.

zach.bimson’s picture

Issue summary: View changes

  • zach.bimson committed 514fee58 on 1.0.x
    Issue #3609981: Provider polish — skip-cache/metadata controls, model...
zach.bimson’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.