View a markdown version of this page

Web 搜尋 - Amazon Bedrock

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Web 搜尋

Web 搜尋是一種內建工具,可在 Amazon Bedrock 中提供 Web 搜尋功能。當您啟用它時,支援的模型可以在請求期間從 Web 擷取目前資訊,並使用它來提供答案,而不是僅依賴他們訓練的資料。回應包括對模型使用的來源的引用。Web 搜尋由 託管和建置 AWS,您的資料預設會保持在 AWS 邊界內。

資料控管

根據預設,使用 AmazonBedrockFullAccess 政策時,會從 Amazon Bedrock Web 索引和快取提供 Web 搜尋,而且您的請求資料不會離開擷取 AWS 界限。您也可以使用 IAM 在政策層級強制執行此操作。視您使用的模型而定,您的資料會受到自動化Amazon Bedrock 濫用偵測機制的約束。

何時使用 Web 搜尋

每當答案取決於比模型的參數知識更近期、更專業或更具權威性的資訊時,Web 搜尋就會很有用。Recency 是一個常見案例:新程式庫版本的目前事件、最新產品版本、價格或文件。對於模型知識稀疏或不精確的長尾或專業問題,例如利基 APIs、特定組態值或特定網域的事實,以及您想要有基礎、可參考來源而非回收的情況,也同樣有用。

Web 搜尋的運作方式

由於工具會在 Amazon Bedrock 內執行,因此您不需要託管搜尋索引、管理爬蟲程式,或自行撰寫工具呼叫迴圈。您可以將工具新增至 Amazon Bedrock 推論請求,模型會視需要叫用它。Web 搜尋為模型提供目前資訊,讓模型能夠以引號傳回基本答案。

啟用 Web 搜尋時,模型會決定請求是否需要最新的資訊。如果是這樣,模型會向 Web 搜尋工具發出一或多個搜尋查詢,並收到一組從 Amazon 建置和維護的 Web 索引擷取的觀察。每個觀察都包含標題、來源 URL 和內容片段。模型接著會編寫以這些結果為基礎的答案,並新增指向來源的引文。

如果第一組結果不足以回答問題,模型可以使用找到的內容重新格式化其查詢,並在同一回合內再次搜尋。當結果不支援答案時,模型會通知您,而不是填補訓練資料的差距。

搜尋和擷取操作

Web 搜尋是從兩個操作建置的:

  • 搜尋 – 從 Amazon Bedrock Web 索引和知識圖表中傳回標題、URLs 和程式碼片段,以取得高可信度的事實。

  • 擷取 – 從 Amazon Bedrock 快取擷取特定 URL 的快取頁面內容。如果快取中沒有結果,模型可能會選擇根據其擁有的最佳資訊通知您或建置回應。

根據預設,這兩項操作都是使用 Amazon Bedrock Web 索引和快取完全從 AWS 服務界限內提供,這是託管在內部的 Web 內容快照 AWS,而不是在請求時從即時 Web 擷取。Responses API 中的 external_web_access 參數和 bedrock-websearch:ExternalWebAccess IAM 許可會控管搜尋和擷取是否可以直接連線到外部 Web。如需詳細資訊,請參閱控制外部 Web 存取

支援的模型

Web 搜尋適用於使用 Responses API 透過 Amazon Bedrock bedrock-mantle端點提供的 OpenAI GPT 模型。GPT-5.6 系列 – openai.gpt-5.6-solopenai.gpt-5.6-terraopenai.gpt-5.6-luna – 以及舊版 openai.gpt-5.4和 目前支援此功能。 openai.gpt-5.5本指南中的範例使用 openai.gpt-5.6-terra。如需 Web 搜尋定價,請參閱 Amazon Bedrock 定價頁面

注意

Web 搜尋是一種伺服器端工具,因此當您在bedrock-runtime端點上呼叫回應 API 時無法使用。若要使用它,請呼叫 上的回應 APIbedrock-mantle。如需兩個端點的其他差異,請參閱 在 bedrock-runtime 端點上使用 Responses API

區域可用性

Web 搜尋會處理三個美國區域中的查詢:

區域 區域碼
美國東部 (維吉尼亞北部) us-east-1
美國東部 (俄亥俄) us-east-2
美國西部 (奧勒岡) us-west-2

Web 搜尋是嚴格區域性的。每個區域都會操作自己的搜尋和擷取層,而查詢、擷取、索引資料和結果不會跨區域路由。在指定區域中發出的查詢會保持在該區域的邊界內。

若要使用 Web 搜尋,必須允許請求後方的 IAM 身分呼叫 Web 搜尋動作。如需必要的許可和範例政策,請參閱 Web 搜尋的身分和存取管理

設定您的環境

在執行範例之前,請先設定下列項目:

export OPENAI_API_KEY="your-amazon-bedrock-api-key" export OPENAI_BASE_URL="https://bedrock-mantle.us-west-2.api.aws/openai/v1"

將 Web 搜尋工具新增至請求

