Loading...
    • 開発者ガイド
    • API リファレンス
    • MCP
    • リソース
    • リリースノート
    Search...
    ⌘K

    はじめの一歩

    Claudeの紹介クイックスタート

    モデルと料金

    モデル概要モデルの選択Claude 4.5の新機能Claude 4.5への移行モデルの廃止予定価格設定

    Claudeで構築する

    機能概要Messages API の使用コンテキストウィンドウプロンプトのベストプラクティス

    機能

    プロンプトキャッシングコンテキスト編集拡張思考ストリーミングメッセージバッチ処理引用多言語サポートトークンカウント埋め込みビジョンPDFサポートFiles API検索結果Google Sheetsアドオン

    ツール

    概要ツール使用の実装方法トークン効率的なツール使用細粒度ツールストリーミングBashツールコード実行ツールコンピュータ使用ツールテキストエディタツールWeb fetch toolウェブ検索ツールメモリツール

    エージェントスキル

    概要クイックスタートスキル作成のベストプラクティスAPIでエージェントスキルを使用する

    Agent SDK

    概要Agent SDK リファレンス - TypeScriptPython SDK

    ガイド

    ストリーミング入力権限の処理セッション管理Agent SDKのホスティングシステムプロンプトの変更SDK内のMCPカスタムツールSDKにおけるサブエージェントSDKでのスラッシュコマンドSDK内のエージェントスキルコストと使用量の追跡Todo リストSDK のプラグイン

    API内のMCP

    MCPコネクタリモートMCPサーバー

    Claude on 3rd-party platforms

    Amazon BedrockVertex AI

    プロンプトエンジニアリング

    概要プロンプトジェネレータープロンプトテンプレートの使用プロンプト改善ツール明確で直接的な指示例(マルチショットプロンプト)を使用してClaudeの動作を導くClaudeに考えさせる(CoT)XMLタグを使用Claudeに役割を与える(システムプロンプト)Claudeの応答を事前入力複雑なプロンプトのチェーン化長文コンテキストのヒント拡張思考のヒント

    テストと評価

    成功基準を定義するテストケースを開発する評価ツールの使用レイテンシの削減

    ガードレールを強化

    幻覚を減らす出力の一貫性を高めるジェイルブレイクの軽減handle-streaming-refusalsプロンプトリークの削減Claudeのキャラクターを維持

    管理とモニタリング

    Admin API概要使用量とコストAPIClaude Code Analytics API
    Console
    ツール

    Claudeでのツール使用

    Claudeはツールや関数と相互作用する能力があり、Claudeの機能を拡張してより幅広いタスクを実行できます。

    新しいコースの一部として、Claudeでのツール使用をマスターするために必要なすべてを学びましょう!このフォームを使用してアイデアや提案を共有し続けてください。

    Messages APIを使用してClaudeにツールを提供する方法の例を以下に示します:

    Shell
    curl https://api.anthropic.com/v1/messages \
      -H "content-type: application/json" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -d '{
        "model": "claude-sonnet-4-5",
        "max_tokens": 1024,
        "tools": [
          {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
              "type": "object",
              "properties": {
                "location": {
                  "type": "string",
                  "description": "The city and state, e.g. San Francisco, CA"
                }
              },
              "required": ["location"]
            }
          }
        ],
        "messages": [
          {
            "role": "user",
            "content": "What is the weather like in San Francisco?"
          }
        ]
      }'
    Python
    import anthropic
    
    client = anthropic.Anthropic()
    
    response = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        tools=[
            {
                "name": "get_weather",
                "description": "Get the current weather in a given location",
                "input_schema": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA",
                        }
                    },
                    "required": ["location"],
                },
            }
        ],
        messages=[{"role": "user", "content": "What's the weather like in San Francisco?"}],
    )
    print(response)
    TypeScript
    import { Anthropic } from '@anthropic-ai/sdk';
    
    const anthropic = new Anthropic({
      apiKey: process.env.ANTHROPIC_API_KEY
    });
    
    async function main() {
      const response = await anthropic.messages.create({
        model: "claude-sonnet-4-5",
        max_tokens: 1024,
        tools: [{
          name: "get_weather",
          description: "Get the current weather in a given location",
          input_schema: {
            type: "object",
            properties: {
              location: {
                type: "string",
                description: "The city and state, e.g. San Francisco, CA"
              }
            },
            required: ["location"]
          }
        }],
        messages: [{ 
          role: "user", 
          content: "Tell me the weather in San Francisco." 
        }]
      });
    
      console.log(response);
    }
    
    main().catch(console.error);
    Java
    import java.util.List;
    import java.util.Map;
    
    import com.anthropic.client.AnthropicClient;
    import com.anthropic.client.okhttp.AnthropicOkHttpClient;
    import com.anthropic.core.JsonValue;
    import com.anthropic.models.messages.Message;
    import com.anthropic.models.messages.MessageCreateParams;
    import com.anthropic.models.messages.Model;
    import com.anthropic.models.messages.Tool;
    import com.anthropic.models.messages.Tool.InputSchema;
    
    public class GetWeatherExample {
    
        public static void main(String[] args) {
            AnthropicClient client = AnthropicOkHttpClient.fromEnv();
    
            InputSchema schema = InputSchema.builder()
                    .properties(JsonValue.from(Map.of(
                            "location",
                            Map.of(
     "type", "string",
     "description", "The city and state, e.g. San Francisco, CA"))))
                    .putAdditionalProperty("required", JsonValue.from(List.of("location")))
                    .build();
    
            MessageCreateParams params = MessageCreateParams.builder()
                    .model(Model.CLAUDE_OPUS_4_0)
                    .maxTokens(1024)
                    .addTool(Tool.builder()
                            .name("get_weather")
                            .description("Get the current weather in a given location")
                            .inputSchema(schema)
                            .build())
                    .addUserMessage("What's the weather like in San Francisco?")
                    .build();
    
            Message message = client.messages().create(params);
            System.out.println(message);
        }
    }

    ツール使用の仕組み

    Claudeは2種類のツールをサポートしています:

    1. クライアントツール:あなたのシステム上で実行されるツールで、以下が含まれます:

      • あなたが作成・実装するユーザー定義のカスタムツール
      • コンピューター使用やテキストエディターなどのAnthropicが定義したツールで、クライアント実装が必要なもの
    2. サーバーツール:ウェブ検索やウェブフェッチツールなど、Anthropicのサーバー上で実行されるツール。これらのツールはAPIリクエストで指定する必要がありますが、あなたの側での実装は不要です。

    Anthropicが定義したツールは、モデルバージョン間での互換性を確保するためにバージョン付きタイプ(例:web_search_20250305、text_editor_20250124)を使用します。

    クライアントツール

    以下の手順でクライアントツールをClaudeと統合します:

    1. 1

      Claudeにツールとユーザープロンプトを提供

      • APIリクエストで名前、説明、入力スキーマを含むクライアントツールを定義します。
      • これらのツールが必要になる可能性のあるユーザープロンプトを含めます(例:「サンフランシスコの天気はどうですか?」)
    2. 2

      Claudeがツールの使用を決定

      • Claudeはユーザーのクエリに対してツールが役立つかどうかを評価します。
      • 役立つ場合、Claudeは適切にフォーマットされたツール使用リクエストを構築します。
      • クライアントツールの場合、APIレスポンスのstop_reasonがtool_useになり、Claudeの意図を示します。
    3. 3

      ツールを実行して結果を返す

      • Claudeのリクエストからツール名と入力を抽出
      • あなたのシステム上でツールコードを実行
      • tool_resultコンテンツブロックを含む新しいuserメッセージで結果を返す
    4. 4

      Claudeがツール結果を使用してレスポンスを作成

      • Claudeはツール結果を分析して、元のユーザープロンプトに対する最終的なレスポンスを作成します。

    注意:手順3と4はオプションです。一部のワークフローでは、Claudeのツール使用リクエスト(手順2)だけで十分で、結果をClaudeに送り返す必要がない場合があります。

    サーバーツール

    サーバーツールは異なるワークフローに従います:

    1. 1

      Claudeにツールとユーザープロンプトを提供

      • ウェブ検索やウェブフェッチなどのサーバーツールには、独自のパラメータがあります。
      • これらのツールが必要になる可能性のあるユーザープロンプトを含めます(例:「AIに関する最新ニュースを検索して」や「このURLのコンテンツを分析して」)
    2. 2

      Claudeがサーバーツールを実行

      • Claudeはサーバーツールがユーザーのクエリに役立つかどうかを評価します。
      • 役立つ場合、Claudeはツールを実行し、結果が自動的にClaudeのレスポンスに組み込まれます。
    3. 3

      Claudeがサーバーツール結果を使用してレスポンスを作成

      • Claudeはサーバーツール結果を分析して、元のユーザープロンプトに対する最終的なレスポンスを作成します。
      • サーバーツールの実行には追加のユーザーインタラクションは必要ありません。

    ツール使用の例

    様々なツール使用パターンと技術を実演するコード例をいくつか紹介します。簡潔にするため、ツールはシンプルなツールで、ツールの説明は最高のパフォーマンスを確保するために理想的な長さよりも短くしています。


    価格

    Tool use requests are priced based on:

    1. The total number of input tokens sent to the model (including in the tools parameter)
    2. The number of output tokens generated
    3. For server-side tools, additional usage-based pricing (e.g., web search charges per search performed)

    Client-side tools are priced the same as any other Claude API request, while server-side tools may incur additional charges based on their specific usage.

    The additional tokens from tool use come from:

    • The tools parameter in API requests (tool names, descriptions, and schemas)
    • tool_use content blocks in API requests and responses
    • tool_result content blocks in API requests

    When you use tools, we also automatically include a special system prompt for the model which enables tool use. The number of tool use tokens required for each model are listed below (excluding the additional tokens listed above). Note that the table assumes at least 1 tool is provided. If no tools are provided, then a tool choice of none uses 0 additional system prompt tokens.

    ModelTool choiceTool use system prompt token count
    Claude Opus 4.1auto, none
    any, tool
    346 tokens
    313 tokens
    Claude Opus 4auto, none
    any, tool
    346 tokens
    313 tokens
    Claude Sonnet 4.5auto, none
    any, tool
    346 tokens
    313 tokens
    Claude Sonnet 4auto, none
    any, tool
    346 tokens
    313 tokens
    Claude Sonnet 3.7 (deprecated)auto, none
    any, tool
    346 tokens
    313 tokens
    Claude Haiku 4.5auto, none
    any, tool
    346 tokens
    313 tokens
    Claude Haiku 3.5auto, none
    any, tool
    264 tokens
    340 tokens
    Claude Opus 3 (deprecated)auto, none
    any, tool
    530 tokens
    281 tokens
    Claude Sonnet 3auto, none
    any, tool
    159 tokens
    235 tokens
    Claude Haiku 3auto, none
    any, tool
    264 tokens
    340 tokens

    These token counts are added to your normal input and output tokens to calculate the total cost of a request.

    現在のモデル別価格については、モデル概要表をご参照ください。

    ツール使用プロンプトを送信する場合、他のAPIリクエストと同様に、レスポンスは報告されるusageメトリクスの一部として入力トークンと出力トークンの両方のカウントを出力します。


    次のステップ

    クックブックで、すぐに実装できるツール使用コード例のリポジトリを探索してください:

    計算機ツール

    精密な数値計算のためにシンプルな計算機ツールをClaudeと統合する方法を学びます。

    カスタマーサービスエージェント

    クライアントツールを活用してサポートを強化する応答性の高いカスタマーサービスボットを構築します。

    JSON抽出器

    Claudeとツール使用が非構造化テキストから構造化データを抽出する方法をご覧ください。

      © 2025 ANTHROPIC PBC

      Products

      • Claude
      • Claude Code
      • Max plan
      • Team plan
      • Enterprise plan
      • Download app
      • Pricing
      • Log in

      Features

      • Claude and Slack
      • Claude in Excel

      Models

      • Opus
      • Sonnet
      • Haiku

      Solutions

      • AI agents
      • Code modernization
      • Coding
      • Customer support
      • Education
      • Financial services
      • Government
      • Life sciences

      Claude Developer Platform

      • Overview
      • Developer docs
      • Pricing
      • Amazon Bedrock
      • Google Cloud’s Vertex AI
      • Console login

      Learn

      • Blog
      • Catalog
      • Courses
      • Use cases
      • Connectors
      • Customer stories
      • Engineering at Anthropic
      • Events
      • Powered by Claude
      • Service partners
      • Startups program

      Company

      • Anthropic
      • Careers
      • Economic Futures
      • Research
      • News
      • Responsible Scaling Policy
      • Security and compliance
      • Transparency

      Help and security

      • Availability
      • Status
      • Support center

      Terms and policies

      • Privacy policy
      • Responsible disclosure policy
      • Terms of service: Commercial
      • Terms of service: Consumer
      • Usage policy

      Products

      • Claude
      • Claude Code
      • Max plan
      • Team plan
      • Enterprise plan
      • Download app
      • Pricing
      • Log in

      Features

      • Claude and Slack
      • Claude in Excel

      Models

      • Opus
      • Sonnet
      • Haiku

      Solutions

      • AI agents
      • Code modernization
      • Coding
      • Customer support
      • Education
      • Financial services
      • Government
      • Life sciences

      Claude Developer Platform

      • Overview
      • Developer docs
      • Pricing
      • Amazon Bedrock
      • Google Cloud’s Vertex AI
      • Console login

      Learn

      • Blog
      • Catalog
      • Courses
      • Use cases
      • Connectors
      • Customer stories
      • Engineering at Anthropic
      • Events
      • Powered by Claude
      • Service partners
      • Startups program

      Company

      • Anthropic
      • Careers
      • Economic Futures
      • Research
      • News
      • Responsible Scaling Policy
      • Security and compliance
      • Transparency

      Help and security

      • Availability
      • Status
      • Support center

      Terms and policies

      • Privacy policy
      • Responsible disclosure policy
      • Terms of service: Commercial
      • Terms of service: Consumer
      • Usage policy
      © 2025 ANTHROPIC PBC