Skip to main content

Chat - Function Calling

Enable the model to call external functions by providing a tools array. The model will generate structured JSON input for the function instead of a text response.
For more details, see the OpenAI Function Calling Guide.

Request

Headers

Request Body

Example Request

Python Example

Response

When the model decides to call a function, the response will contain tool_calls instead of a text content:
The finish_reason will be tool_calls when the model wants to call a function. Execute the function yourself, then send the result back in a new message with role: "tool".