Skip to content

Mixing web_search_preview and file_search results in invalid_value "url_citation" type validation error #8030

@Irvel

Description

@Irvel

Description

When I attempt to call both tools within a single generateText (or streamText) call, the Responses API returns annotations that include both url_citation and file_citation types. The SDK’s validator expects only url_citation in certain paths, which leads to a type validation error.

Reproduction:

const result = await generateText({
  model: openai('gpt-5'),
  system,
  prompt,
  tools: {
    web_search_preview: openai.tools.webSearchPreview({ searchContextSize: 'high' }),
    file_search: openai.tools.fileSearch({ vectorStoreIds: ['myvectorstoreid'], maxNumResults: 3 }),
  },
  providerOptions: {
      openai: {
        reasoningEffort: "high",
        textVerbosity: "low",
        serviceTier: "flex",
      },
    },
});

Error:

APICallError [AI_APICallError]: Failed to process successful response
    at postToApi (file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:636:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    ... 2 lines matching cause stack trace ...
    at async file:///repo/node_modules/ai/dist/index.mjs:1426:22
    at async _retryWithExponentialBackoff (file:///repo/node_modules/ai/dist/index.mjs:1577:12)
    at async streamStep (file:///repo/node_modules/ai/dist/index.mjs:4719:15)
    at async fn (file:///repo/node_modules/ai/dist/index.mjs:5060:9)
    at async file:///repo/node_modules/ai/dist/index.mjs:1426:22 {
  cause: TypeError: First parameter has member 'readable' that is not a ReadableStream.
      at assertReadableStream (/repo/node_modules/web-streams-polyfill/dist/ponyfill.js:466:19)
      at convertReadableWritablePair (/repo/node_modules/web-streams-polyfill/dist/ponyfill.js:4035:9)
      at ReadableStream.pipeThrough (/repo/node_modules/web-streams-polyfill/dist/ponyfill.js:4119:29)
      at parseJsonEventStream (file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:502:17)
      at file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:785:12
      at postToApi (file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:625:20)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async OpenAIResponsesLanguageModel.doStream (file:///repo/node_modules/@ai-sdk/openai/dist/index.mjs:2592:50)
      at async fn (file:///repo/node_modules/ai/dist/index.mjs:4763:27)
      at async file:///repo/node_modules/ai/dist/index.mjs:1426:22,
  url: 'https://api.openai.com/v1/responses',
  requestBodyValues: {
    model: 'gpt-5',
    input: [ [Object], [Object] ],
    temperature: undefined,
    top_p: undefined,
    max_output_tokens: undefined,
    text: { verbosity: 'low' },
    metadata: undefined,
    parallel_tool_calls: undefined,
    previous_response_id: undefined,
    store: undefined,
    user: undefined,
    instructions: undefined,
    service_tier: 'flex',
    include: undefined,
    prompt_cache_key: undefined,
    safety_identifier: undefined,
    reasoning: { effort: 'high' },
    tools: [ [Object], [Object] ],
    tool_choice: 'auto',
    stream: true
  },
  statusCode: 200,
  responseHeaders: {
    'alt-svc': 'h3=":443"; m

(omitted some of the output for breivity)

Error message: [{"code":"invalid_value","values":["url_citation"],"path":["output",13,"content",0,"annotations",0,"type"],"message":"Invalid input: expected \"url_citation\""},{"expected":"number","code":"invalid_type","path":["output",13,"content",0,"annotations",0,"start_index"],"message":"Invalid input: expected number, received undefined"},{"expected":"number","code":"invalid_type","path":["output",13,"content",0,"annotations",0,"end_index"],"message":"Invalid input: expected number, received undefined"},{"expected":"string","code":"invalid_type","path":["output",13,"content",0,"annotations",0,"url"],"message":"Invalid input: expected string, received undefined"},{"expected":"string","code":"invalid_type","path":["output",13,"content",0,"annotations",0,"title"],"message":"Invalid input: expected string, received undefined"},{"code":"invalid_value","values":["url_citation"],"path":["output",13,"content",0,"annotations",1,"type"],"message":"Invalid input: expected \"url_citation\""},{"expected":"number","code":"invalid_type","path":["output",13,"content",0,"annotations",1,"start_index"],"message":"Invalid input: expected number, received undefined"},{"expected":"number","code":"invalid_type","path":["output",13,"content",0,"annotations",1,"end_index"],"message":"Invalid input: expected number, received undefined"},{"expected":"string","code":"invalid_type","path":["output",13,"content",0,"annotations",1,"url"],"message":"Invalid input: expected string, received undefined"},{"expected":"string","code":"invalid_type","path":["output",13,"content",0,"annotations",1,"title"],"message":"Invalid input: expected string, received undefined"}]
                at Object.validate (file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:403:14)
                at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
                at async safeValidateTypes (file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:431:20)
                at async safeParseJSON (file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:476:12)
                at async file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:820:24
                at async postToApi (file:///repo/node_modules/@ai-sdk/provider-utils/dist/index.mjs:625:14)
                at async OpenAIResponsesLanguageModel.doGenerate (file:///repo/node_modules/@ai-sdk/openai/dist/index.mjs:2342:9)
                at async fn (file:///repo/node_modules/ai/dist/index.mjs:2144:34)
                at async file:///repo/node_modules/ai/dist/index.mjs:1426:22
                at async _retryWithExponentialBackoff (file:///repo/node_modules/ai/dist/index.mjs:1577:12)

AI SDK Version

  • "ai": "^5.0.12"
  • "@ai-sdk/openai": "^2.0.12"

Metadata

Metadata

Assignees

Labels

ai/corecore functions like generateText, streamText, etc. Provider utils, and provider spec.ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelbugSomething isn't working as documentedprovider/openaiIssues related to the @ai-sdk/openai provider

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions