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

Making a Function Call Request

Sending chat completions with function definitions and interpreting the model's function call response.

Making a Function Call Request

What you'll learn: How to send a function-enabled chat completion request and interpret when the model wants to call your function.

The Complete Round-Trip

You've defined your functions using JSON Schema. Now it's time to actually send them to the model and see what comes back. Making a function call request involves including your function definitions in the messages payload, then checking if the model responds with a regular text message or a function call instruction.

Think of it like giving someone a Swiss Army knife along with a question. They might answer directly ("It's 72 degrees"), or they might hand you back the knife with instructions: "Use the thermometer tool, set location to 'Boston'."

The Request Structure

When you make a function-enabled request, you include:

  • Your conversation messages (system, user, assistant)
  • A functions parameter with your function definitions (from JSON Schema)
  • Optionally, a function_call parameter to control behavior ("auto", "none", or {"name": "specific_function"})

The Response: Two Possible Paths

The model's response will either contain:

  1. Regular content: Just text in message.content
  2. Function call: A function_call object with name and arguments (JSON string)

When you receive a function call response, the model is saying "I don't have the answer, but you should execute this function with these parameters." It's your job to actually run that function in your code, then send the result back in a new message.

Key Takeaway: A function call request sends both messages and function definitions; the model's response either answers directly or returns a structured function call instruction that you must execute and return.