Skip to content
InnovateTechie
Claude API

Claude Tool Use: Function Calling With the API

InnovateTechieBy InnovateTechie10 min read
Share
Claude Tool Use: Function Calling With the API

Part ofClaude AI Features: The Complete Overview

Claude tool use (function calling) lets Claude call tools you define via a JSON schema. The tool_use and tool_result loop, a worked example, and how it ties to MCP.

Claude tool use — also called function calling — lets Claude call external tools you define through a JSON schema. You describe a tool, Claude returns a structured tool_use request when a prompt matches it, your code runs the function, and you pass the result back as a tool_result for Claude's final answer.

Claude tool use is the foundation of every agent, chatbot, and automation we build on the Claude API. We use it daily on this site, and the mechanics are simpler than the "agent" hype suggests. Below: how the request/response loop works, how to define a tool, how Claude decides when to call one, a worked example, real use cases, and where Model Context Protocol (MCP) fits in.

What is Claude tool use?

Claude tool use is the feature that lets Claude Opus 4.8 (or any current Claude model) call functions instead of only writing text. You hand the model a list of tools — each a name, a description, and an input schema — and Claude decides, per turn, whether a tool would help answer the request. When it decides yes, it emits a structured call your application executes.

"Function calling" and "tool use" are the same thing. Function calling is the OpenAI-era name; tool use is Anthropic's term, and Anthropic's tool use documentation uses it throughout. If you have written OpenAI function-calling code, the concept transfers directly — only the field names change.

Tools split into two categories by where the code runs. Client tools run in your application: user-defined tools you write, plus Anthropic-schema tools like bash and text_editor. Server tools run on Anthropic's infrastructure — web_search, web_fetch, code_execution, and tool_search — and you get the results back without executing anything yourself.

Client toolsServer tools
Runs whereYour applicationAnthropic's servers
You execute?Yes — you return a tool_resultNo — result is in the response
ExamplesYour own functions, bash, text_editorweb_search, web_fetch, code_execution
Best forYour databases, internal APIs, actionsLive web data, sandboxed code, retrieval

New to the API entirely? Start with our Claude API getting-started guide, then come back — the rest of this assumes you can already send a basic message.

How the Claude tool use loop works

For a client tool, Claude never runs your code. It only asks you to, and the request/response loop has four steps:

  1. Send the request with a tools array and the user's message. Each tool carries its schema.
  2. Claude responds with stop_reason: "tool_use" and one or more tool_use content blocks. Each block has an id, the tool name, and an input object matching your schema.
  3. Your code executes the tool — query the database, hit the API, run the function — and builds a tool_result block referencing the original tool_use_id.
  4. Send the result back. Claude reads it and either answers (stop_reason: "end_turn") or calls another tool, repeating the loop.

Server tools collapse this: you declare the tool, and Anthropic runs the sampling loop and returns cited results in the same response, so there is no tool_result for you to build. Everything routes through one endpoint — POST /v1/messages — so tools are a feature of the Messages API, not a separate product.

Diagram of the Claude tool use loop — request with tools, tool_use block, client executes, tool_result returned, final answer

Defining a tool with a JSON schema

A tool definition is three fields: name, description, and input_schema (standard JSON Schema). The description is the most important part — Claude reads it to decide when to call the tool, so write it like a routing rule, not a code comment. Here is a Claude tools example for an order-lookup function:

{
  "name": "get_order_status",
  "description": "Look up the current status of a customer order by its ID. Use this whenever the user asks where an order is, whether it shipped, or for a delivery estimate.",
  "input_schema": {
    "type": "object",
    "properties": {
      "order_id": {
        "type": "string",
        "description": "The order ID, e.g. 'ORD-10432'"
      }
    },
    "required": ["order_id"]
  }
}

Pass that tool to the model and send a matching question:

import anthropic
 
client = anthropic.Anthropic()
response = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    tools=[get_order_status],
    messages=[{"role": "user", "content": "Where is order ORD-10432?"}],
)
print(response.stop_reason)  # "tool_use"

Claude returns a tool_use block with input of {"order_id": "ORD-10432"}. You run your real lookup, then reply with a tool_result carrying the shipping status, and Claude writes the final sentence to the customer. Two rules save hours of debugging: parse tool_use.input as real JSON (never string-match it), and if a tool fails, return a tool_result with is_error: true rather than dropping it — Claude will adapt.

How Claude decides to call a tool

By default, Claude uses judgment. With tool_choice set to auto, it calls a tool when the request maps to that tool's described capability and the answer is not already in context; it answers directly for stable knowledge, creative tasks, and plain conversation. You steer that boundary with the tool_choice parameter and with your system prompt.

tool_choiceBehavior
{"type": "auto"}Claude decides whether to call a tool (default)
{"type": "any"}Claude must call some tool, but picks which
{"type": "tool", "name": "..."}Claude must call the one named tool
{"type": "none"}Claude cannot call any tool

If Claude under-calls tools you expected it to use, the fix is usually the prompt, not the code. A light instruction such as "Use the tools to investigate before responding" raises tool use; sharper trigger conditions inside each tool's description help even more. Anthropic's engineering team wrote up the advanced tool use patterns we lean on when a model is too eager or too shy. You can also add strict: true to a tool so its inputs always validate against your schema exactly.

