Skip to content

feat(agents): zdr and vendorKey options for createAI - #2571

Merged
mattzcarey merged 2 commits into
mainfrom
feat/createai-byok-zdr
Oct 12, 2026
Merged

mattzcarey merged 2 commits into
mainfrom
feat/createai-byok-zdr

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Adds a gateway option and a model option to createAI, for vendor models routed through AI Gateway:

  • zdr turns Zero Data Retention on or off for one request on unified billing, whatever the gateway's own setting.
  • vendorKey: "request" (AI SDK only, per model) forwards the key the vendor's provider put on the request, instead of stripping it.
const ai = createAI({ binding: env.AI, zdr: true });

const anthropic = createAnthropic({ apiKey: env.ANTHROPIC_API_KEY });
ai(anthropic("claude-opus-4-8"), { vendorKey: "request" });

ai-gateway-provider and workers-ai-provider/gateway have both of these and createAI didn't (#2569, cloudflare/ai#675).

  • zdr is an ordinary gateway option: flat or nested, on any layer, inherited by fallback legs. The gateway reads cf-aig-zdr off the universal request itself (Universal.prepare), not off a provider entry, so the core transport sends it in the binding's extraHeaders. pi-ai gets it too. The Workers AI run path doesn't send it.
  • vendorKey belongs to the model it was set on. A fallback leg doesn't inherit it, so a chain can mix a model on your own key with one on unified billing. A re-wrapped model keeps it. With a key on the entry, the gateway uses it and turns unified billing off for that request.

pnpm run check and the model tests (src/tests/models) pass.

@changeset-bot

changeset-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 324f536

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment thread docs/agents/models.md Outdated
Comment on lines +218 to +235
When the gateway stores several keys for one provider, `byokAlias` picks one
by alias. `zdr: true` sends a unified-billing request only to upstreams with
Zero Data Retention, and `zdr: false` turns it off for a gateway that has it
on. Both travel as `cf-aig-byok-alias` / `cf-aig-zdr` on the universal request
and do nothing for a Workers AI model.

To use a key you hold yourself rather than one stored on the gateway, give it
to the vendor's provider and set `vendorKey: "request"`, which forwards the
credential header instead of stripping it:

```ts
const anthropic = createAnthropic({ apiKey: env.ANTHROPIC_API_KEY });
const model = ai(anthropic("claude-opus-4-8"), { vendorKey: "request" });
```

`vendorKey` belongs to the model it is set on (`ai(model, …)` or
`ai.routed(model, …)`). A fallback leg does not inherit it, so a chain can mix
a model on your key with one on unified billing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Check upstream documentation sync

