FC Function Calling
Function Calling allows the model to request execution of your defined functions when needed, and continue answering based on the function results.
On 4ALL API, the GPT, Claude, and Gemini series all support the standard OpenAI tools protocol, so you can write one set of code and use it across models.
Basic flow
- Declare the function signature in the request using
tools; - The model returns
finish_reason: "tool_calls"along with the function name and JSON arguments; - You execute the function and send the result back as a
role: "tool"message; - The model provides the final answer based on the result.
Example
tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Query the current weather in a specified city", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], }, },}]
resp = client.chat.completions.create( model="gpt-5.5", messages=messages, tools=tools)call = resp.choices[0].message.tool_calls[0]# Send back after executing the function:messages.append(resp.choices[0].message)messages.append({ "role": "tool", "tool_call_id": call.id, "content": '{"temp": 31, "condition": "sunny"}',})final = client.chat.completions.create(model="gpt-5.5", messages=messages, tools=tools)Notes
- The arguments are JSON strings generated by the model, so be sure to validate them before executing; do not concatenate them directly into commands or SQL;
- The model may return multiple
tool_callsat once; execute them one by one and return results according totool_call_id; tool_choice: "required"can force tool calling, and"none"can disable it;- In streaming mode, function arguments are delivered incrementally; you need to concatenate them completely before parsing. See Streaming Output.