I was trying to use workers-ai-provider with openai/gpt-5.6-luna but I kept getting an error in AI Gateway
{ "error": "Model execution failed (User Input Error): Invalid value at input: Invalid input", "state": "Failed" }
I used a pretty basic example from https://github.com/cloudflare/ai/tree/main/packages/workers-ai-provider#third-party-models-via-ai-gateway
import { createWorkersAI } from "workers-ai-provider";
import { openai } from "workers-ai-provider/openai";
import { streamText } from "ai";
const workersai = createWorkersAI({
binding: env.AI,
providers: [openai], // opt-in; enables third-party routing
});
const result = streamText({
model: workersai("openai/gpt-5.6-luna"), // routed through AI Gateway
prompt: "Hello",
});
After some investigation by Opus, turns out it's because the gpt-5.6 class of models only support the OpenAI Response API wire format, but the workers-ai-provider/openai provider only does the OpenAI Completions API wire format.
The workaround was to use a custom provider
import { createOpenAI } from "@ai-sdk/openai";
/**
* `gpt-5.6-luna` only accepts the Responses API wire format, while the stock
* `workers-ai-provider/openai` plugin builds models with `.chat()`.
*/
const openaiResponses: ProviderPlugin = {
wireFormat: "openai",
create: ({ modelId, fetch, baseURL }) =>
createOpenAI({ apiKey: "unused", fetch, ...(baseURL ? { baseURL } : {}) }).responses(modelId),
};
const workersai = createWorkersAI({
binding: env.AI,
providers: [openaiResponses], // custom provider
});
I was trying to use
workers-ai-providerwithopenai/gpt-5.6-lunabut I kept getting an error in AI GatewayI used a pretty basic example from https://github.com/cloudflare/ai/tree/main/packages/workers-ai-provider#third-party-models-via-ai-gateway
After some investigation by Opus, turns out it's because the gpt-5.6 class of models only support the OpenAI Response API wire format, but the
workers-ai-provider/openaiprovider only does the OpenAI Completions API wire format.The workaround was to use a custom provider