大規模言語モデル(LLM)は静的データセットで学習されるため、株価や明日の天気などリアルタイムの情報を正確に回答できません。Web検索機能を有効化すると、モデルはWeb上から最新の情報を取得・統合し、その結果に基づいて応答します。
利用方法
Web検索機能は3種類の呼び出し方式をサポートしており、それぞれ異なるパラメーターで有効化します。
OpenAI 互換 — Responses API
Web検索機能を有効化するには、web_search ツールを tools パラメーターに追加します。
Responses API では、Qwen3.5、qwen3-max、qwen3-max-2026-01-23 のみがサポートされます。
最適な応答を得るためには、web_search、web_extractor、code_interpreterの各ツールを同時に有効化してください。
# 依存関係をインポートし、クライアントを作成...
response = client.responses.create(
model="qwen3-max-2026-01-23",
input="杭州の天気",
tools=[
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
extra_body={"enable_thinking": True}
)OpenAI 互換 — Chat Completions API
Web検索を有効化するには、enable_search: true パラメーターを渡します。
# 依存関係をインポートし、クライアントを作成...
completion = client.chat.completions.create(
# Web検索をサポートするモデルを使用
model="qwen3-max",
messages=[{"role": "user", "content": "明日の杭州の天気はどうなりますか?"}],
# enable_search は OpenAI 標準パラメーターではないため、Python SDK では extra_body を使用(Node.js SDK ではトップレベルパラメーターを使用)
extra_body={"enable_search": True}
)DashScope
Web検索を有効化するには、enable_search: true パラメーターを渡します。
# 依存関係をインポート...
response = dashscope.Generation.call(
# 環境変数を設定していない場合は、以下の行を Model Studio API キーに置き換えます:api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Web検索をサポートするモデルを使用
model="qwen3-max",
messages=[{"role": "user", "content": "明日の杭州の天気はどうなりますか?"}],
# enable_search パラメーターでWeb検索を有効化
enable_search=True,
result_format="message"
)サポート対象モデル
国際版
Qwen Plus:qwen3.5-plus、qwen3.5-plus-2026-02-15 以降のスナップショット
思考モードおよび非思考モードの両方で、
agentおよびagent_maxの検索戦略がサポートされます。Qwen Flash:qwen3.5-flash、qwen3.5-flash-2026-02-23 およびその後のスナップショット
思考モードおよび非思考モードの両方で、
agentおよびagent_maxの検索戦略がサポートされます。qwen3-max および qwen3-max-2026-01-23:
非思考モード:検索戦略を
agentに設定します。思考モード: 検索戦略を
agentまたはagent_maxに設定します。agent_max 戦略は、agent 戦略に加えて Web エクストラクターをサポートします。
qwen3-max-2025-09-23:検索戦略を
agentに設定します。
グローバル
Qwen Plus:qwen3.5-plus、qwen3.5-plus-2026-02-15 以降のスナップショット
Qwen Flash:qwen3.5-flash、qwen3.5-flash-2026-02-23 およびその後のスナップショット
上記のモデルは、思考モードおよび非思考モードの両方で、agent および agent_max の検索戦略をサポートします。
中国本土
Qwen Plus:qwen3.5-plus、qwen3.5-plus-2026-02-15 以降のスナップショット
思考モードおよび非思考モードの両方で、
agentおよびagent_maxの検索戦略がサポートされます。Qwen Flash:qwen3.5-flash、qwen3.5-flash-2026-02-23 およびその後のスナップショット
思考モードおよび非思考モードの両方で、
agentおよびagent_maxの検索戦略がサポートされます。qwen3-max および qwen3-max-2026-01-23:
非思考モード:検索戦略を
agentに設定します。思考モード: 検索戦略を
agentまたはagent_maxに設定します。agent_max 戦略は、agent 戦略に加えて Web エクストラクターもサポートします。
qwen3-max-2025-09-23:検索戦略を
agentに設定します。
クイックスタート
以下のコードを実行して、Web検索サービスを用いて株価情報を素早く照会できます。
OpenAI 互換
OpenAI 互換プロトコルでは、応答に検索ソースを含める機能はサポートされていません。
Python
import os
from openai import OpenAI
client = OpenAI(
# 環境変数を設定していない場合は、以下の行を Model Studio API キーに置き換えます:api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3-max",
messages=[
{"role": "system", "content": "あなたは親切なアシスタントです。"},
{"role": "user", "content": "アリババの株価はいくらですか?"},
],
extra_body={
"enable_search": True,
"search_options": {
// Web検索戦略;agent のみサポート
"search_strategy": "agent"
}
}
)
print(completion.choices[0].message.content)応答例
最新の市場データによると、アリババの株価は以下の通りです。
* **米国株(BABA)**:最新価格は約 **$159.84** です。
* **香港株(09988.HK)**:最新価格は約 **HK$158.00** です。
注意:株価はリアルタイムで変動するため、この情報は参考用です。最新の市場データによると、アリババの株価は以下の通りです。
* **米国株(BABA)**:最新価格は約 **$159.84** です。
* **香港株(09988.HK)**:最新価格は約 **HK$158.00** です。
注意:株価はリアルタイムで変動するため、この情報は参考用です。Node.js
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
});
async function main() {
const completion = await openai.chat.completions.create({
model: "qwen3-max",
messages: [
{ role: "user", content: "アリババの株価はいくらですか?" }
],
enable_search: true,
search_options: {
// Web検索戦略;agent のみサポート
search_strategy: "agent"
}
});
console.log(completion.choices[0].message.content);
}
main();応答例
最新の市場データによると、アリババの株価は以下の通りです。
* **米国株(BABA)**:最新価格は約 **$159.84** です。
* **香港株(09988.HK)**:最新価格は約 **HK$158.00** です。
注意:株価はリアルタイムで変動するため、この情報は参考用です。最新の市場データによると、アリババの株価は以下の通りです。
* **米国株(BABA)**:最新価格は約 **$159.84** です。
* **香港株(09988.HK)**:最新価格は約 **HK$158.00** です。
注意:株価はリアルタイムで変動するため、この情報は参考用です。curl
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-max",
"messages": [
{
"role": "user",
"content": "アリババの株価はいくらですか?"
}
],
"enable_search": true,
"search_options": {
"search_strategy": "agent"
}
}'DashScope
DashScope プロトコルでは、enable_sourceをtrueに設定することで、応答に検索ソースを含めることができます。
Python
import os
import dashscope
dashscope.base_http_api_url = "https://dashscope-intl.aliyuncs.com/api/v1"
response = dashscope.Generation.call(
api_key=os.getenv("DASHSCOPE_API_KEY"),
model="qwen3-max",
messages=[{"role": "user", "content": "アリババの株価"}],
enable_search=True,
search_options={
// Web検索戦略;現時点で agent のみサポート:複数回のWeb検索およびLLM呼び出しによる反復的な情報取得と統合を可能にします
"search_strategy": "agent",
"enable_source": True // 検索ソースを返すかどうか
},
result_format="message",
)
print("="*20 + "検索結果" + "="*20)
for web in response.output.search_info["search_results"]:
print(f"[{web['index']}]: [{web['title']}]({web['url']})")
print("="*20 + "応答内容" + "="*20)
print(response.output.choices[0].message.content)応答例
====================検索結果====================
[1]: [アリババ(BABA)株価、チャート、引用符 - 東方財経](https://wap.eastmoney.com/quote/stock/106.BABA.html)
[2]: [アリババ(BABA)米国株価、今日の価格とチャート - 新浪財経](https://gu.sina.cn/quotes/us/BABA)
[3]: [アリババ(BABA)最新株価、リアルタイムチャート、分析および予測](https://cn.investing.com/equities/alibaba)
[4]: [アリババ-W(9988.HK)株価、ニュース、引用符および記録 - Yahooファイナンス](https://hk.finance.yahoo.com/quote/9988.HK/)
[5]: [アリババ(BABA)株価、引用符、ディスカッション - 雪球](https://xueqiu.com/S/BABA)
[6]: [アリババ(BABA)株価、時価総額、リアルタイム引用符、チャート、財務情報 - Moomoo](https://www.moomoo.com/hans/stock/BABA-US)
[7]: [アリババグループホールディング社(BABA)株価、ニュース、引用符および記録](https://finance.yahoo.com/quote/BABA/)
[8]: [アリババ - 腾讯証券](https://gu.qq.com/usBABA.N)
[9]: [W(09988)株価、時価総額、リアルタイム引用符、チャート、財務情報 - アリババ - Moomoo](https://www.moomoo.com/hans/stock/09988-HK)
====================応答内容====================
最新の市場データによると、アリババの株価情報は以下の通りです。
* **米国株(BABA)**:
* 本日の始値:$160.98
* 前営業日の終値:$160.80
* 本日の高値:$161.19
* 本日の安値:$156.20
* **香港株(09988.HK)**:
* 最新引用価格:約 HK$158.00 - 158.10
* 本日の始値:HK$156.50
* 前営業日の終値:HK$162.00
* 本日のレンジ:HK$156.30 - 158.40Java
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.SearchOptions;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.common.Role;
import java.util.Arrays;
public class Main {
static {Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";}
public static void main(String[] args) {
Generation gen = new Generation();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content("アリババの株価")
.build();
SearchOptions searchOptions = SearchOptions.builder()
// Web検索戦略;agent のみサポート
.searchStrategy("agent")
// 検索ソースを返す
.enableSource(true)
.build();
GenerationParam param = GenerationParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("qwen3-max")
.messages(Arrays.asList(userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.enableSearch(true)
.searchOptions(searchOptions)
.build();
try {
GenerationResult result = gen.call(param);
System.out.println("=".repeat(20)+"検索結果"+"=".repeat(20));
System.out.println(result.getOutput().getSearchInfo().getSearchResults());
System.out.println("=".repeat(20)+"応答内容"+"=".repeat(20));
System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent());
} catch (Exception e) {
System.out.println("エラー:" + e.getMessage());
}
}
}応答例
====================検索結果====================
[SearchInfo.SearchResult(siteName=null, icon=null, index=1, title=アリババ(BABA)株価、チャート、引用符 - 東方財経, url=https://wap.eastmoney.com/quote/stock/106.BABA.html), SearchInfo.SearchResult(siteName=null, icon=null, index=2, title=アリババ(BABA)_US株価、今日の価格とチャート_新浪財経, url=https://gu.sina.cn/quotes/us/BABA), SearchInfo.SearchResult(siteName=null, icon=null, index=3, title=アリババ(BABA)最新株価、リアルタイムチャート、分析および予測, url=https://cn.investing.com/equities/alibaba), SearchInfo.SearchResult(siteName=null, icon=null, index=4, title=アリババ(BABA)株価、引用符、ディスカッション - 雪球, url=https://xueqiu.com/S/BABA), SearchInfo.SearchResult(siteName=null, icon=null, index=5, title=アリババ-W (9988.HK)株価、ニュース、引用符および記録 - Yahooファイナンス, url=https://hk.finance.yahoo.com/quote/9988.HK/), SearchInfo.SearchResult(siteName=null, icon=null, index=6, title=アリババ(BABA)株価、時価総額、リアルタイム引用符、チャート、財務情報- Moomoo, url=https://www.moomoo.com/hans/stock/BABA-US), SearchInfo.SearchResult(siteName=null, icon=null, index=7, title=アリババグループホールディング社(BABA) - Yahooファイナンス, url=https://finance.yahoo.com/quote/BABA/), SearchInfo.SearchResult(siteName=null, icon=null, index=8, title=アリババ - 腾讯証券, url=https://gu.qq.com/usBABA.N), SearchInfo.SearchResult(siteName=null, icon=null, index=9, title=W(09988)株価、時価総額、リアルタイム引用符、チャート、財務情報- アリババ - Moomoo, url=https://www.moomoo.com/hans/stock/09988-HK)]
====================応答内容====================
最新の市場データによると、アリババの株価は以下の通りです。
* **米国株(BABA)**:最新価格は約 **$159.84** です。
* **香港株(09988.HK)**:最新価格は約 **HK$158.00** です。
注意:株価はリアルタイムで市場取引とともに変動するため、この情報は参考用です。curl
curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-max",
"input":{
"messages":[
{
"role": "user",
"content": "アリババの株価"
}
]
},
"parameters": {
"enable_search": true,
"search_options": {
"search_strategy": "agent",
"enable_source": true
},
"result_format": "message"
}
}'応答例
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": "最新の市場データによると、アリババの株価は米国および香港の上場銘柄で異なります。\n\n* **米国株(BABA)**:最新価格は約 **$160.40** です。\n * 本日の始値:$160.98\n * 本日のレンジ:$156.20 - 161.19\n\n* **香港株(09988.HK)**:最新価格は約 **HK$158.10** です。\n * 本日の始値:HK$156.50\n * 本日のレンジ:HK$156.30 - 158.40\n\n注意:株価は市場取引とともにリアルタイムで変動するため、この情報は参考用です。",
"role": "assistant"
}
}
],
"search_info": {
"search_results": [
{
"index": 1,
"title": "アリババ(BABA)株価、チャート、引用符 - 東方財経",
"url": "https://wap.eastmoney.com/quote/stock/106.BABA.html"
},
{
"index": 2,
"title": "アリババ(BABA)_US株価、今日の価格とチャート_新浪財経",
"url": "https://gu.sina.cn/quotes/us/BABA"
},
{
"index": 3,
"title": "アリババ-W (9988.HK)株価、ニュース、引用符および記録 - Yahooファイナンス",
"url": "https://hk.finance.yahoo.com/quote/9988.HK/"
},
{
"index": 4,
"title": "アリババ(BABA)最新株価、リアルタイムチャート、分析および予測",
"url": "https://cn.investing.com/equities/alibaba"
},
{
"index": 5,
"title": "アリババ(BABA)株価、引用符、ディスカッション - 雪球",
"url": "https://xueqiu.com/S/BABA"
},
{
"index": 6,
"title": "アリババ(BABA)株価、時価総額、リアルタイム引用符、チャート、財務情報- Moomoo",
"url": "https://www.moomoo.com/hans/stock/BABA-US"
},
{
"index": 7,
"title": "W(09988)株価、時価総額、リアルタイム引用符、チャート、財務情報- アリババ - Moomoo",
"url": "https://www.moomoo.com/hans/stock/09988-HK"
},
{
"index": 8,
"title": "アリババグループホールディング社(BABA)株価、ニュース、引用符および記録",
"url": "https://hk.finance.yahoo.com/quote/BABA/"
},
{
"index": 9,
"title": "アリババ - 腾讯証券",
"url": "https://gu.qq.com/usBABA.N"
}
]
}
},
"usage": {
"input_tokens": 2004,
"output_tokens": 203,
"plugins": {
"search": {
"count": 1,
"strategy": "agent"
}
},
"prompt_tokens_details": {
"cached_tokens": 0
},
"total_tokens": 2207
},
"request_id": "45c231d2-811e-4e04-a361-f2c1909f1dd9"
}Responses APIによるWeb検索
tools パラメーターを使用してWebエクストラクター機能を有効にするには、web_search ツールを tools 配列に追加します。
qwen3.5-plus、qwen3.5-plus-2026-02-15、qwen3.5-flash、qwen3.5-flash-2026-02-23、、および思考モードのqwen3-max、qwen3-max-2026-01-23でのみサポートされています。
最適な応答を得るためには、web_search、web_extractor、およびcode_interpreterツールを一緒に有効にすることを推奨します。
from openai import OpenAI
import os
client = OpenAI(
# 環境変数を設定していない場合は、以下の行を Model Studio API キーに置き換えます:api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)
response = client.responses.create(
model="qwen3-max-2026-01-23",
input="シンガポールの天気",
tools=[
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
extra_body={"enable_thinking": True}
)
print("="*20 + "応答内容" + "="*20)
print(response.output_text)
print("="*20 + "ツール呼び出し回数" + "="*20)
usage = response.usage
if hasattr(usage, 'x_tools') and usage.x_tools:
print(f"Web検索回数: {usage.x_tools.get('web_search', {}).get('count', 0)}")
# 中間出力を表示するには、以下の行のコメントを解除してください
# for r in response.output:
# print(r.model_dump_json())import OpenAI from "openai";
const openai = new OpenAI({
// 環境変数を設定していない場合は、以下の行を Model Studio API キーに置き換えます:apiKey: "sk-xxx",
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});
async function main() {
const response = await openai.responses.create({
model: "qwen3-max-2026-01-23",
input: "シンガポールの天気",
tools: [
{ type: "web_search" },
{ type: "web_extractor" },
{ type: "code_interpreter" }
],
enable_thinking: true
});
console.log("====================応答内容====================");
console.log(response.output_text);
console.log("====================ツール呼び出し回数====================");
console.log(`Web検索回数: ${response.usage.x_tools.web_search?.count || 0}`);
// console.log(JSON.stringify(response.output[0], null, 2));
}
main();curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-max-2026-01-23",
"input": "シンガポールの天気",
"tools": [
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
"enable_thinking": true
}'課金
課金には2つの側面があります。
モデル呼び出し料金:Web検索からのWebコンテンツがプロンプトに追加されるため、モデルの入力トークン数が増加します。モデルの標準価格に基づいて課金されます。価格の詳細については、「モデル一覧」をご参照ください。
検索戦略料金:
agent戦略:
1,000回あたりの料金:
中国本土およびグローバルデプロイメントモード:0.573411米ドル
国際デプロイメントモード:10.00米ドル。
agent_max戦略(期間限定オファー):
これには、Web検索とWebエクストラクターの料金が含まれます。
Web検索ツールの1,000回あたりの料金は以下の通りです:
中国本土デプロイメントモード:0.573411米ドル。
国際デプロイメントモード:10.00米ドル。
Webエクストラクターツールは期間限定で無料です。
エラーメッセージ
エラーが発生した場合は、「エラーメッセージ」で解決策をご参照ください。