Course contentsShow
← AI Engineering
Lesson 545 of 1,88614. Function Calling and Tool UseFree lesson

OpenAI Function Calling API Structure

Exploring the anatomy of function definitions including name, description, and parameters schema in OpenAI's API.

OpenAI Function Calling API Structure

What you'll learn: How to define functions for OpenAI's API using the three essential components: name, description, and parameters schema.

The Anatomy of a Function Definition

When you want an LLM to call functions, you need to describe them in a way the model understands. OpenAI's function calling API requires a specific JSON structure with three core components:

1. Name

A simple string identifier for your function (e.g., "get_weather" or "search_database"). This is what the model will reference when deciding to call it.

2. Description

A plain-English explanation of what the function does. Think of this as documentation for the LLM—the clearer you are, the better it understands when to use the function. For example: "Retrieves current weather data for a given city".

3. Parameters Schema

A JSON Schema object defining what inputs the function expects. This includes:

  • Type: Usually "object" wrapping your parameters
  • Properties: Each parameter's name, type, and description
  • Required: Array of mandatory parameter names

The Pattern

Think of it like hiring someone over email. You tell them the task name ("get_weather"), explain what it does ("fetch weather info"), and specify exactly what information you need from them ("city name as a string, required"). The LLM uses this structured "job description" to decide if and how to call your function.

This structure lets the model understand both what your function does and how to use it correctly—without ever executing the code itself.

Key Takeaway: OpenAI function definitions require three parts—name (identifier), description (purpose), and parameters schema (input specification)—all in JSON format to help the model understand when and how to invoke your functions.