Forced function documentation typo

The documentation shows {"type": "function", "name": "get_weather"}

but it should be {"type": "function", "function": {"name": "get_weather"}}

as shown in the screenshot.

If you use the first one you get InvalidRequestError: Missing required parameter: 'tool_choice.function'.
Hope this saves someone some time chasing down the error!

https://platform.openai.com/docs/guides/function-calling?api-mode=responses

1 Like

Are you sure?

The original doc version works fine for me.

Responses example
select_model="gpt-4.1-mini"

tools = [{
    "type": "function",
    "name": "get_weather",
}]

input_messages = [{"role": "user", "content": "What's the weather like in Paris today?"}]

response = client.responses.create(
    model=select_model,
    input=input_messages,
    tools=tools,
)

print(response.output)

Perhaps you were trying to use completions, which would be as you proposed:

Completions example

from openai import OpenAI

client = OpenAI()

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get current temperature for a given location.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "City and country e.g. Bogotá, Colombia"
                }
            },
            "required": [
                "location"
            ],
            "additionalProperties": False
        },
        "strict": True
    }
}]

completion = client.chat.completions.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "What is the weather like in Paris today?"}],
    tools=tools
)

print(completion.choices[0].message.tool_calls)

There is a toggle on the page to select between Chat Completions and Responses.

However, the text in the image doesn’t change, making one of the selections factually incorrect, although the text right above it does switch.

2 Likes

I see, my mistake.

The image indeed remains unchanged, I only looked at the text.