tools format for most text models, so switching models only means changing model.
Which endpoint each model needs
Results from October 14, 2026, running the same weather function through a full call → result → final answer round trip:
Use Chat Completions for models marked ”—”, and whenever you’re unsure. Use Responses for the GPT-6 family. Gemini also supports
functionDeclarations in native generateContent; see the Gemini protocol.
Chat Completions example
Install the SDK (python -m pip install openai) and set the LAOZHANG_API_KEY environment variable first.
message.tool_calls in the first reply holds the function name and its arguments as a JSON string. The second request sends back the model’s message plus one tool message per call, and each tool_call_id must match the id of its call.
To use another model from the Chat Completions column, change MODEL; nothing else changes. For gpt-6-sol, also pass reasoning_effort="none" in both requests, or the API returns 400.
Responses example
In Responses, a tool definition drops the nestedfunction object, and results go back as function_call_output items:
Send history back to Responses
Rebuild eachfunction_call item from its call_id, name, and arguments, as the example does. Don’t rely on conversation state stored on the server:
- Don’t continue with
previous_response_id. - Don’t paste the first response’s
outputback intoinputunchanged.
The requested item was created under a different Azure OpenAI resourcePrevious response with id '...' not found
FAQ
Why does gpt-6.1-sol return 400 when I pass tools?
OpenAI doesn’t allow function tools together with reasoning in Chat Completions for gpt-6.1-sol, and this model doesn’t accept reasoning_effort: "none". Call it through Responses as shown above.
What if the model returns several function calls at once?
Run each one and send each result back with its owntool_call_id (Chat Completions) or call_id (Responses). Both examples above already loop over every call.
What if the arguments aren’t valid JSON?
Validate them withjson.loads. If parsing fails, send the error back as the function result so the model can try again. In Responses, "strict": true on the tool plus "additionalProperties": false in parameters keeps arguments within the schema.
Is function calling billed separately?
No. Tool definitions and function results count as input tokens, and the generated arguments count as output tokens, at the model’s price. Server-side tools such as web search add a per-search fee.Related documentation
- Let the model search the web and cite sources: Web search
- Choosing between Chat Completions and Responses, and GPT-6 parameter rules: OpenAI models
- Function calling in the native Gemini format: Gemini protocol
References
- OpenAI: Function calling
- Google: Function calling with the Gemini API