若要啟用 Web 搜尋,請在請求中將 類型的工具web_search新增至tools陣列。模型只會在判斷請求需要目前資訊時使用工具。如需可執行的範例,請參閱 代碼範例

控制外部 Web 存取

根據預設,Web 搜尋完全從 Amazon Bedrock Web 索引和快取提供,沒有請求資料離開 AWS 界限進行擷取。搜尋和擷取是否可能到達外部 Web 是由兩個共同運作的控制項所管理:回應 API 中的 external_web_access 參數和 bedrock-websearch:ExternalWebAccess IAM 許可。

external_web_access 參數預設為 true,符合 OpenAI Responses API,因此您的呼叫不需要變更。AmazonBedrockFullAccess 政策會授予基本 Web 搜尋動作 - bedrock-websearch:InvokeSearchbedrock-websearch:InvokeFetch- 但不授予 bedrock-websearch:ExternalWebAccess。因此,external_web_accesstrue從未保留 的身分離開 的請求會在授權檢查403 AccessDeniedExternalWebAccess傳回 。模型不會使請求失敗:它會基於其在搜尋和快取擷取中的答案,並報告其無法取得外部 Web 存取。

若要提出未命中此錯誤的請求,請使用下列兩種方法之一。

將請求保留在 AWS 邊界內

在工具"external_web_access": false上設定 。這不需要 ExternalWebAccess許可,完全從 Amazon Bedrock Web 索引和快取提供擷取,而且您的請求資料不會離開 AWS 界限。由於 AmazonBedrockFullAccess 不會授予 ExternalWebAccess,因此根據預設,此組態是安全的。

response = client.responses.create( model="openai.gpt-5.6-terra", input="Summarize recent guidance on AWS Lambda cold starts.", tools=[{"type": "web_search", "external_web_access": False}], )
curl "https://bedrock-mantle.us-west-2.api.aws/openai/v1/responses" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai.gpt-5.6-terra", "input": "Summarize recent guidance on AWS Lambda cold starts.", "tools": [{"type": "web_search", "external_web_access": false}] }'

啟用外部 Web 存取

bedrock-websearch:ExternalWebAccess 授予請求身分,並external_web_access保留其預設值為 true。此組態會控管搜尋和擷取是否可能連線到外部 Web。今天,完全從 Amazon Bedrock Web 索引和快取提供擷取,因此即使授與此許可,也不會有請求資料離開 AWS 界限。在未來的版本中,此組態可能會允許搜尋和擷取從即時外部 Web 擷取內容,此時請求資料可能會離開 AWS 界限。外部 Web 存取預設為停用 bedrock-websearch:ExternalWebAccess (即不允許),任何未來的變更都需要允許 bedrock-websearch:ExternalWebAccess 做為明確選擇加入,才能生效。外部 Web 存取仍由您控制:它僅適用於因為您授予 許可並啟用 參數。

代碼範例

回應 API

from openai import OpenAI client = OpenAI() response = client.responses.create( model="openai.gpt-5.6-terra", input="What are the most significant AWS launches announced this month?", tools=[{"type": "web_search", "external_web_access": False}], ) print(response.output_text)

回應包含基本答案文字,以及指向來源的url_citation註釋:

{ "content": [ { "annotations": [ { "end_index": 573, "start_index": 441, "title": "Upgrade Amazon EKS clusters with confidence using Kubernetes version rollbacks | AWS News Blog", "type": "url_citation", "url": "https://aws.amazon.com/blogs/aws/upgrade-amazon-eks-clusters-with-confidence-using-kubernetes-version-rollbacks/" }, { "end_index": 1094, "start_index": 888, "title": "AWS Weekly Roundup: AWS Builder Center at 1 year, Network Scanning in Security Hub, Loom for AWS, and more (July 13, 2026) | AWS News Blog", "type": "url_citation", "url": "https://aws.amazon.com/blogs/aws/aws-weekly-roundup-aws-builder-center-at-one-year-network-scanning-in-security-hub-loom-for-aws-and-more-july-13-2026/" }, { "end_index": 1837, "start_index": 1414, "title": "AWS Weekly Roundup: One-click Lambda setup prompt, OpenAI GPT-5.6 models on Bedrock, and more (July 20, 2026) | AWS News Blog", "type": "url_citation", "url": "https://aws.amazon.com/blogs/aws/aws-weekly-roundup-one-click-lambda-setup-prompt-openai-gpt-5-6-models-on-bedrock-and-more-july-20-2026/" } ], "logprobs": [], "text": "As of **July 30, 2026**, the most significant AWS launches this month:\n\n1. **Amazon EKS Kubernetes version rollbacks** — EKS now lets admins roll back a Kubernetes version upgrade within **seven days**, effectively adding an “undo” path for cluster upgrades and reducing upgrade risk for large or regulated Kubernetes fleets. It’s available at no additional cost in commercial Regions where EKS is available. ([aws.amazon.com](https://aws.amazon.com/blogs/aws/upgrade-amazon-eks-clusters-with-confidence-using-kubernetes-version-rollbacks/))\n\n2. **AWS Security Hub Network Scanning + Azure support** — Security Hub added active Network Scanning to find resources actually reachable from the public internet, and also expanded unified security management to **Microsoft Azure** resources, making this a notable multi-cloud security/posture-management move. ([aws.amazon.com](https://aws.amazon.com/blogs/aws/aws-weekly-roundup-aws-builder-center-at-one-year-network-scanning-in-security-hub-loom-for-aws-and-more-july-13-2026/))\n\n3. **New frontier models on Amazon Bedrock: Claude Sonnet 5, Claude Opus 5, and OpenAI GPT-5.6 models** — AWS added major new model choices to Bedrock this month: Anthropic’s Claude Sonnet 5 and Claude Opus 5, plus OpenAI GPT-5.6 Sol, Terra, and Luna, expanding Bedrock’s role as a multi-model enterprise AI platform. ([aws.amazon.com](https://aws.amazon.com/blogs/aws/aws-weekly-roundup-one-click-lambda-setup-prompt-openai-gpt-5-6-models-on-bedrock-and-more-july-20-2026/))", "type": "output_text" } ], "id": "msg_dcda8e4b477f5a1d96bfbcadefef7a77", "phase": "final_answer", "role": "assistant", "status": "completed", "type": "message" }

