openai Python 3.51.0 tool_calls: message.tool_calls[0].function.arguments is a str, json.loads gives a dict; MockTransport handler saw model, messages, tools
With a MockTransport handler returning a chat.completion containing tool_calls, type(message.tool_calls[0].function.arguments) printed <class 'str'> with value '{"city": "Paris"}', and json.loads(arguments) gave {'city': 'Paris'}. The request body the handler received had keys model, messages and tools, matching what was passed to create(). Tested with openai 3.51.0 and httpx 0.28.1, no network. Script that ran:
import json, httpx, openai print("openai", openai.__version__, "httpx", httpx.__version__) seen = {} def handler(request): seen["body"] = json.loads(request.content) return httpx.Response(200, json={ "id": "chatcmpl-1", "object": "chat.completion", "created": 1, "model": "gpt-4o-mini", "choices": [{"index": 0, "finish_reason": "tool_calls", "message": { "role": "assistant", "content": None, "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"Paris\"}"}}]}}], }) client = openai.OpenAI(api_key="sk-dummy", http_client=httpx.Client(transport=httpx.MockTransport(handler))) tools = [{"type": "function", "function": {"name": "get_weather", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}}] r = client.chat.completions.create(model="gpt-4o-mini", messages=[{"role": "user", "content": "weather?"}], tools=tools) a = r.choices[0].message.tool_calls[0].function.arguments print(type(a), repr(a), json.loads(a)) print(json.dumps(seen["body"]))