Both model reference pages changed. The docs rules require matching updates in cloudflare-docs, which this repository cannot verify.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +184 to +187
const dropped = new Set([
...(vendorKey === "request" ? [] : route.authHeaders),
"content-length"
]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟥 Vendor keys exposed to gateway logs

With vendorKey: "request", forwardedHeaders passes the vendor credential in the universal request. Gateway request logging can retain that credential, exposing it to log readers.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@agent-think

agent-think Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🟡 agents import sizes: 6 entry points grew

Entry point Exports Largest gzip change Size now
🟡 agents/mcp 15 resized up to +3.8 KiB (+0.98%) 396.8 KiB
🟡 agents/mcp/server 1 resized +2.3 KiB (+2.8%) 82.8 KiB
🟡 agents/chat-sdk 5 resized up to +1.3 KiB (+0.49%) 267 KiB
🟡 agents 30 resized up to +1.3 KiB (+0.49%) 264.5 KiB
🟡 agents/workflows 2 resized up to +1.3 KiB (+0.49%) 265.8 KiB
🟡 agents/mcp/client 1 resized +1.3 KiB (+0.81%) 160.1 KiB
Changed exports (54)
Import Gzip change Size now
🟡 agents/mcp#createMcpHandler +3.8 KiB (+0.98%) 396.8 KiB
🟡 agents/mcp#experimental_createMcpHandler +2.3 KiB (+0.61%) 383.1 KiB
🟡 agents/mcp#createLegacyMcpHandler +2.3 KiB (+0.6%) 383 KiB
🟡 agents/mcp/server#createMcpHandler +2.3 KiB (+2.8%) 82.8 KiB
🟡 agents/mcp#WorkerTransport +2.2 KiB (+0.63%) 352.9 KiB
🟡 agents/mcp#SSEEdgeClientTransport +1.9 KiB (+0.54%) 349.2 KiB
🟡 agents/mcp#StreamableHTTPEdgeClientTransport +1.9 KiB (+0.53%) 349.2 KiB
🟡 agents/mcp#getMcpAuthContext +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#MCP_SERVER_ID_MAX_LENGTH +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#RPCClientTransport +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#normalizeServerId +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#RPCServerTransport +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#DurableObjectEventStore +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#McpAgent +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#ElicitRequestSchema +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/mcp#RPC_DO_PREFIX +1.8 KiB (+0.53%) 349.1 KiB
🟡 agents/chat-sdk#ChatSdkStateAdapter +1.3 KiB (+0.49%) 267 KiB
🟡 agents/chat-sdk#createChatSdkState +1.3 KiB (+0.49%) 267.1 KiB
🟡 agents#getCurrentAgent +1.3 KiB (+0.49%) 264.5 KiB
🟡 agents#__DO_NOT_USE_WILL_BREAK__withInvocationScope +1.3 KiB (+0.49%) 264.5 KiB
🟡 agents#isDurableObjectStorageReset +1.3 KiB (+0.49%) 264.5 KiB
🟡 agents/workflows#AgentWorkflow +1.3 KiB (+0.49%) 265.8 KiB
🟡 agents/chat-sdk#ChatSdkStateAgent +1.3 KiB (+0.49%) 266.3 KiB
🟡 agents/mcp/client#MCPClientManager +1.3 KiB (+0.81%) 160.1 KiB
🟡 agents#unstable_callable +1.3 KiB (+0.49%) 264.6 KiB
🟡 agents#routeAgentRequest +1.3 KiB (+0.48%) 265.2 KiB
🟡 agents#normalizeServerId +1.3 KiB (+0.48%) 264.5 KiB
🟡 agents#isPlatformTransientError +1.3 KiB (+0.48%) 264.5 KiB
🟡 agents#buildAgentUrl +1.3 KiB (+0.48%) 265.2 KiB
🟡 agents#buildAgentPath +1.3 KiB (+0.48%) 265 KiB
🟡 agents#getAgentByName +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#camelCaseToKebabCase +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#__DO_NOT_USE_WILL_BREAK__agentContext +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#DEFAULT_AGENT_STATIC_OPTIONS +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#isDurableObjectCodeUpdateReset +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#MCP_SERVER_ID_MAX_LENGTH +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#SqlError +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#routeAgentEmail +1.3 KiB (+0.48%) 264.7 KiB
🟡 agents#parseSubAgentPath +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#isDurableObjectMemoryLimitReset +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents/chat-sdk#defaultThreadShard +1.3 KiB (+0.48%) 264.5 KiB
🟡 agents/chat-sdk#defaultKeyShard +1.3 KiB (+0.48%) 264.6 KiB
🟡 agents#DurableObjectOAuthClientProvider +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#AGENT_TOOL_MILESTONE_PART +1.3 KiB (+0.48%) 264.4 KiB
🟡 agents#Agent +1.3 KiB (+0.47%) 264.4 KiB
🟡 agents#StreamingResponse +1.2 KiB (+0.47%) 264.4 KiB
🟡 agents#SUB_PREFIX +1.2 KiB (+0.47%) 264.4 KiB
🟡 agents#createHeaderBasedEmailResolver +1.2 KiB (+0.47%) 264.6 KiB
🟡 agents#MessageType +1.2 KiB (+0.47%) 264.6 KiB
🟡 agents#AGENT_TOOL_PROGRESS_PART +1.2 KiB (+0.47%) 264.4 KiB

…and 4 more exports in the workflow artifact.

How this works

Each runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement.

Compared 7945da9c → 324f5365 · workflow run · reported by agent-think[bot]

@pkg-pr-new

pkg-pr-new Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2571

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2571

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2571

hono-agents

npm i https://pkg.pr.new/hono-agents@2571

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2571

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2571

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2571

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2571

commit: 324f536

@mattzcarey mattzcarey changed the title feat(agents): byokAlias, zdr and vendorKey options for createAI feat(agents): zdr and vendorKey options for createAI Oct 12, 2026
@mattzcarey
mattzcarey merged commit 1bd2bc5 into main Oct 12, 2026
16 checks passed
@mattzcarey
mattzcarey deleted the feat/createai-byok-zdr branch October 12, 2026 15:50
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
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.

1 participant