Function Calling & Tool Execution: Connecting LLMs to APIs and Databases
Function calling is an API capability where an LLM inspects user requests against a provided list of programming tools and outputs structured JSON arguments to invoke external functions, databases, or web scrapers.
Overview #
Function calling is an API capability where an LLM inspects user requests against a provided list of programming tools and outputs structured JSON arguments to invoke external functions, databases, or web scrapers.
The Mechanics of Function Calling #
Models do not execute code directly on the server; instead, they output structured parameters for your application to execute safely:
- Client provides function schemas in JSON Schema format.
- Model evaluates whether the prompt requires an external tool.
- Model returns a message with
tool_callscontaining the function name and parsed JSON arguments. - Your application runs the function and submits the result back with
role: 'tool'. - Model summarizes the final answer for the user.
Frequently Asked Questions #
Q: Does the AI model execute the code during function calling?
No. The AI model generates the structured function name and argument parameters. Your application executes the code in your own secure environment and passes the result back to the model.
Build with API100
Access 100+ AI models through one lightning-fast OpenAI-compatible API with sub-50ms routing overhead and zero markup on cached tokens.

