workers-ai-provider: response_format.json_schema missing `name` — breaks structured output on OpenAI partner models (e.g. openai/gpt-5.4-mini)
Summary
When workers-ai-provider is used with an OpenAI partner model (e.g. openai/gpt-5.4-mini) and the AI SDK's structured output (generateText + Output.object, or generateObject), the request is rejected by OpenAI with:
{
"state": "Failed",
"error": "Model execution failed (User Input Error): Missing required parameter: 'response_format.json_schema.name'."
}
The provider sends the raw JSON Schema as response_format.json_schema, but OpenAI's Structured Outputs API requires response_format.json_schema to be an object containing a name (and schema). The AI SDK-supplied name (via Output.object({ schema, name })) is silently dropped.
https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create#(resource)%20%24shared%20%3E%20(model)%20response_format_json_schema%20%3E%20(schema)%20%3E%20(property)%20json_schema
Reproducer
// wrangler.jsonc
// "ai": { "binding": "AI", "remote": true }
// "vars": { "LLM_MODEL": "openai/gpt-5.4-mini" }
import { createWorkersAI } from "workers-ai-provider";
import { generateText, Output } from "ai";
import { valibotSchema } from "@ai-sdk/valibot";
import * as v from "valibot";
const Schema = v.object({ ok: v.boolean() });
const workersai = createWorkersAI({ binding: env.AI });
const model = workersai("openai/gpt-5.4-mini");
await generateText({
model,
prompt: "Return { ok: true }",
output: Output.object({
schema: valibotSchema(Schema),
name: "Result", // ← dropped by workers-ai-provider
}),
});
// → Model execution failed (User Input Error):
// Missing required parameter: 'response_format.json_schema.name'.
Expected
OpenAI accepts the request and returns a structured response.
Actual
OpenAI rejects with Missing required parameter: 'response_format.json_schema.name'.. Output.object's name / description have no effect.
Root cause
In packages/workers-ai-provider/src/workersai-chat-language-model.ts, getArgs builds the JSON-mode payload as follows:
https://github.com/cloudflare/ai/blob/9d2cc8b00e02e70f9e1bbf42a8b7c0dd730edc4a/packages/workers-ai-provider/src/workersai-chat-language-model.ts#L95-L109
The AI SDK V3 LanguageModelV3CallOptions.responseFormat shape is { type: "json", schema, name?, description? }. The provider uses .schema but ignores .name / .description, and does not wrap them into the OpenAI Structured Outputs envelope { name, schema, strict? } that the API requires.
Native Workers AI models (@cf/...) are tolerant of the bare schema shape, so this bug only surfaces on partner-model routes (OpenAI, etc.), which is presumably why it has gone unnoticed.
Environment
workers-ai-provider: 3.1.14 (latest)ai: 6.0.x@ai-sdk/valibot: 2.0.x- Runtime: Cloudflare Workers (wrangler dev,
ai.remote: true) - Model:
openai/gpt-5.4-mini
I looked into this — confirming the bug and root cause against current main (9d2cc8b).
In packages/workers-ai-provider/src/workersai-chat-language-model.ts:99-103, the json case builds:
response_format: {
type: "json_schema",
json_schema:
responseFormat?.type === "json" ? responseFormat.schema : undefined,
},
It assigns the raw schema directly to json_schema, whereas OpenAI partner models require json_schema to be { name, schema }. The AI SDK's responseFormat.name (from Output.object({ schema, name })) is never read, so it's dropped — hence Missing required parameter: 'response_format.json_schema.name'.
The fix is minimal and lands in one place: getArgs is shared by doGenerate and doStream (via buildRunInputs), so wrapping the schema as { name, schema } there covers both generation and streaming. One detail: responseFormat.name is optional in the AI SDK (the existing structured-output.test.ts calls Output.object({ schema }) with no name), so the fix needs a name fallback (e.g. responseFormat.name ?? "response") — otherwise those calls would send name: undefined and hit the same error.
One design question before I write it, since it can't be settled from the code alone: json_schema is sent to both native @cf/... models and OpenAI partner models. Do the native models accept the { name, schema } wrapping unconditionally, or should the wrapping be gated on model family (partner-only)? If you can confirm which shape native models expect, I'm happy to open a PR with the fix plus a regression test that asserts the request body.
Thanks for the detailed write-up and root-cause — it was spot on about the code dropping name/description and sending a bare schema. Here's what landed and how it maps to your report.
What shipped
Two things together resolve this, both in [email protected] (going out later today):
1. Partner models (openai/…) — your exact failure. Third-party catalog slugs are no longer handled by the native code path you linked. createWorkersAI now routes "<provider>/<model>" slugs through AI Gateway + the real @ai-sdk/* provider, which builds the response_format.json_schema.name envelope OpenAI requires. You opt in by passing the provider plugin:
import { createWorkersAI } from "workers-ai-provider";
import { openai } from "workers-ai-provider/openai"; // optional peer: @ai-sdk/openai
const workersai = createWorkersAI({
binding: env.AI,
providers: [openai], // routes openai/* through AI Gateway
});
const result = await generateText({
model: workersai("openai/gpt-5.4-mini"),
prompt: "Return { ok: true }",
output: Output.object({ schema: valibotSchema(Schema), name: "Result" }),
});
We verified this end-to-end against live partner models (openai/gpt-5-mini, google/gemini-2.5-flash, anthropic/claude-haiku-4.5, alibaba/qwen3-max) — Output.object({ name, … }) now succeeds. If you call a "<provider>/<model>" slug without configuring providers, you'll now get a clear config error pointing you here, instead of the cryptic upstream Missing required parameter message.
2. Native models (@cf/…) — the adjacent gap. #576 fixes the path you actually linked: native Workers AI expects a bare JSON Schema (not the OpenAI { name, schema, strict } envelope), so we can't wrap it there. Instead name/description are now folded into the schema's standard title/description keywords, so the guidance is preserved rather than dropped (and existing schema-level values are never overwritten).
PR: #576. Changeset references this issue.
Closing
Closing as resolved by the routing change + #576. If your setup still hits a missing-name error after upgrading to 3.2.0 (especially if there's a partner-model config we haven't covered), please reopen with the snippet and we'll dig in. Thanks again!