ウェブ検索を使うと、モデルはインターネット上の最新情報にアクセスし、出典の引用を添えて回答できます。有効にするには、Responses API のウェブ検索ツールを使用します。場合によっては、Chat Completions でも使用できます。
OpenAI のモデルで利用できるウェブ検索には、主に次の 3 種類があります。
推論を伴わないウェブ検索:推論を行わないモデルがユーザーのクエリをウェブ検索ツールに送り、ツールが上位の検索結果に基づいて応答を返します。内部で計画を立てることはなく、モデルは検索ツールの応答をそのまま伝えます。この方式は高速で、簡単な調べ物に適しています。
リーズニングモデルによるエージェント型検索は、モデルが検索プロセスを主体的に管理する方式です。思考の連鎖の一環としてウェブ検索を実行し、結果を分析して、検索を続けるかどうかを判断できます。この柔軟性により複雑なワークフローに適していますが、簡単な調べ物よりも検索に時間がかかります。たとえば、gpt-5.5 などのモデルでは推論レベルを調整することで、検索の深さとレイテンシの両方を変えられます。
deep research は、リーズニングモデルが時間をかけて深く調査するための、エージェント主導の専門的な方式です。モデルは思考の連鎖の一環としてウェブ検索を行い、多くの場合、数百もの情報源を参照します。deep research は実行に数分かかることがあるため、バックグラウンドモードでの使用が適しています。gpt-5.5 を使用し、推論を high または xhigh に設定してください。
ユースケース 推奨される方法 補足 ウェブ検索の新規連携 web_search と gpt-5.5 を使用する Responses APIフィルター、情報源、ライブアクセス制御、長時間の調査など、ホスト型ウェブ検索の各種制御に対応 既存の Chat Completions 検索連携 gpt-5-search-api を使用する Chat CompletionsChat Completions との連携を維持する必要がある場合にのみ使用 複数ステップの調査や長時間かかるレポート作成 推論を high または xhigh に設定した gpt-5.5 作成に数分かかる可能性があるレポートにはバックグラウンドモードを使用
Responses API では、コンテンツ生成用の API リクエストの tools 配列でウェブ検索を設定すると、有効にできます。他のツールと同様、モデルは入力プロンプトの内容に基づいて、ウェブを検索するかどうかを選択できます。
Responses API との新規連携には、{ "type": "web_search" } を使用してください。従来の web_search_preview ツールも既存の連携向けに引き続き利用できますが、filters、external_web_access、return_token_budget などの新しい制御には対応していません。
1
2
3
4
5
6
7
8
9
10 import OpenAI from "openai" ;
const client = new OpenAI ();
const response = await client.responses. create ({
model: "gpt-6-astra" ,
tools: [{ type: "web_search" }],
input: "What was a positive news story from today?" ,
});
console. log (response.output_text); 1
2
3
4
5
6
7
8
9
10
11 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
tools=[{"type": "web_search"}],
input="What was a positive news story from today?",
)
print(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{
responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch),
},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What was a positive news story from today?")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.WebSearchTool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("What was a positive news story from today?")
.addTool(WebSearchTool.builder().type(WebSearchTool.Type.WEB_SEARCH).build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(ResponseTool.CreateWebSearchTool());
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("What was a positive news story from today?")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11 require "openai"
openai = OpenAI::Client.new
response = openai.responses.create(
model: "gpt-6-astra",
tools: [{ type: "web_search" }],
input: "What was a positive news story from today?"
)
puts(response.output_text) 1
2
3
4
5
6
7
8 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"tools": [{"type": "web_search"}],
"input": "what was a positive news story from today?"
}' 1
2
3
4
5
6
7
8 openai responses create \
--model gpt-6-astra \
--raw-output \
--transform 'output.#(type=="message").content.0.text' <<'YAML'
tools:
- type: web_search
input: What was a positive news story from today?
YAML ウェブ検索ツールを使用したモデルの応答には、次の 2 つの部分が含まれます。
検索呼び出しの ID を含む web_search_call 出力項目。実行されたアクションは web_search_call.action に格納されます。アクションは次のいずれかです。
search はウェブ検索を表します。通常は検索に使用した queries が含まれますが、含まれない場合もあります。検索アクションにはツール呼び出しの料金が発生します(料金 を参照)。
open_page はページを開く操作を表します。リーズニングモデルでサポートされています。
find_in_page はページ内の検索を表します。リーズニングモデルでサポートされています。
次の内容を含む message 出力項目:
message.content[0].text に格納されたテキスト結果
引用された URL のアノテーション message.content[0].annotations
デフォルトでは、モデルの応答に、ウェブ検索結果で見つかった URL へのインライン引用が含まれます。また、url_citation アノテーションオブジェクトには、引用元の URL、タイトル、引用位置が含まれます。
ウェブ検索結果やその中の情報をエンドユーザーに表示する場合、ユーザーインターフェース上でインライン引用を見やすく、クリックできる形で表示する必要があります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 [
{
"type" : "web_search_call" ,
"id" : "ws_67c9fa0502748190b7dd390736892e100be649c1a5ff9609" ,
"status" : "completed" ,
"action" : {
"type" : "search" ,
"query" : "latest news about AI"
}
},
{
"id" : "msg_67c9fa077e288190af08fdffda2e34f20be649c1a5ff9609" ,
"type" : "message" ,
"status" : "completed" ,
"role" : "assistant" ,
"content" : [
{
"type" : "output_text" ,
"text" : "On March 6, 2025, several news..." ,
"annotations" : [
{
"type" : "url_citation" ,
"start_index" : 2606 ,
"end_index" : 2758 ,
"url" : "https://..." ,
"title" : "Title..."
}
]
}
]
}
]
Chat Completions API を使うと、ChatGPT の検索 で使用されているファインチューニング済みのモデルとツールに直接アクセスできます。
Chat Completions を使用する場合、モデルはクエリに応答する前に必ずウェブから情報を取得します。検索するかどうかをモデルに判断させるには、web_search ツールを使用する Responses API に切り替えてください。
現在、Chat Completions でのウェブ検索には、次のモデルを使用してください。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import OpenAI from "openai" ;
const client = new OpenAI ();
const completion = await client.chat.completions. create ({
model: "gpt-5-search-api" ,
web_search_options: {},
messages: [
{
role: "user" ,
content: "What was a positive news story from today?" ,
},
],
});
console. log (completion.choices[ 0 ].message.content); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-5-search-api",
web_search_options={},
messages=[
{
"role": "user",
"content": "What was a positive news story from today?",
}
],
)
print(completion.choices[0].message.content) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
func main() {
client := openai.NewClient()
completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Model: "gpt-5-search-api",
WebSearchOptions: openai.ChatCompletionNewParamsWebSearchOptions{},
Messages: []openai.ChatCompletionMessageParamUnion{
openai.UserMessage("What was a positive news story from today?"),
},
})
if err != nil {
panic(err)
}
fmt.Println(completion.Choices[0].Message.Content)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
ChatCompletionCreateParams params =
ChatCompletionCreateParams.builder()
.model("gpt-5-search-api")
.addUserMessage("What was a positive news story today?")
.webSearchOptions(ChatCompletionCreateParams.WebSearchOptions.builder().build())
.build();
client.chat().completions().create(params).choices().stream()
.flatMap(choice -> choice.message().content().stream())
.forEach(System.out::println); 1
2
3
4
5
6
7
8
9
10
11
12
13 using OpenAI.Chat;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string model = "gpt-5-search-api";
ChatClient client = new(model, key);
ChatCompletion completion = await client.CompleteChatAsync(
[new UserChatMessage("What was a positive news story today?")],
new ChatCompletionOptions { WebSearchOptions = new() }
);
Console.WriteLine(completion.Content[0].Text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 require "openai"
client = OpenAI::Client.new
completion = client.chat.completions.create(
model: "gpt-5-search-api",
messages: [
{
role: :user,
content: "What was a positive news story today?"
}
],
web_search_options: {}
)
puts(completion.choices.fetch(0).message.content) 1
2
3
4
5
6
7
8
9
10
11 curl -X POST "https://api.openai.com/v1/chat/completions" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-type: application/json" \
-d '{
"model": "gpt-5-search-api",
"web_search_options": {},
"messages": [{
"role": "user",
"content": "What was a positive news story from today?"
}]
}' choices 配列内の API 応答項目には、次の内容が含まれます。
インライン引用を含むモデルのテキスト結果が格納された message.content
引用された URL のリストが格納された annotations
デフォルトでは、モデルの応答に、ウェブ検索結果で見つかった URL へのインライン引用が含まれます。また、url_citation アノテーションオブジェクトには、引用元の URL とタイトルに加え、モデルの応答内でその情報源が使用された箇所の開始位置と終了位置を示す文字インデックスが含まれます。
ウェブ検索結果やその中の情報をエンドユーザーに表示する場合、ユーザーインターフェース上でインライン引用を見やすく、クリックできる形で表示する必要があります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [
{
"index" : 0 ,
"message" : {
"role" : "assistant" ,
"content" : "the model response is here..." ,
"refusal" : null ,
"annotations" : [
{
"type" : "url_citation" ,
"url_citation" : {
"end_index" : 985 ,
"start_index" : 764 ,
"title" : "Page title..." ,
"url" : "https://..."
}
}
]
},
"finish_reason" : "stop"
}
]
現在の利用方式 推奨される方法 補足 Responses の web_search_preview web_search への移行web_search は filters、external_web_access、return_token_budget などの新しい制御に対応gpt-4o-search-preview または gpt-4o-mini-search-previewResponses の web_search に移行、または Chat Completions を使い続ける必要がある場合は gpt-5-search-api を使用 プレビュー版の検索モデルは非推奨で、2026-07-23 に提供終了 Chat Completions の検索連携 gpt-5-search-api を使用、またはツール制御を増やし、検索を任意にするには Responses の web_search に移行Chat Completions の検索モデルは応答前に必ず検索を実行し、Responses では検索をツールとして提供
検索コンテキストのサイズ
search_context_size は、モデルが応答を生成する前に利用できるウェブ検索結果のコンテキスト量を制御します。簡単な調べ物には low、バランスの取れたデフォルト設定には medium、回答に検索結果のより詳しい情報が必要になりそうな場合には high を使用してください。この設定は、トークン数を厳密に指定するものではなく、情報源や引用の数を保証するものでもありません。
1
2
3
4
5
6
7
8
9
10
11
12
13
14 import OpenAI from "openai" ;
const openai = new OpenAI ();
const response = await openai.responses. create ({
model: "gpt-6-astra" ,
tools: [
{
type: "web_search" ,
search_context_size: "low" ,
},
],
input: "What movie won best picture in 2025?" ,
});
console. log (response.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
tools=[
{
"type": "web_search",
"search_context_size": "low",
}
],
input="What movie won best picture in 2025?",
)
print(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch)
tool.OfWebSearch.SearchContextSize = responses.WebSearchToolSearchContextSizeLow
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What movie won best picture in 2025?")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.WebSearchTool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("What movie won best picture in 2025?")
.addTool(
WebSearchTool.builder()
.type(WebSearchTool.Type.WEB_SEARCH)
.searchContextSize(WebSearchTool.SearchContextSize.LOW)
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateWebSearchTool(
searchContextSize: WebSearchToolContextSize.Low
)
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("What movie won best picture in 2025?")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
input: "What movie won best picture in 2025?",
tools: [
{
type: :web_search,
search_context_size: :low
}
]
)
puts(response.output_text) 1
2
3
4
5
6
7
8
9
10
11 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"tools": [{
"type": "web_search",
"search_context_size": "low"
}],
"input": "What movie won best picture in 2025?"
}'
return_token_budget は、GPT-5+ のリーズニングモデルを使って Responses API で検索を実行する際に、ツールが返せるウェブ検索結果のコンテンツ量を制御します。ほとんどのリクエストではデフォルトのままにしてください。多数のページを調べる必要があり、標準の返却トークン数の上限では途中で停止する可能性がある、入念な調査や評価を実行する場合にのみ、unlimited に設定してください。
unlimited はレイテンシやコストを増加させる可能性があるため、必要な場合に限って使用してください。複数の検索を行う長時間実行のタスクでは、バックグラウンドモード(background: true)を使用すると、リクエストの処理を非同期で継続し、後から最終的なレスポンスを取得できます。
値 動作 defaultウェブ検索結果に標準の返却トークン数の上限を適用します。return_token_budget を省略した場合と同じ動作です。 unlimitedウェブ検索の実行時に適用される、デフォルトの返却トークン数の上限を解除します。
このパラメーターは、GPT-5+ の推論を伴うウェブ検索で使用する、Responses API のホスト型 web_search ツールにのみ適用されます。検索コンテキストウィンドウは変更されません。また、推論を伴わないウェブ検索、従来の Search API の利用方式、コンテナでのウェブ検索、Chat Completions の検索モデル、web_search_preview には適用されません。サポートされる値は default と unlimited のみです。null、数値、その他の文字列は拒否されます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.create({
model: "gpt-6-astra",
reasoning: { effort: "xhigh" },
tools: [
{
type: "web_search",
return_token_budget: "unlimited",
},
],
input: [
"Research the economic impact of semaglutide on global healthcare systems.",
"",
"Do:",
"- Include specific figures, trends, statistics, and measurable outcomes.",
"- Prioritize reliable, up-to-date sources: peer-reviewed research, health organizations (e.g., WHO, CDC), regulatory agencies, or pharmaceutical earnings reports.",
"- Include inline citations and return all source metadata.",
"",
"Be analytical, avoid generalities, and ensure that each section supports data-backed reasoning that could inform healthcare policy or financial modeling.",
].join("\n"),
});
console.log(response.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
reasoning={"effort": "xhigh"},
tools=[
{
"type": "web_search",
"return_token_budget": "unlimited",
}
],
input="""Research the economic impact of semaglutide on global healthcare systems.
Do:
- Include specific figures, trends, statistics, and measurable outcomes.
- Prioritize reliable, up-to-date sources: peer-reviewed research, health organizations (e.g., WHO, CDC), regulatory agencies, or pharmaceutical earnings reports.
- Include inline citations and return all source metadata.
Be analytical, avoid generalities, and ensure that each section supports data-backed reasoning that could inform healthcare policy or financial modeling.""",
)
print(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package main
import (
"context"
"fmt"
"strings"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
"github.com/openai/openai-go/v3/shared"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch)
tool.OfWebSearch.SetExtraFields(map[string]any{"return_token_budget": "unlimited"})
input := strings.Join([]string{
"Research the economic impact of semaglutide on global healthcare systems.",
"",
"Do:",
"- Include specific figures, trends, statistics, and measurable outcomes.",
"- Prioritize reliable, up-to-date sources: peer-reviewed research, health organizations, regulatory agencies, or pharmaceutical earnings reports.",
"- Include inline citations and return all source metadata.",
"",
"Be analytical, avoid generalities, and ensure that each section supports data-backed reasoning that could inform healthcare policy or financial modeling.",
}, "\n")
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortXhigh},
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(input)},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.Reasoning;
import com.openai.models.ReasoningEffort;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.WebSearchTool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input(
"Research the economic impact of semaglutide on global healthcare systems. Include current figures and citations.")
.reasoning(Reasoning.builder().effort(ReasoningEffort.XHIGH).build())
.addTool(
WebSearchTool.builder()
.type(WebSearchTool.Type.WEB_SEARCH)
.putAdditionalProperty("return_token_budget", JsonValue.from("unlimited"))
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
input: "Research the economic impact of semaglutide on global healthcare systems. Include current figures and citations.",
reasoning: { effort: :xhigh },
tools: [
{
type: :web_search,
return_token_budget: :unlimited
}
]
)
puts(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"reasoning": { "effort": "xhigh" },
"tools": [
{
"type": "web_search",
"return_token_budget": "unlimited"
}
],
"input": "Research the economic impact of semaglutide on global healthcare systems.\n\nDo:\n- Include specific figures, trends, statistics, and measurable outcomes.\n- Prioritize reliable, up-to-date sources: peer-reviewed research, health organizations (e.g., WHO, CDC), regulatory agencies, or pharmaceutical earnings reports.\n- Include inline citations and return all source metadata.\n\nBe analytical, avoid generalities, and ensure that each section supports data-backed reasoning that could inform healthcare policy or financial modeling."
}'
ドメインによるフィルタリング
ウェブ検索のドメインフィルタリングでは、検索結果を特定のドメイン群に限定できます。filters パラメーターで、最大 100 件の allowed_domains または最大 100 件の blocked_domains を設定できます。ドメインの記述では HTTP や HTTPS のプレフィックスを省略してください。たとえば、https://openai.com/ ではなく openai.com を使用します。この指定では、サブドメインも検索対象に含まれます。ドメインフィルタリングは、Responses API の web_search ツールでのみ利用できます。
ウェブ検索中に取得したすべての URL を確認するには、sources フィールドを使用します。関連性の高い参照先のみを示すインライン引用とは異なり、sources は、モデルが回答を作成する際に参照した URL の完全なリストを返します。
情報源の数は、引用の数を上回ることがよくあります。サードパーティーのリアルタイムフィードもここに表示され、oai-sports、oai-weather、oai-finance のいずれかのラベルが付きます。sources フィールドは、web_search と web_search_preview の両方のツールで利用できます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.create({
model: "gpt-6-astra",
reasoning: { effort: "low" },
tools: [
{
type: "web_search",
filters: {
allowed_domains: [
"pubmed.ncbi.nlm.nih.gov",
"clinicaltrials.gov",
"www.who.int",
"www.cdc.gov",
"www.fda.gov",
],
blocked_domains: ["reddit.com", "quora.com", "wikipedia.org"],
},
},
],
tool_choice: "auto",
include: ["web_search_call.action.sources"],
input:
"Please perform a web search on how semaglutide is used in the treatment of diabetes.",
});
console.log(response.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
reasoning={"effort": "low"},
tools=[
{
"type": "web_search",
"filters": {
"allowed_domains": [
"pubmed.ncbi.nlm.nih.gov",
"clinicaltrials.gov",
"www.who.int",
"www.cdc.gov",
"www.fda.gov",
],
"blocked_domains": [
"reddit.com",
"quora.com",
"wikipedia.org",
],
},
}
],
tool_choice="auto",
include=["web_search_call.action.sources"],
input="Please perform a web search on how semaglutide is used in the treatment of diabetes.",
)
print(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
"github.com/openai/openai-go/v3/shared"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch)
tool.OfWebSearch.Filters = responses.WebSearchToolFiltersParam{
AllowedDomains: []string{"pubmed.ncbi.nlm.nih.gov", "clinicaltrials.gov", "www.who.int", "www.cdc.gov", "www.fda.gov"},
}
tool.OfWebSearch.Filters.SetExtraFields(map[string]any{"blocked_domains": []string{"reddit.com", "quora.com", "wikipedia.org"}})
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortLow},
Tools: []responses.ToolUnionParam{tool},
Include: []responses.ResponseIncludable{responses.ResponseIncludableWebSearchCallActionSources},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Please perform a web search on how semaglutide is used in the treatment of diabetes.")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.Reasoning;
import com.openai.models.ReasoningEffort;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.ResponseIncludable;
import com.openai.models.responses.WebSearchTool;
import java.util.List;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("Search for how semaglutide is used in the treatment of diabetes.")
.reasoning(Reasoning.builder().effort(ReasoningEffort.LOW).build())
.addInclude(ResponseIncludable.of("web_search_call.action.sources"))
.addTool(
WebSearchTool.builder()
.type(WebSearchTool.Type.WEB_SEARCH)
.filters(
WebSearchTool.Filters.builder()
.allowedDomains(
List.of(
"pubmed.ncbi.nlm.nih.gov",
"clinicaltrials.gov",
"www.who.int",
"www.cdc.gov",
"www.fda.gov"))
.putAdditionalProperty(
"blocked_domains",
JsonValue.from(List.of("reddit.com", "quora.com", "wikipedia.org")))
.build())
.build())
.build();
var response = client.responses().create(params);
response.output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text()));
response.output().stream()
.flatMap(item -> item.webSearchCall().stream())
.flatMap(call -> call.action().search().stream())
.flatMap(action -> action.sources().stream())
.flatMap(List::stream)
.forEach(source -> System.out.println(source.url())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
reasoning: { effort: :low },
input: "Search for how semaglutide is used in the treatment of diabetes.",
include: ["web_search_call.action.sources"],
tools: [
{
type: :web_search,
filters: {
allowed_domains: [
"pubmed.ncbi.nlm.nih.gov",
"clinicaltrials.gov",
"www.who.int",
"www.cdc.gov",
"www.fda.gov"
],
blocked_domains: ["reddit.com", "quora.com", "wikipedia.org"]
}
}
]
)
puts(response.output_text)
response.output
.grep(OpenAI::Models::Responses::ResponseFunctionWebSearch)
.each do |search_call|
action = search_call.action
next unless action.is_a?(
OpenAI::Models::Responses::ResponseFunctionWebSearch::Action::Search
)
Array(action.sources).each { |source| puts(source.url) }
end 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"reasoning": { "effort": "low" },
"tools": [
{
"type": "web_search",
"filters": {
"allowed_domains": [
"pubmed.ncbi.nlm.nih.gov",
"clinicaltrials.gov",
"www.who.int",
"www.cdc.gov",
"www.fda.gov"
],
"blocked_domains": [
"reddit.com",
"quora.com",
"wikipedia.org"
]
}
}
],
"tool_choice": "auto",
"include": ["web_search_call.action.sources"],
"input": "Please perform a web search on how semaglutide is used in the treatment of diabetes."
}'
ウェブ検索では、通常のテキスト結果に加えて画像の結果も返せます。商品の写真、ランドマーク、場所、イベント、参考画像など、最新の画像やウェブ上の情報に基づく画像がアプリケーションで必要な場合は、画像検索を使用してください。
画像検索を使用するには、search_content_types に image を含めます。取得した画像の要約、順位付け、説明に役立つ補足的なテキスト結果も必要な場合は、text を追加してください。
画像固有の動作は、image_settings で制御します。
max_results:取得する画像結果の件数を正の数で指定します。
caption:利用可能な場合に画像の短い説明を取得するよう指定します。
画像検索の生の結果を確認するには、リクエストに web_search_call.results を含め、レスポンスの web_search_call.results[] を読み取ります。画像の結果はアシスタントのメッセージとは別に返されるため、アプリケーションで URL やメタデータが必要な場合は、web_search_call 項目を直接解析してください。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import OpenAI from "openai" ;
const client = new OpenAI ();
const response = await client.responses. create ({
model: "gpt-6-astra" ,
reasoning: { effort: "low" },
tools: [
{
type: "web_search" ,
search_content_types: [ "image" , "text" ],
image_settings: {
max_results: 3 ,
caption: true ,
},
},
],
include: [ "web_search_call.results" ],
input:
"Search for recent images and supporting text sources about the Golden Gate Bridge at sunset." ,
});
console. log (response.output); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
reasoning={"effort": "low"},
tools=[
{
"type": "web_search",
"search_content_types": ["image", "text"],
"image_settings": {
"max_results": 3,
"caption": True,
},
}
],
include=["web_search_call.results"],
input="Search for recent images and supporting text sources about the Golden Gate Bridge at sunset.",
)
print(response.output) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
"github.com/openai/openai-go/v3/shared"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch)
tool.OfWebSearch.SetExtraFields(map[string]any{
"search_content_types": []string{"image", "text"},
"image_settings": map[string]any{"max_results": 3, "caption": true},
})
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortLow},
Tools: []responses.ToolUnionParam{tool},
Include: []responses.ResponseIncludable{responses.ResponseIncludableWebSearchCallResults},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Search for recent images and supporting text sources about the Golden Gate Bridge at sunset.")},
})
if err != nil {
panic(err)
}
fmt.Println(response.Output)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.Reasoning;
import com.openai.models.ReasoningEffort;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.ResponseIncludable;
import com.openai.models.responses.WebSearchTool;
import java.util.List;
import java.util.Map;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input(
"Search for recent images and supporting text sources about the Golden Gate Bridge at sunset.")
.reasoning(Reasoning.builder().effort(ReasoningEffort.LOW).build())
.addInclude(ResponseIncludable.of("web_search_call.results"))
.addTool(
WebSearchTool.builder()
.type(WebSearchTool.Type.WEB_SEARCH)
.putAdditionalProperty(
"search_content_types", JsonValue.from(List.of("image", "text")))
.putAdditionalProperty(
"image_settings", JsonValue.from(Map.of("max_results", 3, "caption", true)))
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.webSearchCall().stream())
.map(call -> call._additionalProperties().get("results"))
.filter(java.util.Objects::nonNull)
.forEach(System.out::println); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
reasoning: { effort: :low },
input: "Search for recent images and supporting text sources about the Golden Gate Bridge at sunset.",
include: ["web_search_call.results"],
tools: [
{
type: :web_search,
search_content_types: ["image", "text"],
image_settings: {
max_results: 3,
caption: true
}
}
]
)
puts(response.output) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"reasoning": { "effort": "low" },
"tools": [
{
"type": "web_search",
"search_content_types": ["image", "text"],
"image_settings": {
"max_results": 3,
"caption": true
}
}
],
"include": ["web_search_call.results"],
"input": "Search for recent images and supporting text sources about the Golden Gate Bridge at sunset."
}' 各 image_result には、次の情報が含まれます。
image_url:検索結果の画像の正規 URL
source_website_url:画像が見つかったページ
thumbnail_url:サムネイルの URL(利用可能な場合)
caption:短いキャプションまたは説明(利用可能な場合)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 {
"output" : [
{
"type" : "web_search_call" ,
"status" : "completed" ,
"results" : [
{
"type" : "image_result" ,
"image_url" : "https://cdn.example/golden-gate-sunset.jpg" ,
"thumbnail_url" : "https://cdn.example/golden-gate-sunset-thumb.jpg" ,
"source_website_url" : "https://example.com/source-page" ,
"caption" : "Golden Gate Bridge at sunset"
}
]
}
]
}
地域に応じて検索結果を絞り込むには、国、都市、地域、タイムゾーンのいずれか、またはそれらの組み合わせで、ユーザーのおおよその位置を指定できます。
city と region は自由形式の文字列フィールドです。たとえば、それぞれに Minneapolis と Minnesota を指定します。
country フィールドには、US のような 2 文字の ISO 国コード を指定します。
timezone フィールドには、America/Chicago のような IANA タイムゾーン を指定します。
ウェブ検索を使用する deep research モデルでは、ユーザーの位置情報はサポートされていません。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import OpenAI from "openai" ;
const openai = new OpenAI ();
const response = await openai.responses. create ({
model: "gpt-6-astra" ,
tools: [
{
type: "web_search" ,
user_location: {
type: "approximate" ,
country: "GB" ,
city: "London" ,
region: "London" ,
},
},
],
input: "What are the best restaurants near me?" ,
});
console. log (response.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
tools=[
{
"type": "web_search",
"user_location": {
"type": "approximate",
"country": "GB",
"city": "London",
"region": "London",
},
}
],
input="What are the best restaurants near me?",
)
print(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch)
tool.OfWebSearch.UserLocation = responses.WebSearchToolUserLocationParam{
Type: "approximate",
Country: openai.String("GB"),
City: openai.String("London"),
Region: openai.String("London"),
}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What are the best restaurants near me?")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.WebSearchTool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("What are the best restaurants near me?")
.addTool(
WebSearchTool.builder()
.type(WebSearchTool.Type.WEB_SEARCH)
.userLocation(
WebSearchTool.UserLocation.builder()
.type(WebSearchTool.UserLocation.Type.APPROXIMATE)
.city("London")
.country("GB")
.region("London")
.build())
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateWebSearchTool(
userLocation: WebSearchToolLocation.CreateApproximateLocation(
country: "GB",
city: "London",
region: "London"
)
)
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("What are the best restaurants near me?")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
input: "What are the best restaurants near me?",
tools: [
{
type: :web_search,
user_location: {
type: :approximate,
country: "GB",
city: "London",
region: "London"
}
}
]
)
puts(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"tools": [{
"type": "web_search",
"user_location": {
"type": "approximate",
"country": "GB",
"city": "London",
"region": "London"
}
}],
"input": "What are the best restaurants near me?"
}'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import OpenAI from "openai" ;
const client = new OpenAI ();
const completion = await client.chat.completions. create ({
model: "gpt-5-search-api" ,
web_search_options: {
user_location: {
type: "approximate" ,
approximate: {
country: "GB" ,
city: "London" ,
region: "London" ,
},
},
},
messages: [
{
role: "user" ,
content: "What are the best restaurants near me?" ,
},
],
});
console. log (completion.choices[ 0 ].message.content); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-5-search-api",
web_search_options={
"user_location": {
"type": "approximate",
"approximate": {
"country": "GB",
"city": "London",
"region": "London",
},
},
},
messages=[
{
"role": "user",
"content": "What are the best restaurants near me?",
}
],
)
print(completion.choices[0].message.content) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
)
func main() {
client := openai.NewClient()
completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
Model: "gpt-5-search-api",
WebSearchOptions: openai.ChatCompletionNewParamsWebSearchOptions{
UserLocation: openai.ChatCompletionNewParamsWebSearchOptionsUserLocation{
Approximate: openai.ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate{
Country: openai.String("GB"),
City: openai.String("London"),
Region: openai.String("London"),
},
},
},
Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("What are the best restaurants near me?")},
})
if err != nil {
panic(err)
}
fmt.Println(completion.Choices[0].Message.Content)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
ChatCompletionCreateParams params =
ChatCompletionCreateParams.builder()
.model("gpt-5-search-api")
.addUserMessage("What are the best restaurants near me?")
.webSearchOptions(
ChatCompletionCreateParams.WebSearchOptions.builder()
.userLocation(
ChatCompletionCreateParams.WebSearchOptions.UserLocation.builder()
.approximate(
ChatCompletionCreateParams.WebSearchOptions.UserLocation.Approximate
.builder()
.country("GB")
.city("London")
.region("London")
.build())
.build())
.build())
.build();
client.chat().completions().create(params).choices().stream()
.flatMap(choice -> choice.message().content().stream())
.forEach(System.out::println); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 require "openai"
client = OpenAI::Client.new
completion = client.chat.completions.create(
model: "gpt-5-search-api",
messages: [
{
role: :user,
content: "What are the best restaurants near me?"
}
],
web_search_options: {
user_location: {
type: :approximate,
approximate: {
country: "GB",
city: "London",
region: "London"
}
}
}
)
puts(completion.choices.fetch(0).message.content) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 curl -X POST "https://api.openai.com/v1/chat/completions" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-type: application/json" \
-d '{
"model": "gpt-5-search-api",
"web_search_options": {
"user_location": {
"type": "approximate",
"approximate": {
"country": "GB",
"city": "London",
"region": "London"
}
}
},
"messages": [{
"role": "user",
"content": "What are the best restaurants near me?"
}]
}'
Responses API のウェブ検索ツールが、コンテンツをリアルタイムに取得するか、キャッシュ済みまたはインデックス済みの結果のみを使用するかを制御します。
web_search ツールに external_web_access: false を設定すると、オフラインでキャッシュのみを使用するモードで実行できます。
設定しない場合、デフォルトは true(リアルタイムアクセス)です。
プレビュー版(web_search_preview)はこのパラメーターを無視し、external_web_access が true に設定されている場合と同じように動作します。
1
2
3
4
5
6
7
8
9
10
11 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"tools": [
{ "type": "web_search", "external_web_access": false }
],
"tool_choice": "auto",
"input": "Find when the Eiffel Tower opened to the public and cite the source."
}' 1
2
3
4
5
6
7
8
9
10
11 import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.create({
model: "gpt-6-astra",
tools: [{ type: "web_search", external_web_access: false }],
tool_choice: "auto",
input: "Find when the Eiffel Tower opened to the public and cite the source.",
});
console.log(response.output_text); 1
2
3
4
5
6
7
8
9
10
11 from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-6-astra",
tools=[{"type": "web_search", "external_web_access": False}],
tool_choice="auto",
input="Find when the Eiffel Tower opened to the public and cite the source.",
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch)
tool.OfWebSearch.SetExtraFields(map[string]any{"external_web_access": false})
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Find when the Eiffel Tower opened to the public and cite the source.")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.WebSearchTool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("Find when the Eiffel Tower opened to the public and cite the source.")
.addTool(
WebSearchTool.builder()
.type(WebSearchTool.Type.WEB_SEARCH)
.putAdditionalProperty("external_web_access", JsonValue.from(false))
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
input: "Find when the Eiffel Tower opened to the public and cite the source.",
tools: [
{
type: :web_search,
external_web_access: false
}
]
)
puts(response.output_text)
Chat Completions API でウェブ検索を利用できるのは、検索専用モデルのみです。これらのモデルは、ドメインフィルター、情報源の完全なリスト、リアルタイムアクセスの制御、返却トークン数の上限の制御など、Responses API の web_search の機能をサポートしていません。
モデル コンテキストウィンドウ 制限事項 gpt-5-search-api200k Chat Completions の検索モデルを使用する方式 gpt-4o-search-preview128k Chat Completions の検索モデルを使用。非推奨、2026-07-23 に提供終了 gpt-4o-mini-search-preview128k Chat Completions の検索モデルを使用。非推奨、2026-07-23 に提供終了
ホスト型の web_search ツールを使用してください。Responses API は既存の連携向けに引き続き web_search_preview を受け付けますが、新しい連携には web_search を使用してください。
モデルのコンテキストウィンドウをより大きくしたい場合は、gpt-5.5 を使用してください。ウェブ検索のコンテキストウィンドウは 128k のままです。
モデル モデルのコンテキストウィンドウ 制限事項 gpt-4.11M 検索コンテキストの上限は 128k gpt-4.1-mini1M 検索コンテキストの上限は 128k o4-mini200k 検索コンテキストの上限は 128k。非推奨、2026-10-23 に提供終了
Responses API のウェブ検索では、モデルのコンテキストウィンドウがより大きい場合でも、検索コンテキストウィンドウの上限は 128k です。
ウェブ検索は、推論強度が minimal の gpt-5 には対応していません。
gpt-5.4 の推論強度を none に設定すると、結果の品質が低下する場合があります。
Responses API のウェブ検索には、使用するモデルのティア別レート制限が適用されます。
web_search_preview は filters と return_token_budget に対応しておらず、external_web_access は無視されます。
tool_choice: "auto" では、検索は必須ではありません。必ず検索を実行する必要がある場合は、tool_choice: "required" を使用するか、使用するツールとしてウェブ検索を明示的に指定してください。