搜索结果

×

搜索结果将在这里显示。

OpenAI接口 网络搜索 文档

网络搜索接口概述

网络搜索接口允许API用户通过OpenAI模型进行网络搜索,获取最新的网络信息。

适用于需要实时数据的应用场景,例如获取:天气、股市行情、交通信息、近期新闻等等。

基础信息

  • 请求方式:POST
  • Base URL: https:/openai-ss.cn/v1/responses
  • 认证方式:Bearer Token

请求示例

import requests

# 配置API密钥 (实际使用时请替换为您的密钥)
api_key = "sk-******"  # 替换为你的令牌

# 设置请求头和URL
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"  # 认证头
}

data = {
    "model": "gpt-4.1",  # 指定使用的模型版本
    "tools": [{"type": "web_search_preview"}],  # 启用网络搜索功能
    "input": "openai近期有发布产品吗?",  # 搜索查询内容
}

try:
    # 发送POST请求
    response = requests.post(
        "https://openai-ss.cn/v1/responses",
        headers=headers,
        json=data
    )

    # 检查响应状态
    response.raise_for_status()

    # 打印JSON格式的响应结果
    print(response.json())

except requests.exceptions.RequestException as e:
    print(f"请求出错: {e}")

响应字段说明

字段 类型 说明
id string 响应唯一ID
model string 使用的模型名称
output array 包含搜索结果和生成内容
usage object 令牌使用情况统计
status string 请求状态(completed/running/failed)

响应示例

