Function calling only works in Playground not SDK

I’m having an issue where the tools calling only works in the platform but not in the Python SDK. Given the same prompt and input, in the SDK i’m getting a response from the bot and in the platform I’m getting the correct output for function calling.

Below is my code and function definition and the message that I used to test both on Playground and SKD is “How’s my nutrition and sleep?”

EDIT: I’m using the same parameters for both SDK and Playground (model, temperature, tools=auto)

COACHING_TOOLS = [
    {
        "type": "function",
        "name": "get_nutrition_data_by_user_and_date_range",
        "description": "Retrieves nutrition data for a user within a specified date range.",
        "strict": True,
        "parameters": {
            "type": "object",
            "properties": {
                "start_timestamp": {
                    "type": "string",
                    "format": "date-time",
                    "description": "The start timestamp for the date range (ISO 8601 format). If no date specified in user message leave this field empty to retrieve data for the last 7 days."
                },
                "end_timestamp": {
                    "type": "string",
                    "format": "date-time",
                    "description": "The end timestamp for the date range (ISO 8601 format). If no date specified in user message leave this field empty to retrieve data for the last 7 days."
                }
            },
            "required": [
                "start_timestamp",
                "end_timestamp"
            ],
            "additionalProperties": False
        }
    },
{
        "type": "function",
        "name": "get_sleep_data_by_user_and_date_range",
        "description": "Retrieves sleep and recovery data for a user within a specified date range.",
        "strict": True,
        "parameters": {
            "type": "object",
            "properties": {
                "start_timestamp": {
                    "type": "string",
                    "format": "date-time",
                    "description": "The start timestamp for the date range (ISO 8601 format). If no date specified in user message leave this field empty to retrieve data for the last 7 days."
                },
                "end_timestamp": {
                    "type": "string",
                    "format": "date-time",
                    "description": "The end timestamp for the date range (ISO 8601 format). If no date specified in user message leave this field empty to retrieve data for the last 7 days."
                }
            },
            "required": [
                "start_timestamp",
                "end_timestamp"
            ],
            "additionalProperties": False
        }
    }
]

response = client.responses.create(
            model="gpt-4.1",
            temperature=0.5,
            tool_choice="auto",
            input=conversation_messages,
            tools=COACHING_TOOLS,
        )

Output from platform:

Output from SDK:
[ResponseOutputMessage(id=‘msg_6861490192a481a2898aedde3206623d06adad9ab2ad6c28’, content=[ResponseOutputText(annotations=, t…in mind. How can I assist you today?', type=‘output_text’, logprobs=)], role=‘assistant’, status=‘completed’, type=‘message’)]

What code do you that handles the tool call?

If I’m setting the tool_choice=‘required’ this code below works and the model is using the tools.

 tool_calls = response.output
        if tool_calls:
            for tool_call in tool_calls:
                print("Requesting function call: " + tool_call.name)
                if tool_call.type != "function_call":
                    continue

                name = tool_call.name
                args = json.loads(tool_call.arguments)

I don’t want to use tool_choice=‘required’ because there are a lot of instances where there’s no need for tools in my use case

The AI is wondering how it can assist.

Either the latest user input is not asking anything targeted, or the user input is not being received within your “conversation_messages”.

Review the construction of your chat history and the addition of the speculative new input to that, by logging the value of conversation_messages right before this API call, and see if you actually have “user” asking something that “tools” will be a useful solution for the AI to employ.

I checked both of these and everything seems correct. The only difference is when I set the tool_choice=‘required’ it asks for the correct tool if my messages ask for either nutrition or sleep or both. If the tool_choice is auto, then no tools is asked for. My input is super obvious → “How is my nutrition?”, “How is my sleep?”

EDIT: You were right. I was not sending my message to the SDK. Now everything works fine