Course contentsShow
← Machine Learning and Deep Learning
Lesson 1924 of 3,53841. Structured Output and Tool CallingFree lesson

OpenAI Function Calling API

Using the OpenAI Chat Completions API with functions parameter to enable tool use.

OpenAI Function Calling API

You'll learn how to use OpenAI's Chat Completions API with the functions parameter to enable structured tool use in LLM applications.

What is the OpenAI Function Calling API?

The OpenAI Function Calling API extends the standard Chat Completions endpoint by adding a functions parameter. Instead of just generating text, the model can recognize when it should call an external function and return a structured JSON object containing the function name and its arguments. Think of it as teaching the LLM to recognize situations where it needs help from external tools—like a smart assistant knowing when to hand off tasks to specialists.

How It Works in Practice

When you make an API call, you provide:

  1. Your conversation messages (system, user, assistant)
  2. A list of function definitions (schemas) the model can choose from
  3. Optionally, a function_call parameter to control behavior

The API returns either a normal text response OR a special response indicating which function to call with what arguments. Your application then executes that function and feeds the result back into the conversation.

Key Elements

Function definitions follow the JSON Schema format you learned earlier—specifying function names, descriptions, and parameter schemas. The model uses these to decide if and when a function should be invoked.

The API doesn't execute functions—it only returns instructions. You handle the actual execution in your code, maintaining full control over what happens.

Key Takeaway: The OpenAI Function Calling API bridges LLM reasoning with external tools by letting models request structured function calls through the functions parameter, returning parseable JSON arguments instead of free-form text.