Fonksiyon Çağırma
Connect models to external data and systems by defining functions the model can choose to call.
How it works
Function calling lets the model invoke external tools and APIs. The model doesn't execute functions itself — it decides when to call them and returns structured arguments your code can use.
Define functions
Describe functions using JSON Schema in the tools parameter. Include the name, description, and parameters for each function you want the model to be able to call.
Model decides to call
Based on the user message and available functions, the model decides whether to respond in natural language or to call one or more functions. It returns a structured tool_calls object with arguments.
Execute function
Your code parses the tool_calls response, extracts the function name and arguments, and calls the actual function — whether it's a database query, an API call, or a local computation.
Return result
Send the function output back to the model as a tool role message. The model uses it to generate a final, grounded response to the user.
Defining a function
Functions are defined using JSON Schema in the tools array. Each tool has a type of "function" and a function object with a name, description, and parameters schema.
JSON Schema example
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit to use"
}
},
"required": ["location"],
"additionalProperties": false
}
}
}
Making the API call
from GlomaxGPT import GlomaxGPT
client = GlomaxGPT()
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"],
"additionalProperties": False
}
}
}
]
response = client.responses.create(
model="glomaxgpt-ultra",
input=[{"role": "user", "content": "What's the weather in Boston?"}],
tools=tools
)
print(response.output)
import GlomaxGPT from "GlomaxGPT";
const client = new GlomaxGPT();
const tools = [
{
type: "function",
function: {
name: "get_weather",
description: "Get the current weather for a location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "City and state, e.g. San Francisco, CA"
},
unit: {
type: "string",
enum: ["celsius", "fahrenheit"]
}
},
required: ["location"],
additionalProperties: false
}
}
}
];
const response = await client.responses.create({
model: "glomaxgpt-ultra",
input: [{ role: "user", content: "What's the weather in Boston?" }],
tools
});
console.log(response.output);
Handling tool calls
When the model returns a tool_calls response, parse the arguments, run the function, and submit the result back in the next turn.
import json
def get_weather(location, unit="celsius"):
# Your actual weather API call here
return {"temperature": 22, "unit": unit, "condition": "sunny"}
messages = [{"role": "user", "content": "What's the weather in Boston?"}]
response = client.responses.create(
model="glomaxgpt-ultra",
input=messages,
tools=tools
)
# Check if the model wants to call a function
for item in response.output:
if item.type == "function_call":
args = json.loads(item.arguments)
result = get_weather(**args)
# Append assistant's tool call and the result
messages.append(item)
messages.append({
"type": "function_call_output",
"call_id": item.call_id,
"output": json.dumps(result)
})
# Get the final response
final = client.responses.create(
model="glomaxgpt-ultra",
input=messages,
tools=tools
)
print(final.output_text)
function getWeather(location, unit = "celsius") {
// Your actual weather API call here
return { temperature: 22, unit, condition: "sunny" };
}
const messages = [{ role: "user", content: "What's the weather in Boston?" }];
const response = await client.responses.create({
model: "glomaxgpt-ultra",
input: messages,
tools
});
for (const item of response.output) {
if (item.type === "function_call") {
const args = JSON.parse(item.arguments);
const result = getWeather(args.location, args.unit);
messages.push(item);
messages.push({
type: "function_call_output",
call_id: item.call_id,
output: JSON.stringify(result)
});
}
}
const final = await client.responses.create({
model: "glomaxgpt-ultra",
input: messages,
tools
});
console.log(final.output_text);
Parallel function calling
Models can call multiple functions simultaneously when the user's request requires it. For example, "What's the weather in Boston and New York?" may trigger two get_weather calls in a single response.
response = client.responses.create(
model="glomaxgpt-ultra",
input=[{
"role": "user",
"content": "What's the weather in Boston and New York?"
}],
tools=tools
)
# Handle multiple tool calls in parallel
tool_results = []
for item in response.output:
if item.type == "function_call":
args = json.loads(item.arguments)
result = get_weather(**args)
tool_results.append({
"type": "function_call_output",
"call_id": item.call_id,
"output": json.dumps(result)
})
# Submit all results at once
messages = [*response.output, *tool_results]
final = client.responses.create(
model="glomaxgpt-ultra",
input=messages,
tools=tools
)
print(final.output_text)
Strict mode
Enable strict: true to enforce JSON Schema validation on function arguments. The model is guaranteed to return arguments that exactly match your schema.
Strict mode requirements
- All properties must be listed in
required additionalPropertiesmust befalse- Only supported JSON Schema features can be used
- Nested objects must also follow the same rules
tools = [
{
"type": "function",
"strict": True,
"function": {
"name": "get_weather",
"description": "Get weather for a location.",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location", "unit"],
"additionalProperties": False
}
}
}
]
tool_choice parameter
Control when and how the model uses tools with the tool_choice parameter.
| Value | Behavior |
|---|---|
"auto" |
Default. Model decides whether to call a function or respond in text. |
"none" |
Model will never call a function; always responds in text. |
"required" |
Model must call at least one function before responding. |
{"type": "function", "name": "..."} |
Forces the model to call a specific named function. |
# Always respond in text, never call functions
response = client.responses.create(
model="glomaxgpt-ultra",
input=messages,
tools=tools,
tool_choice="none"
)
# Force the model to call a specific function
response = client.responses.create(
model="glomaxgpt-ultra",
input=messages,
tools=tools,
tool_choice={"type": "function", "name": "get_weather"}
)
# Must call at least one tool
response = client.responses.create(
model="glomaxgpt-ultra",
input=messages,
tools=tools,
tool_choice="required"
)
Frequently asked questions
No. The model only returns the function name and arguments as structured JSON. Your application code is responsible for executing the function and returning the result. This design keeps your data and systems secure.
There is no hard limit on the number of tools per request, but very large tool lists consume tokens in the context window. In practice, keeping your toolset focused and relevant to the task improves both latency and accuracy.
Function calling enables the model to trigger external actions — it returns structured arguments for a specific function. Structured Outputs constrains the model's text response to follow a JSON schema. Both use JSON Schema, but serve different purposes. They can be combined: use strict: true on your function definitions to get schema-enforced arguments.
Strict mode is optional but strongly recommended for production use. Without it, the model may occasionally return arguments that don't exactly match your schema, requiring additional validation on your end. Strict mode guarantees schema compliance at the cost of some schema feature restrictions.
Parallel function calls happen within a single API response and are billed as one request. The output tokens include all tool call objects. Each subsequent round-trip (submitting tool results and getting a final response) is billed as a separate request based on tokens used.