LLM は Web ページのデータに直接アクセスできません。Web エクストラクターは URL にアクセスし、そのコンテンツを抽出してモデルに提供します。
使用方法
Web エクストラクターは 4 つの方法で呼び出すことができます。必要なパラメーターは方法ごとに異なります:- OpenAI 互換 - レスポンス API
- OpenAI 互換 - Chat Completions API
- DashScope
- Anthropic 互換
web_search と web_extractor を tools パラメーターに追加します。
数学やデータ分析の問題について精度をさらに高めるには、code_interpreter ツールも有効にしてください。
Copy
# 依存関係をインポートしてクライアントを作成します...
response = client.responses.create(
model="qwen3.8-max",
input="Please visit the official Alibaba Cloud Model Studio documentation for the code interpreter and summarize its main content",
tools=[
# Web 抽出を有効にするには、Web 検索ツールも有効にします
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
extra_body={
# 思考モードを有効にする必要があります
"enable_thinking": True
}
)
print(response.output_text)
enable_search を true に、search_strategy を agent_max に設定します。また、enable_thinking を true に設定します。非ストリーミング出力はサポートされていません。
Copy
# 依存関係をインポートしてクライアントを作成します...
completion = client.chat.completions.create(
model="qwen-max",
messages=[{"role": "user", "content": "Please visit the official Alibaba Cloud Model Studio documentation for the code interpreter and summarize its main content"}],
extra_body={
"enable_thinking": True,
"enable_search": True,
"search_options": {"search_strategy": "agent_max"}
},
stream=True
)
enable_search を true に、search_strategy を agent_max に設定します。また、enable_thinking を true に設定します。非ストリーミング出力はサポートされていません。
Copy
import os
import dashscope
# Singapore リージョン。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
client = dashscope.Client(
# 環境変数が設定されていない場合は、次の行を api_key="sk-xxx" に置き換え、Model Studio の API キーを使用してください。
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
stream = client.chat.completions.create(
model="qwen-max",
messages=[{"role": "user", "content": "Please visit the official Alibaba Cloud Model Studio documentation for the code interpreter and summarize its main content"}],
enable_search=True,
search_options={"search_strategy": "agent_max"},
enable_thinking=True,
stream=True
)
tools に名前が web_fetch のツールを追加し、同じリクエストに名前が web_search のツールも追加します。エンドポイントは https://{WorkspaceId}.{region}.maas.aliyuncs.com/apps/anthropic です。Claude Code などの Anthropic 公式クライアントでは、自然言語の質問から抽出を実行でき、追加設定は不要です。Anthropic SDK または HTTP で直接呼び出す場合は、system にクライアント識別子 x-anthropic-billing-header: cc_entrypoint=cli; を指定する必要があります。指定しない場合、抽出は機能しません。type の日付サフィックスはクライアントのバージョンによって決まります。サーバーはツールのカテゴリを識別し、日付サフィックスを検証しないため、クライアントが実際に送信する値を使用してください。検索ツールを追加せずに抽出ツールだけを指定すると、InvalidParameter エラー The web_extractor tool must be executed with web_search tool. が返されます。kimi-k3.1-pro もこの機能をサポートします。以下は Anthropic クライアントを初期化した後の呼び出しコードです。初期化については Anthropic Messages API を参照してください。スナップショットを呼び出す場合は、
model を deepseek-v4.1-flash-1017 に設定します。Copy
# Import dependencies and create the client...
message = client.messages.create(
model="qwen3.8-max",
max_tokens=4096,
# Pass the client identifier
system=[{"type": "text", "text": "x-anthropic-billing-header: cc_entrypoint=cli;"}],
messages=[{"role": "user", "content": "Read the Alibaba Cloud Model Studio code interpreter documentation and summarize the key points."}],
tools=[
# Enabling the web extractor requires the web search tool as well
# The date suffix in type depends on the client version. The values below are the ones current Claude Code sends.
{"type": "web_search_20250305", "name": "web_search", "max_uses": 5},
{"type": "web_fetch_20250910", "name": "web_fetch", "max_uses": 5}
]
)
server_tool_use と web_fetch_tool_result コンテンツブロックとして返されます。抽出回数は usage.server_tool_use.web_fetch_requests に記録されます。対応モデル
deepseek-v4.1-flash-1017 は、モデルページに記載された全 6 リージョンと対応するデプロイ範囲で、Responses API の組み込み web_extractor ツールと Anthropic 互換 API の組み込み web_fetch ツールをサポートします。
kimi-k3.1-pro (Alibaba Cloud Model Studio にデプロイ) は、北京、シンガポール、米国 (バージニア)、ドイツ (フランクフルト)、日本 (東京)、中国 (香港) で、Responses API の組み込み web_extractor ツールと Anthropic 互換 API の web_fetch をサポートします。
推奨モデル
- レスポンス API
- Chat Completions API / DashScope
Qwen-Max:qwen4-max-preview (Token Plan 限定)、Qwen3.8-Max シリーズ、Qwen3.7-Max シリーズQwen-Plus:Qwen3.7-Plus シリーズ、Qwen3.6-Plus シリーズ、Qwen3.5-Plus シリーズDeepSeek:deepseek-v4-flash-0731、deepseek-v4-proGLM:glm-5.2Qwen3.8 open-source シリーズ
- Qwen-Max (思考モード):Qwen3-Max シリーズ
- Qwen-Plus:Qwen3.5-Plus シリーズ
その他のモデル
以下のモデルもこのツールをサポートしていますが、推奨モデルほどの性能が得られない場合があります。レスポンス API 経由でのみサポートされます。- Qwen-Flash:Qwen3.7-Flash シリーズ、Qwen3.6-Flash シリーズ、Qwen3.5-Flash シリーズ
- Qwen3.6 open-source シリーズ (qwen3.6-27b を除く)
- Qwen3.5 open-source シリーズ
クイックスタート
この例では、レスポンス API を使用して Web エクストラクターを呼び出し、技術ドキュメントを要約します。API キーを取得し、環境変数として設定する必要があります。
Copy
import os
from openai import OpenAI
client = OpenAI(
# 環境変数が設定されていない場合は、次の行を api_key="sk-xxx" (非推奨) に置き換え、Model Studio の API キーを使用してください。
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore リージョン。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)
response = client.responses.create(
model="qwen3.8-max",
input="Please visit the official Alibaba Cloud Model Studio documentation for the code interpreter and summarize its main content",
tools=[
{
"type": "web_search"
},
{
"type": "web_extractor"
},
{
"type": "code_interpreter"
}
],
extra_body = {
"enable_thinking": True
}
)
# 中間プロセスの出力を表示するには、次の行のコメントを解除します
# print(response.output)
print("="*20+"Response Content"+"="*20)
print(response.output_text)
# ツール呼び出し回数を出力します
usage = response.usage
print("="*20+"Tool Call Count"+"="*20)
if hasattr(usage, 'x_tools') and usage.x_tools:
print(f"\nWeb extraction count: {usage.x_tools.get('web_extractor', {}).get('count', 0)}")
Copy
====================Response Content====================
Based on the official Alibaba Cloud Model Studio documentation, I have summarized the core content of the **コードインタープリター** feature for you:
## 1. Feature Positioning
...
> **Document Source**: Alibaba Cloud Model Studio official documentation - [Qwen Code Interpreter](https://www.alibabacloud.com/help/model-studio/qwen-code-interpreter) and [Assistant API Code Interpreter](https://www.alibabacloud.com/help/model-studio/code-interpreter)
====================Tool Call Count====================
Web extraction count: 1
ストリーミング出力
Web 抽出には時間がかかる場合があります。ストリーミング出力を有効にすると、中間結果をリアルタイムで受け取れます。ツール実行の中間ステータスを取得するには、レスポンス API を使用してください。
- OpenAI 互換 - レスポンス API
- OpenAI 互換 - Chat Completions API
- DashScope
Copy
import os
from openai import OpenAI
client = OpenAI(
# 環境変数が設定されていない場合は、次の行を api_key="sk-xxx" (非推奨) に置き換え、Model Studio の API キーを使用してください。
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore リージョン。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)
stream = client.responses.create(
model="qwen3.8-max",
input="Please visit the official Alibaba Cloud Model Studio documentation for the code interpreter and summarize its main content",
tools=[
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
stream=True,
extra_body={"enable_thinking": True}
)
reasoning_started = False
output_started = False
for chunk in stream:
# 思考プロセスを出力します
if chunk.type == 'response.reasoning_summary_text.delta':
if not reasoning_started:
print("="*20 + "Thinking Process" + "="*20)
reasoning_started = True
print(chunk.delta, end='', flush=True)
# ツール呼び出しの完了時に出力します
elif chunk.type == 'response.output_item.done':
if hasattr(chunk, 'item') and hasattr(chunk.item, 'type'):
if chunk.item.type == 'web_extractor_call':
print("\n" + "="*20 + "Tool Call" + "="*20)
print(chunk.item.goal)
print(chunk.item.output)
elif chunk.item.type == 'reasoning':
reasoning_started = False
# 応答コンテンツを出力します
elif chunk.type == 'response.output_text.delta':
if not output_started:
print("\n" + "="*20 + "Response Content" + "="*20)
output_started = True
print(chunk.delta, end='', flush=True)
# 応答が完了したら、ツール呼び出し回数を出力します
elif chunk.type == 'response.completed':
print("\n" + "="*20 + "Tool Call Count" + "="*20)
usage = chunk.response.usage
if hasattr(usage, 'x_tools') and usage.x_tools:
print(f"Web extraction count: {usage.x_tools.get('web_extractor', {}).get('count', 0)}")
print(f"Web search count: {usage.x_tools.get('web_search', {}).get('count', 0)}")
Copy
import os
from openai import OpenAI
client = OpenAI(
# 環境変数が設定されていない場合は、次の行を api_key="sk-xxx" (非推奨) に置き換え、Model Studio の API キーを使用してください。
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore リージョン。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)
stream = client.chat.completions.create(
model="qwen-max",
messages=[
{"role": "user", "content": "Please visit the official Alibaba Cloud Model Studio documentation for the code interpreter and summarize its main content"}
],
extra_body={
"enable_thinking": True,
"enable_search": True,
"search_options": {"search_strategy": "agent_max"}
},
stream=True
)
reasoning_started = False
output_started = False
for chunk in stream:
if chunk.choices:
delta = chunk.choices[0].delta
# 思考プロセスを出力します
if hasattr(delta, 'reasoning_content') and delta.reasoning_content:
if not reasoning_started:
print("="*20 + "Thinking Process" + "="*20)
reasoning_started = True
print(delta.reasoning_content, end='', flush=True)
# 応答コンテンツを出力します
if delta.content:
if not output_started:
print("\n" + "="*20 + "Response Content" + "="*20)
output_started = True
print(delta.content, end='', flush=True)
Java SDK はサポートされていません。
Copy
import os
import dashscope
from dashscope.v2 import DashScopeError
# Singapore リージョン。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
client = dashscope.Client(
# 環境変数が設定されていない場合は、次の行を api_key="sk-xxx" に置き換え、Model Studio の API キーを使用してください。
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
reasoning_started = False
output_started = False
try:
stream = client.chat.completions.create(
model="qwen-max",
messages=[
{"role": "user", "content": "Please visit the official Alibaba Cloud Model Studio documentation for the code interpreter and summarize its main content"}
],
enable_search=True,
search_options={"search_strategy": "agent_max"},
enable_thinking=True,
stream=True
)
for chunk in stream:
delta = chunk.choices[0].delta
# 思考プロセスを出力します
if delta.reasoning_content:
if not reasoning_started:
print("="*20 + "Thinking Process" + "="*20)
reasoning_started = True
print(delta.reasoning_content, end='', flush=True)
# 応答コンテンツを出力します
if delta.content:
if not output_started:
print("\n" + "="*20 + "Response Content" + "="*20)
output_started = True
print(delta.content, end='', flush=True)
except DashScopeError as e:
print(f"HTTP status code: {e.status_code}")
print(f"Error code: {e.code}")
print(f"Error message: {e.message}")
print("See: https://www.alibabacloud.com/help/ja/model-studio/developer-reference/error-code")
課金
課金には以下が含まれます:- モデル呼び出し料金:Web ページから抽出したコンテンツがプロンプトに追加されるため、入力トークン数が増加します。これらのトークンは、モデルの標準レートで課金されます。料金の詳細については、Model Studio コンソールをご参照ください。
-
ツール呼び出し料金:Web 抽出および Web 検索が含まれます。
-
Web 検索の料金 (1,000 回あたり):
- China (Beijing) リージョン:$0.57341。
- シンガポールリージョン: $10.00。
- Web エクストラクターは期間限定で無料です。
-
Web 検索の料金 (1,000 回あたり):