---
title: Webフェッチツール
url: https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool
description: 特定のURLからコンテンツを取得して読み込み、ライブのWebコンテンツでClaudeのコンテキストを拡張します。
---

<Note>
  「zero data retention」（ゼロデータ保持）、すなわちZDRがこの機能にどのように適用されるかについては、[APIとデータ保持](https://platform.claude.com/docs/ja/manage-claude/api-and-data-retention)を参照してください。
</Note>

「web fetch tool」（Webフェッチツール）を使用すると、Claudeは指定されたWebページやPDFドキュメントから完全なコンテンツを取得できます。

最新のウェブフェッチツールのバージョン（`web_fetch_20260318`）は**dynamic filtering**（動的フィルタリング）をサポートしています。Claudeはコードを記述・実行して、取得したコンテンツが「context window」（コンテキストウィンドウ）に到達する前にフィルタリングし、関連する情報のみを保持して残りを破棄できます。これにより、応答の品質を維持しながらトークン消費を削減できます。動的フィルタリングは、Claude 4.6以降のモデルおよび[Claude Mythos Preview](https://anthropic.com/glasswing)で利用できます。`web_fetch_20260318`では、エージェントワークフロー向けの[「response inclusion」（レスポンス包含）](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#response-inclusion)の制御も追加されています。以前のバージョン（動的フィルタリングと[「cache bypass」（キャッシュバイパス）](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#cache-bypass)に対応した`web_fetch_20260309`、動的フィルタリングのみに対応した`web_fetch_20260209`、基本的なフェッチに対応した`web_fetch_20250910`）も引き続き利用できます。

Webフェッチ（動的フィルタリングの有無を問わず）は、Claude API、[Claude Platform on AWS](https://platform.claude.com/docs/ja/build-with-claude/claude-platform-on-aws)、および[Microsoft Foundry](https://platform.claude.com/docs/ja/build-with-claude/claude-in-microsoft-foundry)で利用できます。Microsoft Foundryでは、[Azureでホストされている](https://platform.claude.com/docs/ja/build-with-claude/claude-in-microsoft-foundry#additional-features-not-supported-when-hosted-on-azure)デプロイメントは基本的なWebフェッチツール（`web_fetch_20250910`、動的フィルタリングなし）のみをサポートします。Anthropicでホストされているデプロイメントはすべてのバージョンをサポートします。Webフェッチは現在、Amazon BedrockおよびGoogle Cloudでは利用できません。

<Note>
  [Claude Mythos Preview](https://anthropic.com/glasswing)の場合、WebフェッチはClaude APIおよびMicrosoft Foundryで利用できます。現在、Amazon BedrockまたはGoogle Cloud上のMythos Previewでは利用できません。
</Note>

<Note>
  モデルの応答品質、API自体、またはドキュメントの品質に関するフィードバックは、[フィードバックフォーム](https://forms.gle/NhWcgmkcvPCMmPE86)からお寄せください。
</Note>

Zero Data Retentionの適格性と`allowed_callers`の回避策については、[サーバーツール](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/server-tools#zdr-and-allowed-callers)を参照してください。

<Warning>
  Claudeが機密データとともに信頼できない入力を処理する環境でWebフェッチツールを有効にすると、データ流出のリスクが生じます。このツールは、信頼できる環境でのみ、または機密性のないデータを扱う場合にのみ使用してください。

  流出リスクを最小限に抑えるため、Claudeは自身の出力にのみ現れるURLをフェッチできません。Claudeがフェッチできるのは、会話内に以前に現れたURLのみです。具体的には、ユーザーメッセージ内のURL、クライアントサイドのツール結果内のURL（結果がClaudeの生成したテキストをそのまま返している場合も含む）、および以前のWeb検索またはWebフェッチの結果に含まれるURLです（[URL検証](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#url-validation)を参照）。また、Claudeは、APIキーやパスワードなどの認証情報を含むと思われるURLを、その認証情報がシステムプロンプトまたはユーザーメッセージのテキストに含まれていない限りフェッチできません。

  ただし、このツールを使用する際には慎重に検討すべき残存リスクが依然として存在します。

  データ流出が懸念される場合は、以下を検討してください。

  * Webフェッチツールを完全に無効にする
  * `max_uses`パラメータを使用してリクエスト数を制限する
  * `allowed_domains`パラメータを使用して既知の安全なドメインに制限する
</Warning>

モデルのサポート状況については、[ツールリファレンス](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/tool-reference)を参照してください。

## Webフェッチの仕組み

Webフェッチは[サーバーツール](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/server-tools)です。APIがリクエスト中にコンテンツを取得し、結果を会話に挿入します。ユーザー側で何かを実行したり、`tool_result`を返したりする必要はありません。例外は、Claudeが同じ並列ツール呼び出しグループ内でWebフェッチとクライアントツールの1つを呼び出す場合です。この場合、APIはそのフェッチが実行される前に`stop_reason: "tool_use"`でレスポンスを返し、クライアントの`tool_result`ブロックを送り返したときにフェッチを実行します。[1つのターンでサーバーツールとクライアントツールを混在させる](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/server-tools#mixing-server-tools-and-client-tools-in-one-turn)を参照してください。

APIリクエストにWebフェッチツールを追加すると、次のように動作します。

1. Claudeは、プロンプトと利用可能なURLに基づいて、いつコンテンツをフェッチするかを判断します。
2. APIは指定されたURLから完全なテキストコンテンツを取得します。
3. PDFの場合、APIはコンテンツをbase64エンコードされたデータとして返し、直接添付されたPDFドキュメントと同様に処理します。
4. Claudeは取得したコンテンツを分析し、オプションの引用付きで応答を提供します。

<Note>
  Webフェッチツールは現在、JavaScriptで動的にレンダリングされるWebサイトをサポートしていません。実際のブラウザが必要なページ（JavaScriptレンダリング、クリック、フォーム入力など）については、[ブラウザ使用ツール](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/browser-use-tool)を検討してください。これはクライアントツールであり、アプリケーションがブラウザを操作し、ページのテキストやスクリーンショットをツール結果としてClaudeに返します。
</Note>

### Claudeがフェッチするタイミング

Claudeは、リクエストが特定のページやドキュメントを指している場合にフェッチします。

* 会話内（または以前のツール結果内）にURLが提供されている場合
* ユーザーがURLなしで特定のリソース（特定の記事、README、料金ページ、ドキュメントのセクションなど）を指定し、かつ[Web検索ツール](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-search-tool)も有効になっていて、Claudeが最初にそれを見つけられる場合（[検索とフェッチの組み合わせ](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#combined-search-and-fetch)を参照）

Claudeは、特定のページを参照しない一般知識の質問やオープンエンドな質問に対してはフェッチ**しません**。「この記事を要約してください: `<url>`」はフェッチをトリガーします。「REST API設計のベストプラクティスは何ですか？」には直接回答します。

### 動的フィルタリング

Webページ全体やPDFをフェッチすると、特に大きなドキュメントから特定の情報のみが必要な場合、トークンをすぐに消費してしまいます。`web_fetch_20260209`以降では、Claudeはコードを記述して実行し、取得したコンテンツをコンテキストに読み込む前にフィルタリングできます。

この動的フィルタリングは、特に次のような場合に役立ちます。

* 長いドキュメントから特定のセクションを抽出する
* Webページの構造化データを処理する
* PDFから関連情報をフィルタリングする
* 大きなドキュメントを扱う際のトークンコストを削減する

<Note>
  動的フィルタリングは[コード実行ツール](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/code-execution-tool)上で実行され、APIはリクエストに対してこれを自動的に有効にします。`tools`配列にコード実行ツールを追加する必要はありません。
</Note>

動的フィルタリングを有効にするには、`web_fetch_20260209`またはそれ以降のバージョンを使用します。以下の例では`web_fetch_20260318`を使用しています。

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 4096,
      "messages": [
        {
          "role": "user",
          "content": "Fetch the content at https://example.com/research-paper and extract the key findings."
        }
      ],
      "tools": [{
        "type": "web_fetch_20260318",
        "name": "web_fetch"
      }]
    }'
  ```

  ```bash CLI
  ant messages create <<'YAML'
  model: claude-opus-5-5
  max_tokens: 4096
  messages:
    - role: user
      content: >-
        Fetch the content at https://example.com/research-paper
        and extract the key findings.
  tools:
    - type: web_fetch_20260318
      name: web_fetch
  YAML
  ```

  ```python Python
  client = anthropic.Anthropic()

  response = client.messages.create(
      model="claude-opus-5-5",
      max_tokens=4096,
      messages=[
          {
              "role": "user",
              "content": "Fetch the content at https://example.com/research-paper and extract the key findings.",
          }
      ],
      tools=[{"type": "web_fetch_20260318", "name": "web_fetch"}],
  )
  print(response)
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const response = await client.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 4096,
    messages: [
      {
        role: "user",
        content:
          "Fetch the content at https://example.com/research-paper and extract the key findings."
      }
    ],
    tools: [{ type: "web_fetch_20260318", name: "web_fetch" }]
  });

  console.log(response);
  ```

  ```csharp C#
  AnthropicClient client = new();

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 4096,
      Messages = [new() { Role = Role.User, Content = "Fetch the content at https://example.com/research-paper and extract the key findings." }],
      Tools = [new ToolUnion(new WebFetchTool20260318())]
  };

  var message = await client.Messages.Create(parameters);
  Console.WriteLine(message);
  ```

  ```go Go
  client := anthropic.NewClient()

  response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 4096,
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("Fetch the content at https://example.com/research-paper and extract the key findings.")),
  	},
  	Tools: []anthropic.ToolUnionParam{
  		{OfWebFetchTool20260318: &anthropic.WebFetchTool20260318Param{}},
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response.RawJSON())
  ```

  ```java Java
  import com.anthropic.models.messages.WebFetchTool20260318;

  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      MessageCreateParams params = MessageCreateParams.builder()
          .model(Model.CLAUDE_OPUS_5_5)
          .maxTokens(4096L)
          .addUserMessage("Fetch the content at https://example.com/research-paper and extract the key findings.")
          .addTool(WebFetchTool20260318.builder().build())
          .build();

      Message response = client.messages().create(params);
      IO.println(response);
  }
  ```

  ```php PHP
  $client = new Client();

  $message = $client->messages->create(
      maxTokens: 4096,
      messages: [
          ['role' => 'user', 'content' => 'Fetch the content at https://example.com/research-paper and extract the key findings.']
      ],
      model: 'claude-opus-5-5',
      tools: [[
          'type' => 'web_fetch_20260318',
          'name' => 'web_fetch',
      ]],
  );
  echo $message;
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  message = client.messages.create(
    model: "claude-opus-5-5",
    max_tokens: 4096,
    messages: [
      { role: "user", content: "Fetch the content at https://example.com/research-paper and extract the key findings." }
    ],
    tools: [{
      type: "web_fetch_20260318",
      name: "web_fetch"
    }]
  )
  puts message
  ```
</CodeGroup>

## Webフェッチの使用方法

APIリクエストでWebフェッチツールを指定します。

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": "Please analyze the content at https://example.com/article"
        }
      ],
      "tools": [{
        "type": "web_fetch_20250910",
        "name": "web_fetch",
        "max_uses": 5
      }]
    }'
  ```

  ```bash CLI
  ant messages create \
    --model claude-opus-5-5 \
    --max-tokens 1024 \
    --message '{role: user, content: "Please analyze the content at https://example.com/article"}' \
    --tool '{type: web_fetch_20250910, name: web_fetch, max_uses: 5}'
  ```

  ```python Python
  client = anthropic.Anthropic()

  response = client.messages.create(
      model="claude-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": "Please analyze the content at https://example.com/article",
          }
      ],
      tools=[{"type": "web_fetch_20250910", "name": "web_fetch", "max_uses": 5}],
  )
  print(response)
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const response = await client.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: "Please analyze the content at https://example.com/article"
      }
    ],
    tools: [
      {
        type: "web_fetch_20250910",
        name: "web_fetch",
        max_uses: 5
      }
    ]
  });

  console.log(response);
  ```

  ```csharp C#
  AnthropicClient client = new();

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 1024,
      Messages = [new() { Role = Role.User, Content = "Please analyze the content at https://example.com/article" }],
      Tools = [new ToolUnion(new WebFetchTool20250910() { MaxUses = 5 })]
  };

  var message = await client.Messages.Create(parameters);
  Console.WriteLine(message);
  ```

  ```go Go
  client := anthropic.NewClient()

  response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 1024,
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("Please analyze the content at https://example.com/article")),
  	},
  	Tools: []anthropic.ToolUnionParam{
  		{OfWebFetchTool20250910: &anthropic.WebFetchTool20250910Param{
  			MaxUses: anthropic.Int(5),
  		}},
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response.RawJSON())
  ```

  ```java Java
  import com.anthropic.models.messages.WebFetchTool20250910;

  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      MessageCreateParams params = MessageCreateParams.builder()
          .model(Model.CLAUDE_OPUS_5_5)
          .maxTokens(1024L)
          .addUserMessage("Please analyze the content at https://example.com/article")
          .addTool(WebFetchTool20250910.builder()
              .maxUses(5L)
              .build())
          .build();

      Message response = client.messages().create(params);
      IO.println(response);
  }
  ```

  ```php PHP
  $client = new Client();

  $message = $client->messages->create(
      maxTokens: 1024,
      messages: [
          ['role' => 'user', 'content' => 'Please analyze the content at https://example.com/article']
      ],
      model: 'claude-opus-5-5',
      tools: [[
          'type' => 'web_fetch_20250910',
          'name' => 'web_fetch',
          'max_uses' => 5,
      ]],
  );
  echo $message;
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  message = client.messages.create(
    model: "claude-opus-5-5",
    max_tokens: 1024,
    messages: [
      { role: "user", content: "Please analyze the content at https://example.com/article" }
    ],
    tools: [{
      type: "web_fetch_20250910",
      name: "web_fetch",
      max_uses: 5
    }]
  )
  puts message
  ```
</CodeGroup>

## ツール定義

Webフェッチツールは以下のパラメータをサポートしています。

```json JSON
{
  "type": "web_fetch_20250910",
  "name": "web_fetch",

  // Optional: Limit the number of fetches per request
  "max_uses": 10,

  // Optional: Only fetch from these domains
  "allowed_domains": ["example.com", "docs.example.com"],

  // Optional: Never fetch from these domains (cannot be combined with allowed_domains)
  "blocked_domains": ["private.example.com"],

  // Optional: Enable citations for fetched content
  "citations": {
    "enabled": true
  },

  // Optional: Maximum content length in tokens
  "max_content_tokens": 100000
}
```

以降のツールバージョンでは、さらに2つのオプションパラメータが追加されています。`use_cache`には`web_fetch_20260309`以降が必要です（[キャッシュバイパス](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#cache-bypass)を参照）。`response_inclusion`には`web_fetch_20260318`以降が必要です（[レスポンスインクルージョン](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#response-inclusion)を参照）。

### 最大使用回数

`max_uses`パラメータは、実行されるWebフェッチの回数を制限します。失敗したフェッチも制限に対してカウントされます。Claudeが許可された回数を超えてフェッチを試みた場合、`web_fetch_tool_result`は`max_uses_exceeded`エラーコードを持つエラーになります。現在、デフォルトの制限はありません。

### ドメインフィルタリング

`allowed_domains`と`blocked_domains`によるドメインフィルタリングについては、[サーバーツール](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/server-tools#domain-filtering)を参照してください。

[Claude Managed Agents](https://platform.claude.com/docs/ja/managed-agents/overview)では、エージェントツールセットの`web_fetch`エントリにこれらのフィールドを設定します。リストに含める各ドメインは、パスを含まないプレーンなホスト名である必要があります。[Web検索とWebフェッチのドメインを制限する](https://platform.claude.com/docs/ja/managed-agents/tools-web-restrictions)を参照してください。

### コンテンツ制限

`max_content_tokens`パラメータは、コンテキストに含まれるコンテンツの量を制限します。取得したコンテンツがこの制限を超える場合、ツールはそれを切り詰めます。これは、大きなドキュメントをフェッチする際のトークン使用量の制御に役立ちます。この制限はテキストコンテンツに適用され、PDFなどのバイナリコンテンツには適用されません。

<Note>
  `max_content_tokens`パラメータの制限は概算です。実際に使用される入力トークン数は若干異なる場合があります。
</Note>

Claude Managed Agentsでは、エージェントツールセットの`web_fetch`エントリも`max_content_tokens`を受け付けます。[Webツールの設定](https://platform.claude.com/docs/ja/managed-agents/tools-web-restrictions#settings)を参照してください。

### キャッシュバイパス

<Note>
  `web_fetch_20260309`以降（`web_fetch_20260318`を含む）が必要です。
</Note>

`use_cache`パラメータは、キャッシュされたコンテンツを返してよいかどうかを制御します。キャッシュをバイパスして最新のコンテンツをフェッチするには、`"use_cache": false`を設定します。デフォルトは`true`です。キャッシュをバイパスすると「latency」（レイテンシ）が増加するため、ユーザーが明示的に最新のコンテンツを要求した場合、または急速に変化するソースをフェッチする場合にのみキャッシュを無効にしてください。

```json
{
  "tools": [
    {
      "type": "web_fetch_20260309",
      "name": "web_fetch",
      "use_cache": false
    }
  ]
}
```

### レスポンスインクルージョン

<Note>
  `web_fetch_20260318`以降が必要です。
</Note>

`response_inclusion`パラメータは、同じターン内で完了した[コード実行](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/code-execution-tool)呼び出しによって結果が消費された場合に、フェッチ結果ブロックがAPIレスポンスにどのように表示されるかを制御します。`"response_inclusion": "excluded"`を設定すると、ネストされた`server_tool_use`と結果ブロックのペアがレスポンスから完全に削除され、生のページコンテンツをクライアントにエコーバックする必要のないエージェントワークフローの出力トークンコストを削減できます。デフォルトは`"full"`です。直接呼び出しの結果、または完了前に一時停止したコード実行呼び出しの結果は、次のターンで送り返せるように常に完全な形で返されます。

```json
{
  "tools": [
    {
      "type": "web_fetch_20260318",
      "name": "web_fetch",
      "response_inclusion": "excluded"
    }
  ]
}
```

### 引用

引用が常に有効になっているWeb検索とは異なり、Webフェッチでは引用はオプションであり、デフォルトでは無効になっています。Claudeが取得したドキュメントから特定の箇所を引用できるようにするには、`"citations": {"enabled": true}`を設定します。

<Note>
  APIの出力をエンドユーザーに直接表示する場合は、元のソースへの引用を含めてください。APIの出力に変更を加える場合（エンドユーザーに表示する前に再処理したり、独自の資料と組み合わせたりする場合を含む）は、法務チームと相談のうえ、適切に引用を表示してください。
</Note>

## レスポンス

レスポンス構造の例を以下に示します。

```json Output
{
  "role": "assistant",
  "content": [
    // 1. Claude's decision to fetch
    {
      "type": "text",
      "text": "I'll fetch the content from the article to analyze it."
    },
    // 2. The fetch request
    {
      "type": "server_tool_use",
      "id": "srvtoolu_01234567890abcdef",
      "name": "web_fetch",
      "input": {
        "url": "https://example.com/article"
      }
    },
    // 3. Fetch results
    {
      "type": "web_fetch_tool_result",
      "tool_use_id": "srvtoolu_01234567890abcdef",
      "content": {
        "type": "web_fetch_result",
        "url": "https://example.com/article",
        "content": {
          "type": "document",
          "source": {
            "type": "text",
            "media_type": "text/plain",
            "data": "Full text content of the article..."
          },
          "title": "Article Title",
          "citations": { "enabled": true }
        },
        "retrieved_at": "2025-08-25T10:30:00Z"
      }
    },
    // 4. Claude's analysis with citations (if enabled)
    {
      "text": "Based on the article, ",
      "type": "text"
    },
    {
      "text": "the main argument presented is that artificial intelligence will transform healthcare",
      "type": "text",
      "citations": [
        {
          "type": "char_location",
          "document_index": 0,
          "document_title": "Article Title",
          "start_char_index": 1234,
          "end_char_index": 1456,
          "cited_text": "Artificial intelligence is poised to revolutionize healthcare delivery..."
        }
      ]
    }
  ],
  "id": "msg_a930390d3a",
  "usage": {
    "input_tokens": 25039,
    "output_tokens": 931,
    "server_tool_use": {
      "web_fetch_requests": 1
    }
  },
  "stop_reason": "end_turn"
}
```

### フェッチ結果

フェッチ結果には以下が含まれます。

* `url`: フェッチされたURL
* `content`: 取得したコンテンツを含むドキュメントブロック
* `retrieved_at`: コンテンツが取得された時点のタイムスタンプ

<Note>
  Webフェッチツールは、パフォーマンスを向上させ冗長なリクエストを削減するために結果をキャッシュします。返されるコンテンツは、そのURLで利用可能な最新バージョンを常に反映しているとは限りません。キャッシュの動作は自動的に管理され、さまざまなコンテンツタイプや使用パターンに最適化するために時間とともに変更される可能性があります。最新のコンテンツをフェッチするには、`"use_cache": false`を設定してください（[キャッシュバイパス](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#cache-bypass)を参照）。
</Note>

PDFドキュメントの場合、コンテンツはbase64エンコードされたデータとして返されます。

```json Output
{
  "type": "web_fetch_tool_result",
  "tool_use_id": "srvtoolu_02",
  "content": {
    "type": "web_fetch_result",
    "url": "https://example.com/paper.pdf",
    "content": {
      "type": "document",
      "source": {
        "type": "base64",
        "media_type": "application/pdf",
        "data": "JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmo..."
      },
      "citations": { "enabled": true }
    },
    "retrieved_at": "2025-08-25T10:30:02Z"
  }
}
```

### エラー

Webフェッチツールでエラーが発生した場合、Claude APIは200（成功）レスポンスを返し、エラーはレスポンス本文内で表現されます。Claudeはエラー結果を確認し、ターンを続行します。例：

```json Output
{
  "type": "web_fetch_tool_result",
  "tool_use_id": "srvtoolu_a93jad",
  "content": {
    "type": "web_fetch_tool_result_error",
    "error_code": "url_not_accessible"
  }
}
```

発生しうるエラーコードは以下のとおりです。

* `invalid_tool_input`: 不正な形式のURLやHTTP(S)以外のスキームなど、無効なツール入力
* `url_too_long`: URLが最大長（250文字）を超えている
* `url_not_allowed`: ドメインフィルタリングルール（組織の設定を含む）、またはプライベートアドレス、`robots.txt`、お客様が提供していない認証情報を含むと思われるURLなどのAnthropic側の制限によってURLがブロックされた
* `url_not_in_prior_context`: URLが会話内に以前出現していない（[URL検証](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/web-fetch-tool#url-validation)を参照）
* `url_not_accessible`: コンテンツの取得に失敗した（HTTPエラー）
* `too_many_requests`: レート制限を超過した
* `unsupported_content_type`: サポートされていないコンテンツタイプ（テキスト、HTML、PDFのみ対応）
* `max_uses_exceeded`: Webフェッチツールの最大使用回数を超過した
* `unavailable`: 内部エラーが発生した

## URL検証

セキュリティ上の理由から、Webフェッチツールは会話コンテキスト内に以前出現したURLのみをフェッチできます。これには以下が含まれます。

* ユーザーメッセージ内のURL
* クライアント側のツール結果内のURL
* 以前のWeb検索またはWebフェッチの結果から得られたURL

このツールは、Claude自身の出力にのみ現れるURLや、システムプロンプトにのみ現れるURLをフェッチできません。システムプロンプト内のURLをフェッチ可能にするには、そのURLをユーザーメッセージにも含めてください。[コード実行](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/code-execution-tool)、[MCPコネクタ](https://platform.claude.com/docs/ja/agents-and-tools/mcp-connector)、[ツール検索](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/tool-search-tool)など、他のサーバーサイドツールの結果も許可されたソースではありません。クライアントサイドのツール結果は、Claudeが生成したテキストをそのまま返している場合（たとえば、入力を出力するコマンドや、入力を引用するエラーメッセージなど）でも、許可されたソースです。

また、このツールは、APIキーやパスワードなどの認証情報を含むと思われるURLを、その認証情報がシステムプロンプトまたはユーザーメッセージのテキストに含まれていない限り拒否します。認証情報がツール結果にのみ現れる場合は、この条件を満たしません。この場合、結果は`url_not_allowed`エラーになります。このようなURLをフェッチするには、ユーザーメッセージにそのURLを含めてください。

## 検索とフェッチの組み合わせ

Web検索ツールとWebフェッチツールの両方が有効になっていて、ユーザーがURLを提供せずに特定のページやドキュメントを指定した場合（例：「anthropics/anthropic-sdk-pythonリポジトリのREADMEを読んでください」）、ClaudeはWeb検索を使用してそれを見つけ、その結果をフェッチします。次の例では、1つのリクエストで検索と分析を依頼しています。

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 4096,
      "messages": [
        {
          "role": "user",
          "content": "Find recent articles about quantum computing and analyze the most relevant one in detail"
        }
      ],
      "tools": [
        {
          "type": "web_search_20250305",
          "name": "web_search",
          "max_uses": 3
        },
        {
          "type": "web_fetch_20250910",
          "name": "web_fetch",
          "max_uses": 5,
          "citations": {"enabled": true}
        }
      ]
    }'
  ```

  ```bash CLI
  ant messages create <<'YAML'
  model: claude-opus-5-5
  max_tokens: 4096
  messages:
    - role: user
      content: >-
        Find recent articles about quantum computing
        and analyze the most relevant one in detail
  tools:
    - type: web_search_20250305
      name: web_search
      max_uses: 3
    - type: web_fetch_20250910
      name: web_fetch
      max_uses: 5
      citations:
        enabled: true
  YAML
  ```

  ```python Python
  client = anthropic.Anthropic()

  response = client.messages.create(
      model="claude-opus-5-5",
      max_tokens=4096,
      messages=[
          {
              "role": "user",
              "content": "Find recent articles about quantum computing and analyze the most relevant one in detail",
          }
      ],
      tools=[
          {"type": "web_search_20250305", "name": "web_search", "max_uses": 3},
          {
              "type": "web_fetch_20250910",
              "name": "web_fetch",
              "max_uses": 5,
              "citations": {"enabled": True},
          },
      ],
  )
  print(response)
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const response = await client.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 4096,
    messages: [
      {
        role: "user",
        content:
          "Find recent articles about quantum computing and analyze the most relevant one in detail"
      }
    ],
    tools: [
      { type: "web_search_20250305", name: "web_search", max_uses: 3 },
      {
        type: "web_fetch_20250910",
        name: "web_fetch",
        max_uses: 5,
        citations: { enabled: true }
      }
    ]
  });

  console.log(response);
  ```

  ```csharp C#
  AnthropicClient client = new();

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 4096,
      Messages = [new() { Role = Role.User, Content = "Find recent articles about quantum computing and analyze the most relevant one in detail" }],
      Tools = [
          new ToolUnion(new WebSearchTool20250305() { MaxUses = 3 }),
          new ToolUnion(new WebFetchTool20250910() { MaxUses = 5, Citations = new() { Enabled = true } })
      ]
  };

  var message = await client.Messages.Create(parameters);
  Console.WriteLine(message);
  ```

  ```go Go
  client := anthropic.NewClient()

  response, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 4096,
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("Find recent articles about quantum computing and analyze the most relevant one in detail")),
  	},
  	Tools: []anthropic.ToolUnionParam{
  		{OfWebSearchTool20250305: &anthropic.WebSearchTool20250305Param{
  			MaxUses: anthropic.Int(3),
  		}},
  		{OfWebFetchTool20250910: &anthropic.WebFetchTool20250910Param{
  			MaxUses:   anthropic.Int(5),
  			Citations: anthropic.CitationsConfigParam{Enabled: anthropic.Bool(true)},
  		}},
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response.RawJSON())
  ```

  ```java Java
  import com.anthropic.models.messages.CitationsConfigParam;
  // ...
  import com.anthropic.models.messages.WebFetchTool20250910;
  import com.anthropic.models.messages.WebSearchTool20250305;

  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      MessageCreateParams params = MessageCreateParams.builder()
          .model(Model.CLAUDE_OPUS_5_5)
          .maxTokens(4096L)
          .addUserMessage("Find recent articles about quantum computing and analyze the most relevant one in detail")
          .addTool(WebSearchTool20250305.builder()
              .maxUses(3L)
              .build())
          .addTool(WebFetchTool20250910.builder()
              .maxUses(5L)
              .citations(CitationsConfigParam.builder().enabled(true).build())
              .build())
          .build();

      Message response = client.messages().create(params);
      IO.println(response);
  }
  ```

  ```php PHP
  $client = new Client();

  $message = $client->messages->create(
      maxTokens: 4096,
      messages: [
          ['role' => 'user', 'content' => 'Find recent articles about quantum computing and analyze the most relevant one in detail']
      ],
      model: 'claude-opus-5-5',
      tools: [
          [
              'type' => 'web_search_20250305',
              'name' => 'web_search',
              'max_uses' => 3,
          ],
          [
              'type' => 'web_fetch_20250910',
              'name' => 'web_fetch',
              'max_uses' => 5,
              'citations' => ['enabled' => true],
          ],
      ],
  );
  echo $message;
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  message = client.messages.create(
    model: "claude-opus-5-5",
    max_tokens: 4096,
    messages: [
      { role: "user", content: "Find recent articles about quantum computing and analyze the most relevant one in detail" }
    ],
    tools: [
      {
        type: "web_search_20250305",
        name: "web_search",
        max_uses: 3
      },
      {
        type: "web_fetch_20250910",
        name: "web_fetch",
        max_uses: 5,
        citations: { enabled: true }
      }
    ]
  )
  puts message
  ```
</CodeGroup>

このワークフローでは、Claudeは次のように動作します。

1. Web検索を使用して関連する記事を見つけます。
2. 最も有望な結果を選択します。
3. Webフェッチを使用して完全なコンテンツを取得します。
4. 引用付きの詳細な分析を提供します。

## プロンプトキャッシング

ターンをまたいでツール定義をキャッシュするには、[プロンプトキャッシングを使用したツール使用](https://platform.claude.com/docs/ja/agents-and-tools/tool-use/tool-use-with-prompt-caching)を参照してください。

## ストリーミング

ストリーミングを有効にすると、フェッチイベントはストリームの一部となり、コンテンツ取得中は一時停止します。

```sse Output
event: message_start
data: {"type": "message_start", "message": {"id": "msg_abc123", "type": "message"}}

event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}

// Claude's decision to fetch

event: content_block_start
data: {"type": "content_block_start", "index": 1, "content_block": {"type": "server_tool_use", "id": "srvtoolu_xyz789", "name": "web_fetch"}}

// Fetch URL streamed
event: content_block_delta
data: {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"url\":\"https://example.com/article\"}"}}

