Function Calling in the Gemini API
Pass functions as tools: the manual function_call → function_result loop with call_id in the Interactions API, automatic calling in SDK chats, history inspection, tool_choice modes and parallel calls.
What Is Function Calling
Function calling lets you describe functions and hand them to the model: it decides when and with what arguments to call them. The model doesn't run the function itself. It returns the name and arguments, and your code makes the call.
The Gemini API offers this in two interfaces:
- Interactions API (
client.interactions.create) — the primary API, which Google recommends for new projects. Functions are described with a JSON schema, and a call and its result are linked bycall_id. You run the call loop. - Chats on generateContent (
client.chats.create) — now legacy but still supported. Only here can the Python SDK call your functions for you (automatic function calling) and build the schema from the name, docstring and type annotations.
You need the google-genai SDK (pip install -U google-genai). The examples use gemini-4-hydrogen: it launched on 2026-11-12, is available on the free tier, and Google recommends it as the upgrade from Gemini 3.8 Flash and the 2.5 models. gemini-2.5-flash is deprecated; since 2026-12-01 requests to it are routed to gemini-3.5-flash-lite.
The rest of this lesson opens after a free sign-up
Sign up with email or Google: the first two lessons of every course stay open for good, and the whole catalog is open for 7 days. No card needed.


