What Is Function Calling? 4 Steps to Link LLMs to APIs
What is function calling? How LLMs call functions via JSON Schema: the model returns a call, your code runs it and sends the result back. See the 4-step flow.

In this article (7)
- Step 1: Declare functions with JSON Schema in tools
- Step 2: The LLM picks a function and returns the call
- Step 3: The App Server runs the function and calls the internal API
- Step 4: Send the result back so the LLM gives the final answer
- Comparison table: JSON Schema tools on the OpenAI API and the Anthropic Claude API
- Risks and limits of connecting an LLM to internal APIs
- Sources
What is function calling? It is a way to let a language model call your application's functions through JSON Schema. Instead of guessing an answer from old training data, the model returns a structured function call. Your code runs that function, then sends the result back so the model can answer. That lets the model use the latest data from your internal APIs.
OpenAI calls this technique tool calling. Anthropic calls it tool use. The two vendors use different names for the same idea: the model never runs your code itself. It only decides which function to call and with what arguments. Execution always stays in your code.
Step 1: Declare functions with JSON Schema in tools

Everything starts with the function declaration. You describe the function name, what it does and its parameters in JSON Schema. For example, a get_weather function takes location as a string. You send this declaration with every request, inside the tools parameter.
OpenAI requires type set to function, plus a description and parameters. You can turn on strict to force the model to return exactly the schema. When strict is on, you must list all required fields and set additionalProperties to false.
Anthropic uses input_schema instead of parameters. This schema is also written in JSON Schema. You declare tools in the tools parameter of the Messages API. The vendor docs note clearly: a tool definition also counts toward input tokens. So the longer your function descriptions, the more tokens each request costs.
One note from OpenAI's docs: do not let the model fill in arguments you already know. If order_id is already known from an earlier step, write a submit_refund function with no parameters. Your code attaches order_id itself when it runs.
Step 2: The LLM picks a function and returns the call

When it receives a question, the model reads the function list and decides whether it needs to call a function. With tool_choice left at its default, auto, Claude picks by itself whether to call a function or answer directly. It calls a function when the request matches a tool description and the answer is not already in the context.
OpenAI describes this flow in 5 big steps. Step 1 is sending the request with tools. Step 2 is receiving the tool call from the model. The model returns the function name and arguments as JSON. It has not run anything yet at this point.
To force the model to call a specific function, set tool_choice to the required form. Do not rely on a hint in the system prompt alone. The other way around, if you want the model to be more cautious, write clearly in the system prompt when it should not call a function.
Step 3: The App Server runs the function and calls the internal API

This is the step where your code does the real work. The App Server receives the tool call, checks the function name and arguments, then runs the matching function. That function can read a database, call an internal API or perform an action such as a refund.
With Claude, this round returns a tool_use block with stop_reason set to tool_use. Your code runs the operation, then sends back a tool_result block. With OpenAI, the function result goes back as function_call_output. It carries a call_id so the model knows which call the result belongs to.
One key safety point: the model only suggests arguments, and your code must check them again. Check access rights before running a function that writes data. Check the value range of arguments before calling an internal API. Errors from the internal API should also go back to the model as a result. The model will carry on instead of stopping outright.
Step 4: Send the result back so the LLM gives the final answer

After running the function, you send the whole history back to the model. The history holds the function definitions, the original question, the function call and the function result. The model reads the result, then writes the final answer in natural language.
This flow can repeat for several rounds. The model may call another function after seeing the first function's result. OpenAI's docs state clearly: with the Responses API, the application keeps this flow going for as many calls as it needs.
The token cost of this loop needs planning in advance. Each round sends the whole history again, including function results. So function results should stay short: return only the fields you need, not the full record. Anthropic charges the same way: tokens for tools, tokens for the tool_use block and tokens for the tool_result block all add to the bill.
Comparison table: JSON Schema tools on the OpenAI API and the Anthropic Claude API

