Skip to content
Source
Sign inSign up
TanStack/ai

`ai-openai`: `modelOptions.verbosity` is sent top-level instead of as `text.verbosity`, and `modelOptions.text` is dropped when `outputSchema` is set #2292 (GitHub #2291)

OpenXhale1(GitHub profile, opens in a new tab) opened this issue 0 comments
Xhale1(GitHub profile, opens in a new tab)commented

Disclaimer: I used Opus 5.5 to help report this issue. I ran into it while migrating my company's repo from Vercel AI to Tanstack AI.

TanStack AI version

@tanstack/ai 1.10.1, @tanstack/ai-openai 1.2.1 (@tanstack/openai-base 1.1.3)

Framework/Library version

Node 26.14, server-side (no framework), zod 4.6.7

Describe the bug and the steps to reproduce it

There's no way to set verbosity on the OpenAI Responses text adapter when using outputSchema:

  1. modelOptions.verbosity is typed on OpenAIBaseOptions (its JSDoc links to text.verbosity), but mapOptionsToRequest spreads modelOptions into the request as-is, so it's sent as a top-level verbosity field. The Responses API only defines text.verbosity. (Top-level verbosity is correct for Chat Completions, which may be where it came from.)
  2. modelOptions.text.verbosity is sent correctly for plain text, but as soon as outputSchema is set, the adapter replaces text with { format }, so it's dropped. This happens in mapOptionsToRequest, structuredOutput and structuredOutputStream.

Run with node repro.ts (no API key or network needed; fetch is stubbed to print the request):

import { chat } from "@tanstack/ai";
import { createOpenaiChat } from "@tanstack/ai-openai";
import { z } from "zod";

// Print each request body instead of calling OpenAI
globalThis.fetch = async (_url, init) => {
  const { verbosity, text } = JSON.parse(String(init?.body));
  console.log(JSON.stringify({ verbosity, text }));
  return Response.json({ error: { message: "stub" } }, { status: 400 });
};

const adapter = createOpenaiChat("gpt-6-luna", "sk-dummy", { maxRetries: 0 });
const messages = [{ role: "user" as const, content: "Hi" }];
const outputSchema = z.object({ answer: z.string() });

const attempts = [
  // A. The typed option
  () =>
    chat({ adapter, messages, threadId: "t", stream: false, modelOptions: { verbosity: "low" } }),
  // B. The Responses API's own shape
  () =>
    chat({
      adapter,
      messages,
      threadId: "t",
      stream: false,
      modelOptions: { text: { verbosity: "low" } },
    }),
  // C. A + outputSchema
  () =>
    chat({ adapter, messages, threadId: "t", outputSchema, modelOptions: { verbosity: "low" } }),
  // D. B + outputSchema
  () =>
    chat({
      adapter,
      messages,
      threadId: "t",
      outputSchema,
      modelOptions: { text: { verbosity: "low" } },
    }),
];

for (const attempt of attempts) {
  await attempt().catch(() => {});
}

Output, one line per attempt A–D (schema shortened to …):

{"verbosity":"low"}
{"text":{"verbosity":"low"}}
{"verbosity":"low","text":{"format":{"type":"json_schema","name":"structured_output","schema":…,"strict":true}}}
{"text":{"format":{"type":"json_schema","name":"structured_output","schema":…,"strict":true}}}

Expected: A–D all send text.verbosity: "low" (with text.format alongside it in C and D).

Actual: A and C send an unsupported top-level verbosity. D silently drops it. Only B works, and it can't be combined with outputSchema.

Suggested fix

  • In the Responses adapter, move modelOptions.verbosity into text.verbosity (or remove verbosity from the Responses options type and document text.verbosity).
  • When adding the structured-output format, merge into the caller's text instead of replacing it: text: { ...modelOptions.text, format }, in all three places linked above.

Workaround

A middleware that rewrites the request body:

import type { ChatMiddleware } from "@tanstack/ai";

export function openaiVerbosity(verbosity: "low" | "medium" | "high"): ChatMiddleware {
  return {
    name: "openai-verbosity",
    onConfig: (_context, config) => ({
      wrapFetch: (next) => {
        const send = config.wrapFetch ? config.wrapFetch(next) : next;
        return (input, init) => {
          if (typeof init?.body !== "string") return send(input, init);
          const body = JSON.parse(init.body);
          return send(input, {
            ...init,
            body: JSON.stringify({ ...body, text: { ...body.text, verbosity } }),
          });
        };
      },
    }),
  };
}

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. tanstack-source added labelsbug

  2. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

Sign in to join this conversation.