Skip to main content
Function calling lets a model choose structured tool calls that your application can execute. The model does not run the function itself. It returns the function name and arguments, your code runs the function, and you send the result back to the model. Use function calling when the model needs live data, application actions, database lookups, or deterministic calculations.

Basic Tool Definition

Define tools with the OpenAI-compatible tools array:

Execute the Tool

When the model chooses a tool, inspect message.tool_calls, parse the arguments, execute your application function, then send the result back as a tool message.
Python

Choose a Model

Function calling support is model-specific. Use the Text Models page or the Models API to find models with supportsFunctionCalling.
Treat tool arguments as untrusted input. Validate arguments before using them in database queries, shell commands, payments, or other side-effecting operations.

Design Tips

  • Keep tool names and descriptions short and literal.
  • Use JSON Schema to make valid arguments easy for the model to produce.
  • Prefer narrow tools with clear inputs over one broad tool with many optional behaviors.
  • Return concise tool results so the final answer has enough context without wasting tokens.