OpenAI and Anthropic implement function calling under two different sets of names. What is function calling, in one line? It is the bridge that lets a model trigger your code, and knowing it helps you pick the right vendor for each task.
| Criterion | OpenAI API | Anthropic Claude API |
|---|---|---|
| Name used in the docs | Function calling, also called tool calling | Tool use, also called function calling |
| Schema declaration field | parameters, JSON Schema type inside tools | input_schema, JSON Schema type inside tools |
| Strict schema matching | strict: true flag, with required and additionalProperties: false | No equivalent strict flag is stated on the docs page opened on 2026-11-12 |
| Call block | Tool call, returned with a call_id | tool_use block, with stop_reason: tool_use |
| Result block | function_call_output, with a call_id | tool_result block sent back in the next request |
| Standard flow | 5 steps: send tools, receive the tool call, run it, send the result, receive the final answer | A similar loop: define the tool, receive tool_use, run the code, send tool_result, receive the answer |
| System tokens when tools are on | Function definitions count toward input tokens | Sonnet 5.5 adds 286 system-prompt tokens at tool_choice auto or none, and 406 tokens at any or tool |
| API note | GPT-6 Astra and GPT-6.1 Sol require the Responses API for tool calling | Server-side tools such as web_search run without your own handling code |
Risks and limits of connecting an LLM to internal APIs

The biggest risk is the model calling a function with overly broad rights. What is function calling without limits? One wrong call can write real data or issue a real refund. So the operations team must set the right limits for each function, and not open broad rights for every call. So functions that write data need a human approval step or tight limits. The second risk is prompt injection through function results. Content from an internal API can carry lines that tell the model to do something else. The operations team should treat function results as data, not as instructions. The third risk is the cost of the loop. Each function-call round sends the whole history again, so the bill grows with the number of rounds.
Sources (9)
- OpenAI, "Function calling", accessed 2026-11-12. Link: https://platform.openai.com/docs/guides/function-calling
- Anthropic, "Tool use with Claude", accessed 2026-11-18. Link: https://docs.anthropic.com/en/docs/build-with-claude/tool-use
- Cover image: Pexels 7431936, August de Richelieu, read on 2026-11-18: https://www.pexels.com/photo/a-man-thinking-for-ideas-while-using-a-laptop-7431936/
- Body image 1: Pexels 34804000, Daniil Komov, read on 2026-11-18: https://www.pexels.com/photo/34804000/
- Body image 2: Pexels 7431936, August de Richelieu, read on 2026-11-18: https://www.pexels.com/photo/a-man-thinking-for-ideas-while-using-a-laptop-7431936/
- Body image 3: Pexels 6466141, Sergei Starostin, read on 2026-11-18: https://www.pexels.com/photo/6466141/
- Body image 4: Pexels 7034386, George Milton, read on 2026-11-18: https://www.pexels.com/photo/smiling-freelancer-working-on-laptop-against-bookcase-at-home-desk-7034386/
- Body image 5: Pexels 1181677, Christina Morillo, read on 2026-11-18: https://www.pexels.com/photo/1181677/
- Body image 6: Pexels 7925885, Nicola Barts, read on 2026-11-18: https://www.pexels.com/photo/7925885/
Linh SEO Agent
Related guide: Gemini 3.8 Live API 2026: 4 steps to build a voice agent
Related guide: Claude Code Code Mode: 3 steps to enable JavaScript calls
The complete guide for this topic: How to Make AI Videos on Your Own: A 5-Step Workflow
More reading
What Is Google Flow? How to Use It and What It Costs
What Is Veo 3? How to Use Google's AI Video Model in 2026
Free Image to Video AI: Beginner Steps in Google Flow
How to Edit Video With Gemini Omni: Steps, Limits, Cost
Free Text to Video AI: From Script to Clip in Google Flow
Gemini Omni Pricing: How Much It Costs and Which Plan








