OpenAI has announced the release of its brand-new Function Calling Guide, designed to help developers extend the capabilities of OpenAI models by integrating custom tools and functions. Based on extensive user feedback, the guide has been revamped to be 50% shorter and clearer, featuring new best practices, in-doc function generation, and a fully functional example using a weather API. This update reflects OpenAI’s commitment to making AI tools more accessible and developer-friendly, empowering developers to leverage function calling more effectively in their applications.
announcing our brand new function calling guide @openai!
we heard your feedback and made some key changes:
– 50% shorter & clearer
– new best practices (more on this below 👇)
– in-doc function generation (!)
– fully-functional example w/ weather APIcheck it out and let me… pic.twitter.com/Id89E9PEff
— ilan bigio (@ilanbigio) January 13, 2025
How OpenAI Function Calling Works?
Function calling allows OpenAI models to interact with developer-defined tools, enabling them to perform tasks beyond generating text or audio. Here’s a simplified breakdown of the process:
- Define a Function: Create a function (e.g., get_weather) that the model can call.
- Model Decides to Call the Function: Based on the system prompt and user input, the model determines when to invoke the function.
- Execute the Function: Run the function code and return the results.
- Incorporate Results: The model uses the function’s output to generate its final response.

The image shows the process of how function calling works between a developer and an AI model. Here’s a step-by-step breakdown:
- Tool Definitions + Messages: The developer defines the tool (function) and sends a message. In this case, the get_weather(location) function is defined, and the user asks, “What’s the weather in Paris?”
- Tool Calls: The model recognizes that it needs to call the get_weather function with the argument “paris”.
- Execute Function Code: The developer (or system) executes the actual get_weather(“paris”) function. The function returns a response, e.g., {“temperature”: 14}.
- Results: The result from the function ({“temperature”: 14}) is returned to the model along with all prior messages.
- Final Response: The model uses the function result to generate a natural language response, such as “It’s currently 14°C in Paris.”
Also Read: Top 6 LLMs that Support Function Calling
A Quick Example: Weather API
Let’s walk through a real-world example using a get_weather function. This function retrieves the current temperature for a given set of coordinates.
Step 1: Define the Function
import requests
def get_weather(latitude, longitude):
response = requests.get(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m")
data = response.json()
return data['current']['temperature_2m']
Step 2: Call the Model with the Function Defined
from openai import OpenAI
import json
client = OpenAI(api_key="sk-api_key”)
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for provided coordinates in celsius.",
"parameters": {
"type": "object",
"properties": {
"latitude": {"type": "number"},
"longitude": {"type": "number"}
},
"required": ["latitude", "longitude"],
"additionalProperties": False
},
"strict": True
}
}]
messages = [{"role": "user", "content": "What's the weather like in Paris today?"}]
completion = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=tools,
)
Step 3: Execute the Function
tool_call = completion.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
result = get_weather(args["latitude"], args["longitude"])
Step 4: Supply the Results to the Model
# Append the model's tool call message
messages.append(completion.choices[0].message)
# Append the result message as a string
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": json.dumps({"temperature": result}) # Convert the result to a JSON string
})
# Create the second chat completion
completion_2 = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=tools,
)
Step 5: Get the Final Response
print(completion_2.choices[0].message.content)
Output:
The current temperature in Paris is -2.8°C.
Best Practices for Function Calling
To help you get the most out of function calling, here are some pro tips:
- Write Clear and Detailed Descriptions
- Clearly describe the purpose of the function, its parameters, and its output.
- Use the system prompt to guide the model on when (and when not) to use the function.
- Apply Software Engineering Best Practices
- Make functions intuitive and obvious.
- Use enums and object structures to prevent invalid states.
- Offload the Burden from the Model
- Don’t make the model fill arguments you already know.
- Combine functions that are always called in sequence.
- Keep the Number of Functions Small
- Aim for fewer than 20 functions at a time for higher accuracy.
- Leverage OpenAI Resources
- Use the Playground to generate and iterate on function schemas.
- Consider fine-tuning for complex tasks or large numbers of functions.
End Note
OpenAI’s revamped Function Calling Guide empowers developers to integrate custom tools seamlessly, making AI more accessible and practical. By simplifying processes, offering clear examples, and prioritizing user feedback, OpenAI enables developers to innovate and build solutions that harness the full potential of AI, driving real-world impact and creativity.