Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/witty-seas-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"workers-ai-provider": major
---

Support the AI SDK v7. Peer dependencies now require `ai@^7`, `@ai-sdk/provider@^4`, and (for the AI Gateway sub-path plugins) `@ai-sdk/openai@^4`, `@ai-sdk/anthropic@^4`, and `@ai-sdk/google@^4`. AI SDK v6 is no longer supported.

The Workers AI models (chat, embeddings, image, transcription, speech, reranking) continue to implement the `*ModelV3` specs, which AI SDK v7 still accepts unchanged, so their behavior is identical. The AI Gateway delegate — which wraps the third-party `@ai-sdk/*` providers routed through Gateway — is migrated from the `LanguageModelV3` spec to `LanguageModelV4` to match those providers on v7. No runtime behavior changes; the delegate remains a pass-through over the underlying provider models.
20 changes: 10 additions & 10 deletions packages/workers-ai-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@ai-sdk/anthropic": "^3.0.84",
"@ai-sdk/google": "^3.0.0",
"@ai-sdk/openai": "^3.0.71",
"@ai-sdk/provider": "^3.0.10",
"@ai-sdk/anthropic": "^4.0.0",
"@ai-sdk/google": "^4.0.0",
"@ai-sdk/openai": "^4.0.0",
"@ai-sdk/provider": "^4.0.0",
"@cloudflare/gateway-core": "workspace:*",
"@cloudflare/workers-types": "^4.20260628.1",
"ai": "^6.0.204",
"ai": "^7.0.0",
"zod": "^4.4.3"
},
"peerDependencies": {
"@ai-sdk/anthropic": "^3.0.0",
"@ai-sdk/google": "^3.0.0",
"@ai-sdk/openai": "^3.0.0",
"@ai-sdk/provider": "^3.0.0",
"ai": "^6.0.0"
"@ai-sdk/anthropic": "^4.0.0",
"@ai-sdk/google": "^4.0.0",
"@ai-sdk/openai": "^4.0.0",
"@ai-sdk/provider": "^4.0.0",
"ai": "^7.0.0"
},
"peerDependenciesMeta": {
"@ai-sdk/anthropic": {
Expand Down
22 changes: 11 additions & 11 deletions packages/workers-ai-provider/src/client-fallback.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
LanguageModelV3,
LanguageModelV3CallOptions,
LanguageModelV3GenerateResult,
LanguageModelV3StreamResult,
LanguageModelV4,
LanguageModelV4CallOptions,
LanguageModelV4GenerateResult,
LanguageModelV4StreamResult,
} from "@ai-sdk/provider";
import { type FallbackAttempt, WorkersAIFallbackError, WorkersAIGatewayError } from "./errors";
import type { Transport } from "./gateway-delegate";
Expand All @@ -12,7 +12,7 @@ export interface FallbackLeg {
/** The model slug this leg dispatches. */
slug: string;
/** The built AI SDK model. */
model: LanguageModelV3;
model: LanguageModelV4;
/** Transport the leg uses. */
transport: Transport;
}
Expand All @@ -26,13 +26,13 @@ export interface FallbackLeg {
* produced a stream). Errors that surface *mid-stream* — after content has
* already been emitted — are not recoverable here and propagate as-is.
*/
export function createClientFallbackModel(legs: FallbackLeg[]): LanguageModelV3 {
export function createClientFallbackModel(legs: FallbackLeg[]): LanguageModelV4 {
if (legs.length === 0) {
throw new Error("createClientFallbackModel requires at least one model leg.");
}
const primary = legs[0].model;

async function attempt<T>(run: (model: LanguageModelV3) => PromiseLike<T>): Promise<T> {
async function attempt<T>(run: (model: LanguageModelV4) => PromiseLike<T>): Promise<T> {
const attempts: FallbackAttempt[] = [];
for (const leg of legs) {
try {
Expand All @@ -54,16 +54,16 @@ export function createClientFallbackModel(legs: FallbackLeg[]): LanguageModelV3
}

return {
specificationVersion: "v3",
specificationVersion: "v4",
provider: primary.provider,
modelId: primary.modelId,
supportedUrls: primary.supportedUrls,
doGenerate(
options: LanguageModelV3CallOptions,
): PromiseLike<LanguageModelV3GenerateResult> {
options: LanguageModelV4CallOptions,
): PromiseLike<LanguageModelV4GenerateResult> {
return attempt((m) => m.doGenerate(options));
},
doStream(options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3StreamResult> {
doStream(options: LanguageModelV4CallOptions): PromiseLike<LanguageModelV4StreamResult> {
return attempt((m) => m.doStream(options));
},
};
Expand Down
24 changes: 12 additions & 12 deletions packages/workers-ai-provider/src/gateway-delegate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LanguageModelV3, LanguageModelV3CallOptions } from "@ai-sdk/provider";
import type { LanguageModelV4, LanguageModelV4CallOptions } from "@ai-sdk/provider";
import {
asText,
buildGatewayEntry,
Expand Down Expand Up @@ -154,7 +154,7 @@ export interface ProviderPlugin {
modelId: string;
fetch: typeof globalThis.fetch;
baseURL?: string;
}): LanguageModelV3;
}): LanguageModelV4;
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -401,7 +401,7 @@ export interface GatewayDelegateConfig {
}

export interface GatewayDelegate {
(slug: string, options?: DelegateCallOptions): LanguageModelV3;
(slug: string, options?: DelegateCallOptions): LanguageModelV4;
}

/**
Expand Down Expand Up @@ -431,7 +431,7 @@ export function createGatewayDelegate(config: GatewayDelegateConfig): GatewayDel
const buildOne = (
slug: string,
options: DelegateCallOptions,
): { model: LanguageModelV3; transport: Transport } => {
): { model: LanguageModelV4; transport: Transport } => {
const parsed = parseSlug(slug);
const info = resolveProvider(slug, parsed);

Expand Down Expand Up @@ -816,7 +816,7 @@ function makeServerFallbackModel(params: {
opts: DelegateCallOptions;
selection: Selection;
callOptions: DelegateCallOptions;
}): LanguageModelV3 {
}): LanguageModelV4 {
const { binding, gatewayId, gatewayOptions, legs, opts, selection, callOptions } = params;
const first = legs[0]!;

Expand All @@ -834,7 +834,7 @@ function makeServerFallbackModel(params: {

const dispatch = async (
method: "doGenerate" | "doStream",
options: LanguageModelV3CallOptions,
options: LanguageModelV4CallOptions,
): Promise<unknown> => {
// 1) Capture each leg's native request without hitting the network.
const entries: GatewayEntry[] = [];
Expand All @@ -854,7 +854,7 @@ function makeServerFallbackModel(params: {
...(leg.info.baseURL ? { baseURL: leg.info.baseURL } : {}),
});
try {
await (model[method] as (o: LanguageModelV3CallOptions) => Promise<unknown>)(
await (model[method] as (o: LanguageModelV4CallOptions) => Promise<unknown>)(
options,
);
} catch (e) {
Expand Down Expand Up @@ -905,21 +905,21 @@ function makeServerFallbackModel(params: {
fetch: (async () => resp) as typeof globalThis.fetch,
...(winner.info.baseURL ? { baseURL: winner.info.baseURL } : {}),
});
return (winnerModel[method] as (o: LanguageModelV3CallOptions) => Promise<unknown>)(
return (winnerModel[method] as (o: LanguageModelV4CallOptions) => Promise<unknown>)(
options,
);
};

return {
specificationVersion: "v3",
specificationVersion: "v4",
provider: refModel.provider,
modelId: refModel.modelId,
supportedUrls: refModel.supportedUrls,
doGenerate(options) {
return dispatch("doGenerate", options) as ReturnType<LanguageModelV3["doGenerate"]>;
return dispatch("doGenerate", options) as ReturnType<LanguageModelV4["doGenerate"]>;
},
doStream(options) {
return dispatch("doStream", options) as ReturnType<LanguageModelV3["doStream"]>;
return dispatch("doStream", options) as ReturnType<LanguageModelV4["doStream"]>;
},
} as LanguageModelV3;
} as LanguageModelV4;
}
2 changes: 1 addition & 1 deletion packages/workers-ai-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export function createWorkersAI(options: WorkersAISettings): WorkersAI {
"catalog",
);
}
// The delegate returns a `LanguageModelV3` built by the configured plugin.
// The delegate returns a `LanguageModelV4` built by the configured plugin.
// It's structurally compatible with the AI SDK consumers this provider is
// used with; the cast keeps the public return type unchanged.
return getDelegate(modelId)(
Expand Down
Loading
Loading