Skip to content

Generate Text > OpenAI > Web Search > Zod validation error if the web sources include oai-<sports|finance|etc.> sources #9978

@joncursi

Description

@joncursi

Description

When performing a web search using generateText with an OpenAI model, OpenAI may respond with the following sources as an example:

{
  ...
   "output":[
      {
        ...
         "action":{
            "type":"search",
            "query":"current price of BTC",
            "sources":[
               {
                  "type":"url",
                  "url":"https://coinmarketcap.com/currencies/ethereum/?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://coinmarketcap.com/currencies/ether-fi-ethfi/?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://coinmarketcap.com/currencies/ethereum-classic/?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://www.coindesk.com/markets/2025/10/31/analyst-says-ethereum-is-the-best-ecosystem-and-ether-is-poised-to-top-usd5-000?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://www.coindesk.com/markets/2024/12/06/ether-hits-4-000-as-coinbase-premium-and-ethereum-active-addresses-surge?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://www.coinbase.com/price/ethereum?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://bingx.com/en/converter/ethereum/usd?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://www.worldcoinindex.com/coin/ethereum/rates?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://bravenewcoin.com/insights/ethereum-eth-price-prediction-ethereum-breaks-4400-as-triangle-breakout-and-surging-volume-fuel-5k-7k-rally-outlook?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://bravenewcoin.com/insights/ethereum-price-forecast-eth-eyes-4100-as-market-sentiment-strengthens?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://www.coingecko.com/en/coins/ethereum?utm_source=openai"
               },
               {
                  "type":"url",
                  "url":"https://coingape.com/price/ethereum/?utm_source=openai"
               },
               {
                  "type":"api",
                  "name":"oai-finance"
               }
            ]
         }
      }
   ]
 }
  ...
}

Note the following source:

{
  "type":"api",
  "name":"oai-finance"
}

This causes the generateText call to fail due to a Zod validation error inside of the AI SDK:

ZodError: [
      {
        "code": "invalid_value",
        "values": [
          "url"
        ],
        "path": [
          "output",
          0,
          "action",
          "sources",
          12,
          "type"
        ],
        "message": "Invalid input: expected \"url\""
      },
      {
        "expected": "string",
        "code": "invalid_type",
        "path": [
          "output",
          0,
          "action",
          "sources",
          12,
          "url"
        ],
        "message": "Invalid input: expected string, received undefined"
      }
    ]
        at new ZodError (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/zod/v4/core/core.cjs:35:39)
        at Object.<anonymous> (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/zod/v4/core/parse.cjs:82:20)
        at Object.validate (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/@ai-sdk/provider-utils/dist/index.js:1908:33)
        at safeValidateTypes (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/@ai-sdk/provider-utils/dist/index.js:1945:39)
        at safeParseJSON (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/@ai-sdk/provider-utils/dist/index.js:1990:18)
        at /Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/@ai-sdk/provider-utils/dist/index.js:2320:30
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async postToApi (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/@ai-sdk/provider-utils/dist/index.js:2141:14)
        at async OpenAIResponsesLanguageModel.doGenerate (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/@ai-sdk/openai/dist/index.js:3303:9)
        at async fn (/Users/joncursi/Sites/joncursi/askwiz-backend/node_modules/ai/dist/index.js:3429:34),

AI SDK Version

Happens on both v5 and v6 of the AI SDK

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions