Function Calling
Declare callable functions via the tools parameter. When needed, the model returns tool_calls; your program executes them and sends the results back to the model.
1. Declare tools and send the request
bash
curl https://api.novaapis.com/v1/chat/completions \
-H "Authorization: Bearer $NOVA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{ "role": "user", "content": "What is the weather in Beijing today?" }],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather for a given city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City name" }
},
"required": ["city"]
}
}
}]
}'2. Handle the returned tool_calls
If the model decides to call a tool, it returns tool_calls (with the function name and arguments). Your program runs the real function, then appends the result back into messages as a role: "tool" message and sends a second request, from which the model produces the final answer.
3. Call flow
- Client sends the request with
toolsdeclared - Model returns
tool_calls - Client executes the corresponding function and gets a result
- Client sends the result back as a
toolmessage and requests again - Model combines the result and outputs the final answer
Tool-calling support varies by model — choose one that supports Function Calling.