Skip to content

workers-ai-provider does not work with openai/gpt-5.6 class models #643

Description

@longzheng

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
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions