Skip to main content
With function calling, the model replies with the function it wants to call and the arguments. Your code runs the function and sends the result back, and the model writes the final answer. LaoZhang API’s OpenAI-compatible endpoints use the same 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 nested function object, and results go back as function_call_output items:

Send history back to Responses

Rebuild each function_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 output back into input unchanged.
On LaoZhang API, a model can be served by more than one official route, and two consecutive requests may land on different routes. Both patterns above point to objects stored on the earlier route, so they fail with HTTP 400 when the route changes:
  • The requested item was created under a different Azure OpenAI resource
  • Previous response with id '...' not found
Sending the content without item IDs avoids the problem.

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 own tool_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 with json.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.
  • 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