https://api.map.baidu.com/api_aic/v1/search_stream
Response Content-Type: text/event-stream
基于 HTTP Server-Sent Events(SSE)实现。服务端可主动向客户端推送数据包,适合实时展示思考过程与增量文本。
每个字段(如 data:)以 \n 结尾,整条消息以双换行符 \n\n 结束。
每次发送的消息体均为 JSON 字符串,结构与同步接口返回值保持一致。
event 为 data 或 end。end 包在程序报错或请求结束时发出,end 包的 data 为 nil。
id 在同一次请求中递增。
若一秒钟没有数据包,会发送一条空白消息用于维持连接。
data 包中可能包含思考过程 thought_data,不必定返回。
请求参数与「同步对话」相同。若需文本增量输出,将 text_stream 设为 1。
event: dataid: 0data: {"data": {}, "is_end": false, "message": "ok", "status": 0}
思考过程示例:
{"data": {"session_id": "557908058564198400","query": "骑车去百度科技园","dialogue_id": "33113064","thought_data": {"prefix": "正在为你规划从","suffix": "的路线","keywords": ["我的位置","百度科技园"]}},"is_end": false,"message": "ok","status": 0}
{"is_end": false,"log_id": "3534739558","message": "ok","result": {"session_id": "804848076497027072","query": "介绍一下颐和园","answer_type": "gptmodel_flow","conversation": [{"new_line": false,"text": "颐和园是北京的著名景点,","type": "text","target_poi": {"name": "颐和园","std_tag": "旅游景点;其他","uid": "2a7a25ecf9cf13636d3e1bad"}}]},"status": 0}
{"data": {"session_id": "533247978354245632","query": "帮我推荐一下天安门附近的火锅店","dialogue_id": "296536","answer_type": "gptmodel_poi","poi_data": {"info": {"tips": "为您找到天安门附近的火锅店","tts_tips": "为您找到天安门附近的火锅店"},"deeplink_app_url": "","deeplink_html_url": "","data": [{"uid": "c68e523db2bc793c0bf5eb89","name": "海底捞(上地华联店)","lng": 116.3012,"lat": 40.0501,"addr": "北京市海淀区农大南路1号院1号楼上地华联购物中心F4","province_name": "北京市","city_name": "北京市","area_name": "海淀区","phone": "(010)62667572","business_time": "10:00-07:00","tag": "火锅店","category": "美食;中餐厅","overall_rating": "4.8","price": "105.0","ai_recommend_reason": "环境宽敞,适合团建。","ai_tags": ["味道很好","可停车","适合团建"],"ai_daka": "52人在这里提到「味道很好」","ai_show": "1","head_image": "https://poi-pic.cdn.bcebos.com/example.jpg","distance": "3.7km","distance_local": 370,"distance_center": 299,"ranking": "上地最热火锅榜第1名"}]}},"message": "ok","status": 0}
附近没有对应 POI 时,返回空数组,便于区分「出错」与「无结果」:
{"is_end": false,"message": "ok","result": {"session_id": "577955271688060928","query": "附近500米内的茶颜悦色","answer_type": "gptmodel_poi","poi_data": {"info": {"tts_tips": "抱歉未找到结果,我会好好学习天天向上。"},"data": [],"deeplink_app_url": "","deeplink_html_url": ""}},"status": 0}
{"data": {"session_id": "533253914162626560","query": "帮我规划开车去天安门的路线","answer_type": "gptmodel_navigate","navigation_data": {"type": "drive","total": 1,"info": {"tts_tips": "已为您规划前往天安门的路线。全程23.90公里,大约需要51分钟。"},"origin": {"name": "我的位置","lng": 116.339303,"lat": 40.01116},"destination": {"name": "天安门","lng": 116.452562,"lat": 39.936404},"via_points": [{"name": "马驹桥服务区","lng": "116.568613","lat": "39.765945"}],"driving_routes": [{"tag": "红绿灯少","distance": 2000,"duration": 1800,"toll": 0,"toll_distance": 0,"restriction_info": {"status": 0,"desc": ""},"steps": [{"leg_index": 0,"direction": 1,"distance": 1000,"duration": 600,"road_name": "信息路","start_location": {"lng": 116.403874,"lat": 39.914889},"end_location": {"lng": 116.405288,"lat": 39.914889},"path": "116.403874,39.914889;116.405288,39.914889"}]}]}},"message": "ok","status": 0}
{"result": {"query": "帮我规划骑车去天安门的路线","answer_type": "gptmodel_navigate","navigation_data": {"type": "bike","info": {"tts_tips": "已为您规划前往天安门的骑行路线。"},"origin": {"name": "我的位置","lng": 116.339303,"lat": 40.01116},"destination": {"name": "天安门","lng": 116.452562,"lat": 39.936404},"bike_routes": [{"distance": 15000,"duration": 3600,"steps": [{"direction": 3,"distance": 500,"duration": 100,"instruction": "向东行驶500米","path": "116.403874,39.914889;116.408874,39.914889"}]}]}},"status": 0,"message": "ok"}
{"result": {"query": "帮我规划步行去天安门的路线","answer_type": "gptmodel_navigate","navigation_data": {"type": "walk","info": {"tts_tips": "已为您规划前往天安门的步行路线。"},"origin": {"name": "我的位置","lng": 116.339303,"lat": 40.01116},"destination": {"name": "天安门","lng": 116.452562,"lat": 39.936404},"walk_routes": [{"distance": 1500,"duration": 300,"steps": [{"direction": 3,"distance": 500,"duration": 100,"instruction": "向东步行500米","path": "116.403874,39.914889;116.408874,39.914889"}]}]}},"status": 0,"message": "ok"}
{"result": {"query": "帮我规划坐地铁去天安门的路线","answer_type": "gptmodel_navigate","navigation_data": {"type": "public","info": {"tts_tips": "已为您规划前往天安门的公共交通方案。"},"origin": {"name": "我的位置","lng": 116.339303,"lat": 40.01116},"destination": {"name": "天安门","lng": 116.452562,"lat": 39.936404},"total": 1,"public_routes": [{"distance": 12000,"duration": 3600,"price": 5,"steps": [[{"distance": 1219,"duration": 1039,"instructions": "步行1.2公里","vehicle_info": {"type": 5,"detail": null}},{"distance": 8000,"duration": 1500,"instructions": "乘坐地铁","vehicle_info": {"type": 3,"detail": {"name": "地铁4号线","type": "1","stop_num": 8,"on_station": "西二旗","off_station": "西单"}}}]]}]}},"status": 0,"message": "ok"}
火车、飞机、大巴的 vehicle_info.detail 格式预留,当前暂未接入。
请求参数 multi_route=1 时,每种推荐交通方式返回一条路线。
{"result": {"session_id": "28541876856948480","query": "明天早上8点开车去故宫","answer_type": "gptmodel_future_multi_route","multi_route_data": {"drive": {"mode": "drive","rec_travel": true,"tts_tips": "已为您规划明天8点前往故宫博物院的路线。全程24.37公里,大约需要46分钟。","origin": {"name": "我的位置","lng": "116.279881","lat": "40.050676"},"destination": {"name": "故宫博物院","lng": "116.403326","lat": "39.924105"},"driving_routes": []},"public": {"mode": "public","tts_tips": "已为您找到明天8点出发,前往故宫博物院方案,全程1小时45分钟。","origin": {"name": "我的位置","lng": "116.279881","lat": "40.050676"},"destination": {"name": "故宫博物院","lng": "116.403326","lat": "39.924105"},"public_routes": []}}},"status": 0,"message": "ok"}
{"data": {"query": "今天晚上9点在五道口购物中心看电影,开车几点出发合适","answer_type": "gptmodel_future","future_data": {"arrival_time": 1724468896,"departure_time": 1724464800,"origin": {"name": "我的位置","lng": "116.301578","lat": "40.050262"},"destination": {"name": "五道口购物中心","lng": "116.339196","lat": "39.991931"},"info": {"tts_tips": "建议您至少要在21点0分前出发。全程大约需要24分钟。"},"driving_routes": [{"tag": "红绿灯少","distance": 2000,"duration": 1800,"toll": 0,"toll_distance": 0}]}},"status": 0,"message": "ok"}
仅在大模型将 query 识别为出游计划时触发,例如「北京3日游攻略」。需开通高级权限。
{"data": {"query": "北京3日游攻略","answer_type": "gptmodel_travel","travel_data": {"info": {"tts_tips": "参考众多资料, 已帮你生成专属攻略"},"data": {"multi_agent_card": {"deeplink_html_url": "https://map.baidu.com/vercel/h5v3/mark-travel?routeID=example","recommend_info": {"scope_info": {"title": "推荐景点","summary": "北京热门景点:天安门、长城、天坛等。","poi_list": [{"name": "天安门","uid": "65e1ee886c885190f60e77ff","lng": "12958170.88","lat": "4825940.97","std_tag": "旅游景点;文物古迹","score": "4.7"}]},"cater_info": {"title": "推荐美食","summary": "北京热门美食打卡地。","poi_list": []},"hotel_info": {"title": "推荐酒店","summary": "北京多家酒店上榜热门榜单。","poi_list": []}},"travel_trip": {"head_info": {"title": "推荐行程"},"travel_route": [{"days": "1天","title": "京城历史之旅","summary": "故宫探秘,感受京城历史底蕴。","route": [{"type": "poi","ponit": {"name": "故宫博物院","uid": "06d2dffda107b0ef89f15db6"}}]}]}},"note_card": {"title": "相关推荐笔记","note_list": [{"head_line": "北京三日游,精华全攻略","cover_img": ""}]},"bubble_card": {"buble_list": [{"title": "北京热门景区3日游"}]}}}},"status": 0,"message": "ok"}
导航意图下,若 POI 或起终点描述模糊,需要接入方根据返回列表选择后重新发起 search / search_stream。一次 query 中多个 POI 不清晰时,可能连续澄清多次。
{"data": {"query": "开车去肯德基","answer_type": "gptmodel_poi_clarify","poi_clarify_data": {"info": {"tts_tips": "为您找到10个肯德基 您要去第几个"},"data": [{"info": {"name": "肯德基(新浪总部店)","uid": "feab3ad206554aba455726dd","address": "东北旺路中关村软件园二期"},"location": {"lng": 116.282648,"lat": 40.047997},"route": {"distance_local": 380}}]}},"status": 0,"message": "ok"}
大模型识别为沿途搜意图时,接入方需选择途经点后重新发起请求。
{"result": {"query": "开车去故宫顺路去个公园","answer_type": "gptmodel_onway_search_clarify","onwaysearch_clarify_data": {"info": {"tts_tips": "途经点是第几个"},"data": [{"info": {"name": "中国银行城市森林公园","uid": "bd559077fd7bc57688fc0693","address": "北京市海淀区马连洼西路","tags": ["旅游景点","公园"]},"location": {"lng": 116.273353,"lat": 40.040737},"route": {"tags": ["最近"],"distance_local": 2614,"distance_extra": 1154,"time_extra": 274,"time_local": 581}}]}},"status": 0,"message": "ok"}
根据返回列表选择后,将 query 设为语义化选项(如「第一个」「第二个」),再次调用同步或流式接口,通常返回 gptmodel_navigate。
{"query": "第一个","id": "39CC3177EB9691F***AF556B|VYFRRMJLG","loc_lng": 116.30157634933593,"loc_lat": 40.0502618943843,"coord_type": "bd09ll","ret_coord_type": "bd09ll","ak": "您的密钥"}
与「同步对话」一致,详见同步对话页的服务状态码。
上一篇
下一篇