How do parallel tool calls and tool_choice work in the Claude API?

Day 4, 25 minutes · beginner

Goal of this lessonHandle several tool calls in one response, send all results back in one message, and steer tool use with the tool_choice setting.

Why it matters

Real customers ask more than one thing at a time: "Do you have a peace lily and a pothos, what do they cost, and are you open on Saturday?" That is five lookups. If Claude asked for them one by one, the customer would wait for five round trips. Claude can ask for all of them in one response instead, and your code can answer them all at once.

Today you handle several tool calls in one response and learn the one formatting rule that keeps this working. You also try the tool_choice setting in its different forms, including one that the newest models refuse. At the end you have a script that answers a five-part question and a short table of what each setting did.

Parallel tool calls

The docs call this parallel tool use: one response with several tool_use blocks. It is on by default. Your code then has to:

  1. Go through every tool_use block in response.content, not just the first one.
  2. Run each tool. The order is up to you. The docs say independent lookups that only read data are usually safe to run at the same time. Tools that change something, or that depend on each other, are better run one after the other.
  3. Send all results back in one user message, one tool_result per call, each with its own tool_use_id.

Rule 3 is the one people get wrong. A separate user message for each result looks tidy, but the docs say it "teaches" Claude to stop making parallel calls. Wrong and right, in short:

Wrong: assistant [call 1, call 2]  user [result 1]  user [result 2]
Right: assistant [call 1, call 2]  user [result 1, result 2]

If you decide not to run one of the calls, for example because an earlier one failed, you still send a tool_result for it, with is_error set to true and a short reason.

The four kinds of tool_choice

tool_choice says how Claude may use your tools:

Setting What Claude does
{"type": "auto"} decides for itself whether to call a tool. The default when you send tools
{"type": "none"} does not use any tool. The default when you send no tools
{"type": "any"} must use one of your tools, its choice which
{"type": "tool", "name": "get_price"} must use that one tool

Two details:

  • disable_parallel_tool_use goes inside tool_choice, not at the top of the request. With auto it means at most one tool per response; with any or tool it means exactly one. Set it on the request whose response holds the tool calls: setting it later has no effect on calls that were already made.
  • Forcing a tool is not supported on every model. The docs say Claude Opus 5.5, Claude Sonnet 5.5 and Claude Fable 5.2 (among others) answer any and tool with a 400 error: tool_choice: type "tool" and "any" are not supported for this model. Claude Haiku 5.5 accepts them. On the models that refuse, the docs advise auto, together with strict tool use (lesson 5) when you need inputs that always match the schema.

When you force a tool, Claude's response starts straight with the tool call, without a sentence before it. If you want Claude to explain itself and still use a certain tool, the docs suggest auto plus a plain instruction in your message, such as "Use the get_price tool."

Nudging instead of forcing

With auto, you can still steer. The docs give example lines for the system prompt: "Use the tools to investigate before responding." makes Claude use tools more readily; "Use your judgment about whether to call a tool or respond directly." keeps it more careful. For more parallel calls, a line asking Claude to call independent tools at the same time helps.

The steps

  1. Create several_tools.py: one question with five parts, all tool calls of the response handled in one go, all results in one user message.
  2. Run it and count the tool calls.
  3. Switch off parallel calls and run it again.
  4. Try none: no tools at all.
  5. Try any on Claude Opus 5.5 and read the 400 error, then on Claude Haiku 5.5.

Follow the steps below.

Today's actions

Ticks are not saved without an account

Do it in Claude API

Claude API

  1. Open a terminal in your copperleaf-tools folder and turn on the virtual environment as in lesson 2.
  2. Create several_tools.py with this code. It runs every tool call of the first response and sends all results back together in one user message.
    from dotenv import load_dotenv
    import anthropic
    from shop import run_tool
    from tools import TOOLS
    
    load_dotenv()
    client = anthropic.Anthropic()
    
    MODEL = "claude-opus-5-5"
    TOOL_CHOICE = {"type": "auto"}
    QUESTION = "Do you have a peace lily and a pothos, what do they cost, and are you open on Saturday?"
    
    messages = [{"role": "user", "content": QUESTION}]
    try:
        response = client.messages.create(
            model=MODEL, max_tokens=1024, tools=TOOLS, tool_choice=TOOL_CHOICE, messages=messages
        )
    except anthropic.BadRequestError as e:
        raise SystemExit(f"400 error: {e}")
    
    calls = [b for b in response.content if b.type == "tool_use"]
    print(f"stop_reason: {response.stop_reason}, tool calls in this response: {len(calls)}")
    
    if calls:
        results = []
        for call in calls:
            output = run_tool(call.name, call.input)
            print(f"  {call.name}({call.input}) -> {output}")
            results.append({"type": "tool_result", "tool_use_id": call.id, "content": output})
        messages.append({"role": "assistant", "content": response.content})
        messages.append({"role": "user", "content": results})  # all results in ONE message
        response = client.messages.create(
            model=MODEL, max_tokens=1024, tools=TOOLS, messages=messages
        )
        print("second stop_reason:", response.stop_reason)
    
    print("".join(b.text for b in response.content if b.type == "text"))
  3. Run python several_tools.py. Claude usually asks for several tools in one response; the first line says how many. Then you see each call with its result and the final answer.
  4. Change the TOOL_CHOICE line to TOOL_CHOICE = {"type": "auto", "disable_parallel_tool_use": True} and run it again. Now the first response has one tool call, and the second response may ask for more tools instead of answering.
  5. Change it to TOOL_CHOICE = {"type": "none"} and run it. Claude calls no tool and answers in text, without Margriet's data.
  6. Change it to TOOL_CHOICE = {"type": "any"} and run it. With claude-opus-5-5 the script prints a 400 error that says "tool" and "any" are not supported for this model.
  7. Keep any and change the MODEL line to MODEL = "claude-haiku-5-5". Run it: Haiku accepts forced tool use, and the first response starts straight with a tool call. Put MODEL and TOOL_CHOICE back and fill in your table.

Note: The second request in the script always uses the default tool_choice, so Claude can answer in text after the tools ran. Forced tool use also fails on claude-sonnet-5-5 and claude-fable-5-2.

Paid planPay as you go: buy prepaid credits in the Claude Console (minimum 5 US dollars). There is no free tier. Max, Ultra and Team plans include monthly API credits.

Checked on 4 December 2026 · Source: Claude API docs: Parallel tool use (opens in a new tab)

Create a free account to save your progress. Sign in or sign up