You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

o4-mini-2025-04-16调用web_search_preview工具报错问题咨询

解决o4-mini-2025-04-16调用web_search_preview工具时的400错误问题

问题重现

调用OpenAI的o4-mini-2025-04-16模型并使用web_search_preview工具时,持续收到400错误,提示:

Hosted tool 'web_search_preview' is not supported with o4-mini-2025-04-16.

原始请求代码:

const payload = {
  model: "o4-mini-2025-04-16",
  tools: [{
    type: "web_search_preview",
    // Optional: configure search context size (small, medium, high)
    search_context_size: "high"
  }],
  reasoning: {effort: "high"},
  // Optional: set maximum output tokens (default varies by model)
  max_output_tokens: 3000,
  input: "What is the current weather forecast for today? Include temperature, precipitation, and wind conditions."
};

// Make the API request using axios
const response = await axios.post('https://api.openai.com/v1/responses',
  payload,
  {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
    }
  }
);

错误详情:

Error querying OpenAI:
Status code: 400
Response data: {error: {message: "Hosted tool 'web_search_preview' is not supported with o4-mini-2025-04-16.",type: 'invalid_request_error',param: 'tools',code: null}}

已知测试结果:使用gpt-4.1并移除reasoning字段可正常运行;更换支持reasoning的其他模型也能正常工作;OpenAI官方客服告知o4-mini支持web搜索。

可能的修复方案

1. 修正工具参数的格式

OpenAI工具调用规范要求,工具的配置参数必须嵌套在parameters字段内,而非直接与type同级。你的代码中直接将search_context_size放在工具对象中,不符合API要求,这是最可能的错误原因。

修复后的payload工具部分:

tools: [
  {
    type: "web_search_preview",
    parameters: {
      search_context_size: "high"
    }
  }
]

2. 移除Reasoning字段测试

虽然o4-mini支持reasoning功能,但部分工具调用场景下可能存在兼容性冲突。建议先移除reasoning字段,验证工具调用是否正常:

const payload = {
  model: "o4-mini-2025-04-16",
  tools: [
    {
      type: "web_search_preview",
      parameters: {
        search_context_size: "high"
      }
    }
  ],
  max_output_tokens: 3000,
  input: "What is the current weather forecast for today? Include temperature, precipitation, and wind conditions."
};

3. 使用无日期后缀的模型别名

尝试使用o4-mini而非带日期的o4-mini-2025-04-16版本,避免特定版本的功能限制:

model: "o4-mini"

4. 确认API端点兼容性

确保/v1/responses端点支持o4系列模型的工具调用(目前该端点已支持o4系列,但可再次验证官方文档的最新说明)。

内容的提问来源于stack exchange,提问作者Sidharth Rajmohan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 06:51:20