// Pause while fetch executes

// Fetch results streamed
event: content_block_start
data: {"type": "content_block_start", "index": 2, "content_block": {"type": "web_fetch_tool_result", "tool_use_id": "srvtoolu_xyz789", "content": {"type": "web_fetch_result", "url": "https://example.com/article", "content": {"type": "document", "source": {"type": "text", "media_type": "text/plain", "data": "Article content..."}}}}}

// Claude's response continues...
```

## バッチリクエスト

Webフェッチツールは[Messages Batches API](https://platform.claude.com/docs/ja/build-with-claude/batch-processing)に含めることができます。Messages Batches API経由のWebフェッチツール呼び出しは、通常のMessages APIリクエストと同じ料金です。

## 使用量と料金

Web fetch（ウェブフェッチ）の使用には、標準のトークンコスト以外に**追加料金はかかりません**。

```json
{
  "usage": {
    "input_tokens": 25039,
    "output_tokens": 931,
    "cache_read_input_tokens": 0,
    "cache_creation_input_tokens": 0,
    "server_tool_use": {
      "web_fetch_requests": 1
    }
  }
}
```

Web fetchツールは、Claude APIで**追加コストなし**で利用できます。会話コンテキストの一部となる取得済みコンテンツに対して、標準のトークンコストのみをお支払いいただきます。

過剰なトークンを消費する大きなコンテンツを誤って取得してしまうことを防ぐため、`max_content_tokens`パラメータを使用して、ユースケースと予算の考慮事項に基づいた適切な制限を設定してください。

一般的なコンテンツにおけるトークン使用量の例：

* 平均的なウェブページ（10 kB）：約2,500トークン
* 大規模なドキュメントページ（100 kB）：約25,000トークン
* 研究論文のPDF（500 kB）：約125,000トークン

## 次のステップ

<CardGroup>
  <Card href="https://platform.claude.com/docs/ja/agents-and-tools/tool-use/code-execution-tool" title="コード実行ツール" icon="code">
    サンドボックス化されたコンテナでPythonとbashコードを実行し、データの分析、ファイルの生成、ソリューションの反復を行います。
  </Card>

  <Card href="https://platform.claude.com/docs/ja/agents-and-tools/tool-use/server-tools" title="サーバーツール" icon="cloud">
    Anthropicが実行するツールを扱います：server\_tool\_useブロック、pause\_turnの継続、ドメインフィルタリング。
  </Card>

  <Card href="https://platform.claude.com/docs/ja/agents-and-tools/tool-use/tool-reference" title="ツールリファレンス" icon="book">
    Anthropicが提供するツールの一覧と、オプションのツール定義プロパティのリファレンス。
  </Card>
</CardGroup>