直接 HTTPS 請求

如果您不是使用 OpenAI 開發套件,請直接將請求傳送到回應端點。tools 欄位會攜帶 Web 搜尋工具。

curl "https://bedrock-mantle.us-west-2.api.aws/openai/v1/responses" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai.gpt-5.6-terra", "input": "What are the most significant AWS launches announced this month?", "tools": [{"type": "web_search", "external_web_access": false}] }'

從回應讀取引文

Web 搜尋會以附加至文字的url_citation註釋傳回引文。每個註釋都有來源標題和 URL,以及其支援的答案中的字元跨度。保留這些項目並顯示給最終使用者。

from openai import OpenAI client = OpenAI() response = client.responses.create( model="openai.gpt-5.6-terra", input="What are the most significant AWS launches announced this month?", tools=[{"type": "web_search", "external_web_access": False}], ) # The grounded answer print(response.output_text) # The sources behind it for item in response.output: if item.type == "message": for block in item.content: if block.type == "output_text": for ann in block.annotations: if ann.type == "url_citation": print(f"- {ann.title}: {ann.url}")

如果您使用原始 JSON (例如,從直接 HTTPS 呼叫),則相同的資料存在於 output[].content[].annotations[]

jq '.output[] | select(.type=="message") | .content[] | select(.type=="output_text") | .annotations[] | select(.type=="url_citation") | {title, url, start_index, end_index}' response.json

串流回應

Responses API 會在答案產生時將其串流。文字會以response.output_text.delta事件的形式抵達,而每個引文會以response.output_text.annotation.added事件的形式抵達,因為模型會建立陳述式。

from openai import OpenAI client = OpenAI() stream = client.responses.create( model="openai.gpt-5.6-terra", input="What are the most significant AWS launches announced this month?", tools=[{"type": "web_search", "external_web_access": False}], stream=True, ) for event in stream: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True) elif event.type == "response.output_text.annotation.added": ann = event.annotation print(f"\n[source] {ann['title']}: {ann['url']}")

透過線路,註釋事件如下所示:

event: response.output_text.annotation.added data: {"type":"response.output_text.annotation.added","annotation":{"type":"url_citation","title":"News and Updates from the July 2025 Pokémon Presents","url":"https://www.pokemon.com/us/pokemon-news/...","start_index":589,"end_index":698},"annotation_index":2,"content_index":0,"item_id":"msg_...","output_index":1}

安全

Amazon Bedrock 上的 Web 搜尋使用 AWS Identity and Access Management (IAM) 來控制誰可以執行搜尋和擷取以及哪些區域。Web 搜尋的 IAM 服務字首為 bedrock-websearch。如需停用 Web 搜尋的動作、受管政策、條件金鑰、範例政策和管理員控制項的完整清單,請參閱 Web 搜尋的身分和存取管理

使用 CloudTrail 進行監控

Amazon Bedrock 上的 Web 搜尋已與 整合 AWS CloudTrail。CloudTrail 會將 Web 搜尋的 API 活動擷取為資料事件,因此您可以稽核叫用工具的人員、時間和位置。如需擷取的欄位、如何啟用資料事件記錄,以及刻意排除的內容,請參閱監控 Web 搜尋

可接受的使用方式

如果您在 Amazon Bedrock 上使用 Web 搜尋,Amazon Bedrock 會將 Web 搜尋結果 (「搜尋結果」) 提供給支援的模型,該模型可能會用來產生其回應。您對包含搜尋結果的模型輸出的使用和最終使用者的任何使用負責。您必須保留並在您向最終使用者呈現的任何輸出中,顯示模型輸出中提供的來源引文和連結。您無法使用 Web 搜尋來 (a) 從搜尋結果大量擷取、儲存或重現內容,或 (b) 建置或填入競爭索引或資料庫。