Guides
Tool use (function calling) with Claude
Define tools with a JSON Schema, let the model decide when to call them, and send tool results back in the next turn. Complete round-trip example over the SubToAPI conversation endpoint.
Updated
Tools let the model ask your code to do something — look up an order, query a database, call a weather API — and continue with the result. You stay in control: the model only *requests* a call; your backend executes it.
1. Define tools
Each tool has a name, an optional description and an input_schema (JSON Schema, type: "object"). Up to 50 tools per request. Good descriptions matter more than clever schemas.
2. Read the tool_use block
When the model wants a tool, the response contains a tool_use block with an id, the tool name and parsed input, and stop_reason is "tool_use".
3. Run it and send the result back
Append the assistant turn exactly as received, then a user turn with a tool_result block referencing the same tool_use_id. Send the whole thread again; the model now answers with the information.
Controlling tool choice
{ "type": "auto" }— the model decides (default).{ "type": "any" }— the model must call some tool.{ "type": "tool", "name": "get_weather" }— force one specific tool; ideal for structured extraction.{ "type": "none" }— tools are visible but must not be called.
Validate inputs
Treat input like any untrusted request body: validate against your schema before executing anything with side effects.
Frequently asked questions
- Can the model call several tools at once?
- Yes — the response can contain multiple
tool_useblocks. Return onetool_resultper block in the next user turn. - Is tool use available on every model?
- Yes, on
fast,balancedandbest. Usebalancedorbestwhen tool selection needs judgement.