# Tool calling

> Tool calling is when the model asks your code to run a named function, then reads the result.

The model asks your code to run a named function, then reads the result.

Track: Agents
Access: free
Card: https://buildsparkai.com/tool-calling
Plain text: https://buildsparkai.com/tool-calling.md
Last checked: 2026-10-18

## What it is

Tool calling is the model asking your code to run a named function, then reading what your code sends back. OpenAI's function calling guide lists the flow as a request with tools, a tool call from the model, execution on the application side, a second request with the tool output, and a final response or more tool calls. Gemini's function calling guide says the model does not execute the function itself. Anthropic's tool-use guide says the model emits a structured request, and for a client tool your code runs it and returns the result.

## Why it matters

**Cost.** OpenAI's function calling guide says callable function definitions count against the context limit and are billed as input tokens. The same guide then makes another request that includes the tool output. Anthropic's tool-use guide says every client tool call is at least one extra round trip. This card does not add a price.

**Quality.** The model can read the result only on the request that includes it. OpenAI's flow ends in a final response or more tool calls, not in the tool call itself. OpenAI's guide can require the tool call to match the function schema. That constrains the arguments, not the truth of the value your code returns.

**Risk.** Your code runs the function, so the model can ask for an action with a side effect. Anthropic's tool-use guide lists sending an email or writing a file as actions only a tool can perform. A function in the tools list is a function the model can name.

## Try today

Take one lookup you currently paste in by hand. Name it as a function with one argument, send it as a tool, and run the function in your own code before you send the result back.

## Common mistake

Reading a tool call as if the function had already run. OpenAI's guide puts execution on the application side. Gemini's guide says the model does not execute the function itself.

## Self-check

The model returns a tool call named get_close_time. Who runs that function?

Your code runs it, then you send the result back

## Practice and deep

Coming soon. One function you already run by hand, named and described for the model.

Coming soon. How OpenAI, Anthropic, and Gemini each attach a tool result to the next request.

## Sources

- [OpenAI, Function calling](https://developers.openai.com/api/docs/guides/function-calling)
- [Gemini API, Function calling](https://ai.google.dev/gemini-api/docs/function-calling)
- [Anthropic, How tool use works](https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works)

Opened 2026-10-18. Each page is vendor documentation. The card does not add a rate or a usage count.