A worked example: from question to answer

Walk one full turn of Claude tool use, end to end. A user asks your support bot, "Did my order ORD-10432 ship, and what's the weather where it's headed?" You have defined two tools: get_order_status and get_weather.

  1. Claude reads both descriptions and returns two tool_use blocks in one response — parallel tool use is on by default.
  2. Your code runs both lookups concurrently: the order shipped to Denver; Denver is 41°F and clear.
  3. You return both tool_result blocks in a single user message (splitting them across messages quietly trains Claude to stop calling in parallel).
  4. Claude composes one grounded answer: "ORD-10432 shipped yesterday and is heading to Denver, where it's currently 41°F and clear."

No tool output ever gets summarized away — the model works from your exact data. That is the whole appeal: tool use turns Claude from a text generator into a system that reads live state and acts on it.

Real use cases for Claude API tools

We group Claude tool use into two jobs: looking things up (read) and taking actions (write). Read tools are safe to run automatically; write tools deserve a confirmation gate because they change the world.

Use caseCategoryExample tool
Order or account lookupData lookupget_order_status, get_account
Live web groundingData lookupweb_search (server tool)
Data analysis in a sandboxData lookupcode_execution (server tool)
Send an email or messageTake actionsend_email
Create a ticket or recordTake actioncreate_ticket
Book, cancel, or refundTake actionbook_appointment

Server tools cover the common read jobs out of the box. The web_search tool grounds answers in live web content beyond the training cutoff — the same capability behind Claude's web search on claude.ai — and code_execution runs Python in a sandbox for analysis. For anything specific to your business — your inventory, your CRM, your internal APIs — you write custom client tools. One hard limit worth stating plainly: Claude does not generate images, so image creation is never a tool you can hand it.

Diagram of Claude tool use use cases — read tools for data lookup and write tools for taking actions with a confirmation gate

How Claude tool use relates to MCP

Custom tools are perfect until you have fifty of them and want to share them across projects. That is the problem the Model Context Protocol solves. MCP is an open standard for packaging tools (and data sources) behind a server that any MCP-aware client can connect to — so instead of redefining a GitHub or database tool in every codebase, you point at an MCP server once.

Under the hood it is still Claude tool use. When Claude calls an MCP tool, you get the same tool_use/tool_result mechanics; MCP just standardizes the packaging and discovery. The Messages API even ships an MCP connector that lets Claude reach a remote MCP server directly, and Claude Code uses the same protocol — our Claude Code MCP guide covers that side. Think of it this way: raw tool use is how you define one capability; MCP is how you distribute many. Both underpin the broader Claude AI features that turn the model into an agent, from computer use to connectors.

The practical rule we follow: reach for a plain custom tool when a capability lives in one app, and reach for MCP when the same capability needs to be shared across teams or tools. Start with Claude tool use, graduate to MCP when the duplication hurts.

Claude pricing at a glance

PlanPrice
Free$0
Pro$20 / month
Maxfrom $100 / month
APIPay per token

For the full breakdown of every plan, see our how much Claude costs guide.

Frequently Asked Questions

Tool use lets Claude call external tools and APIs you define to fetch data or take actions, rather than only generating text. You describe each tool with a name, description, and JSON schema; Claude emits a structured request when a prompt matches, your code runs it, and the result flows back for a grounded final answer.

Claude emits a structured tooluse request with a stopreason of tooluse. Your code (for client tools) or Anthropic's servers (for server tools) execute it, and the result returns as a toolresult block. Claude reads that result and either answers or calls another tool, looping until done.

They are interchangeable terms for the same Anthropic feature. "Function calling" is the OpenAI-era name that stuck across the industry; "tool use" is Anthropic's term and the one used throughout the Claude API and docs. If you know function calling from other platforms, the concept transfers directly — only the field names differ.

Client tools — your own functions, plus Anthropic-schema tools like bash and texteditor — run inside your application, and you return the result. Server tools like websearch, webfetch, and codeexecution run on Anthropic's infrastructure, so you see the results directly without executing anything yourself.

Use the toolchoice parameter. {"type": "auto"} lets Claude decide, {"type": "any"} forces it to call some tool, and {"type": "tool", "name": "..."} forces one named tool. Set {"type": "none"} to block tools entirely for a turn. Auto is the default and right for most cases.

With toolchoice of auto, Claude calls a tool when the request maps to that tool's described capability and the answer is not already in context. It answers directly for stable knowledge, creative work, and conversation. A clear, trigger-focused tool description is the single biggest lever on this decision.

Many tools are free on claude.ai within plan rate limits. On the API, Claude tool use is billed per token — the tool schemas, tooluse blocks, and toolresult blocks all count as input or output tokens. Server tools like web search add usage-based charges on top, such as a per-search fee.
InnovateTechie

Written by

InnovateTechie

Writing about Claude and the Anthropic toolkit — models, Claude Code, pricing, features, and fixes, in clear, practical, hands-on guides tested by daily use.

View all posts →