{
    'id': 'resp_687a6470dd7c819a8ac3aba3d76030ac03505551af5755e0',
    'object': 'response',
    'created_at': 1752851568,
    'status': 'completed',
    'background': False,
    'error': None,
    'incomplete_details': None,
    'instructions': None,
    'max_output_tokens': None,
    'max_tool_calls': None,
    'model': 'gpt-4.1-2025-04-14',
    'output': [
        {
            'id': 'ws_687a64717e0c819a84990b4ad921160303505551af5755e0',
            'type': 'web_search_call',
            'status': 'completed',
            'action': {
                'type': 'search',
                'query': 'OpenAI近期发布的新产品'
            }
        },
        {
            'id': 'msg_687a64747568819aa4514e3e757ab2b803505551af5755e0',
            'type': 'message',
            'status': 'completed',
            'content': [
                {
                    'type': 'output_text',
                    'annotations': [
                        {
                            'type': 'url_citation',
                            'end_index': 199,
                            'start_index': 114,
                            'title': 'OpenAIOperator',
                            'url': 'https: //zh.wikipedia.org/wiki/OpenAI_Operator?utm_source=openai'
                        },
                        {
                            'type': 'url_citation',
                            'end_index': 391,
                            'start_index': 301,
                            'title': 'OpenAIDeepResearch',
                            'url': 'https: //zh.wikipedia.org/wiki/OpenAI_Deep_Research?utm_source=openai'
                        },
                        {
                            'type': 'url_citation',
                            'end_index': 580,
                            'start_index': 445,
                            'title': 'Sora(人工智能模型)',
                            'url': 'https: //zh.wikipedia.org/wiki/Sora_%28%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD%E6%A8%A1%E5%9E%8B%29?utm_source=openai'
                        },
                        {
                            'type': 'url_citation',
                            'end_index': 755,
                            'start_index': 676,
                            'title': 'OpenAIo3',
                            'url': 'https: //zh.wikipedia.org/wiki/OpenAI_o3?utm_source=openai'
                        },
                        {
                            'type': 'url_citation',
                            'end_index': 920,
                            'start_index': 843,
                            'title': 'GPT-4.5',
                            'url': 'https: //zh.wikipedia.org/wiki/GPT-4.5?utm_source=openai'
                        },
                        {
                            'type': 'url_citation',
                            'end_index': 1109,
                            'start_index': 1032,
                            'title': 'GPT-4.1',
                            'url': 'https: //zh.wikipedia.org/wiki/GPT-4.1?utm_source=openai'
                        },
                        {
                            'type': 'url_citation',
                            'end_index': 1251,
                            'start_index': 1180,
                            'title': '深夜炸场,OpenAI首次开发者日:新模型发布,支持128K上下文,价格直降,GPT商店要来了-36氪',
                            'url': 'https: //www.36kr.com/p/2507548293988352?utm_source=openai'
                        }
                    ],
                    'logprobs': [

                    ],
                    'text': '近期,OpenAI发布了多款新产品和模型,以下是主要的发布内容:\n\n1.**OpenAIOperator**:于2025年1月23日推出的人工智能代理,能够通过网页浏览器自主执行各种任务,如填写表单、下单购物、安排预约等。([
                        zh.wikipedia.org
                    ](https: //zh.wikipedia.org/wiki/OpenAI_Operator?utm_source=openai))\n\n2.**OpenAIDeepResearch**:于2025年2月3日发布的增强型研究功能,旨在扩展人工智能系统的知识获取和推理能力,能够在5至30分钟内自动浏览网页并生成附有引用来源的报告。([
                        zh.wikipedia.org
                    ](https: //zh.wikipedia.org/wiki/OpenAI_Deep_Research?utm_source=openai))\n\n3.**Sora**:于2024年2月15日展示的文本到视频生成模型,能够根据文本描述生成高清视频。([
                        zh.wikipedia.org
                    ](https: //zh.wikipedia.org/wiki/Sora_%28%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD%E6%A8%A1%E5%9E%8B%29?utm_source=openai))\n\n4.**OpenAIo3**:于2025年1月31日发布的生成式预训练模型,作为OpenAIo1的升级版本,在需要推理的问题上保留了更多的计算和思考时间,提高了回答的准确性和深度。([
                        zh.wikipedia.org
                    ](https: //zh.wikipedia.org/wiki/OpenAI_o3?utm_source=openai))\n\n5.**GPT-4.5(Orion)**:于2025年2月27日发布的大型语言模型,主要使用无监督学习进行训练,结合了监督微调及基于人类反馈的强化学习,支持15种语言。([
                        zh.wikipedia.org
                    ](https: //zh.wikipedia.org/wiki/GPT-4.5?utm_source=openai))\n\n6.**GPT-4.1**:于2025年4月14日发布的大型语言模型,提供了GPT-4.1、GPT-4.1mini与GPT-4.1nano三个版本,具备一百万个token的上下文,提升了长文本处理和工具使用能力。([
                        zh.wikipedia.org
                    ](https: //zh.wikipedia.org/wiki/GPT-4.1?utm_source=openai))\n\n此外,OpenAI还推出了AssistantsAPI,帮助开发者在自己的程序中构建智能代理,提供了代码解释器、检索和函数调用等新功能。([
                        36kr.com
                    ](https: //www.36kr.com/p/2507548293988352?utm_source=openai))\n\n这些发布体现了OpenAI在人工智能领域的持续创新和多模态技术的发展。'
                }
            ],
            'role': 'assistant'
        }
    ],
    'parallel_tool_calls': True,
    'previous_response_id': None,
    'reasoning': {
        'effort': None,
        'summary': None
    },
    'service_tier': 'default',
    'store': True,
    'temperature': 1.0,
    'text': {
        'format': {
            'type': 'text'
        }
    },
    'tool_choice': 'auto',
    'tools': [
        {
            'type': 'web_search_preview',
            'search_context_size': 'medium',
            'user_location': {
                'type': 'approximate',
                'city': None,
                'country': 'US',
                'region': None,
                'timezone': None
            }
        }
    ],
    'top_logprobs': 0,
    'top_p': 1.0,
    'truncation': 'disabled',
    'usage': {
        'input_tokens': 309,
        'input_tokens_details': {
            'cached_tokens': 0
        },
        'output_tokens': 611,
        'output_tokens_details': {
            'reasoning_tokens': 0
        },
        'total_tokens': 920
    },
    'user': None,
    'metadata': {

    }
}

使用建议

  1. 对于时效性强的查询,建议启用网络搜索功能
  2. 合理控制查询长度,避免不必要的令牌消耗
  3. 错误处理应包含网络异常和API限制等情况