#.......
20 messages · Page 1 of 1 (latest)
Hi! I’m tuned to answer questions specifically about OpenAI products, APIs, and documentation.
How can I help you with something related to OpenAI?
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@light quartz Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@fleet ridge tell me about your functions tools calls
Let me check the knowledge base for you again. One moment! :books:
OpenAI’s “functions” / “tools” / “function calls” are one unified mechanism that lets models ask your code to do something, using structured JSON arguments you define.
What is a function/tool?
A tool is any capability you expose to the model (e.g., “get weather”, “look up order”). A function is a tool whose input is defined by a JSON Schema. You declare these in the tools array of your API request. [Defining functions; How it works]
Example function definition:
{
"type": "function",
"name": "get_weather",
"description": "Retrieves current weather for the given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Units the temperature will be returned in."
}
},
"required": ["location", "units"],
"additionalProperties": false
},
"strict": true
}
How function/tool calling works
- You define tools (functions) with JSON Schema and send them in the request (
toolsparameter). [Function calling in API] - Model decides to call a tool: instead of plain text, it returns a tool call with:
- tool/function name
- JSON
argumentsstring that matches your schema - a
call_id(ortool_call_idin chat) to correlate responses. [How it works; Detect function call]
- Your code runs the function using those arguments.
- You send the function result back:
- Chat/Responses: as a
tool/function_call_outputitem. - Realtime: as a
function_call_outputconversation item with the samecall_id. [Function tool example; Configure function tool]
- Chat/Responses: as a
The model then uses that output to generate a final natural-language answer.
Example (Responses API, Python)
from openai import OpenAI
import json
client = OpenAI()
tools = [
{
"type": "function",
"name": "get_horoscope",
"description": "Get today's horoscope for an astrological sign.",
"parameters": {
"type": "object",
"properties": {
"sign": {
"type": "string",
"description": "An astrological sign like Taurus or Aquarius",
},
},
"required": ["sign"],
},
},
]
def get_horoscope(sign):
return f"{sign}: Next Tuesday you will befriend a baby otter."
input_list = [
{"role": "user", "content": "What is my horoscope? I am an Aquarius."}
]
response = client.responses.create(
model="gpt-5.5",
tools=tools,
input=input_list,
)
input_list += response.output
for item in response.output:
if item.type == "function_call" and item.name == "get_horoscope":
sign = json.loads(item.arguments)["sign"]
horoscope = get_horoscope(sign)
input_list.append({
"type": "function_call_output",
"call_id": item.call_id,
"output": horoscope,
})
response = client.responses.create(
model="gpt-5.5",
instructions="Respond only with a horoscope generated by a tool.",
tools=tools,
input=input_list,
)
print(response.output_text)
[[Function tool example](<https://developers.openai.com/api/docs/guides/function-calling#function-tool-example>)]
### Structured Outputs (`strict: true`)
If you set `strict: true` in the function definition, the model is guaranteed to produce arguments that exactly match your JSON Schema (Structured Outputs). [[Function calling help](<https://help.openai.com/en/articles/8555517-function-calling-in-the-openai-api>); [Playground article](<https://help.openai.com/en/articles/9492280-function-calling-in-the-chat-playground>)]
### Where you can use function/tools calls
- Responses API / Chat Completions – general server-side use. [Function calling in API]
- Realtime API – live conversations; function calls appear as
function_callitems and you reply withfunction_call_output. [Function calling realtime; Configure function tool] - Assistants / Agents – as custom tools the assistant can invoke during a run. [Assistants functions]
- Playground – add functions via “+Tools > Functions” and manually enter outputs to test. [Playground function calling]
If you tell me your language/runtime (Python, JS, Java, etc.) and use case, I can point you to the most relevant pattern from these examples.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@light quartz Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Your functions @fleet ridge
Let me check the knowledge base for you again. One moment! :books:
OpenAI “functions” are a type of tool you define so models can call your own code with structured JSON arguments.
What is a function tool?
A function tool is declared in the tools array of an API request with:
type: "function"name: identifier the model will calldescription: when/how to use itparameters: JSON Schema describing the arguments- optional
strict: trueto enforce Structured Outputs [Defining functions]
Example definition:
{
"type": "function",
"name": "get_weather",
"description": "Retrieves current weather for the given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Units the temperature will be returned in."
}
},
"required": ["location", "units"],
"additionalProperties": false
},
"strict": true
}
How function calling works
- You send tools with your request (
tools=[{...}]). [How it works] - Model may return a tool call instead of plain text:
- function name
- JSON
arguments - an ID (
call_id/tool_call_id). [How it works]
- Your code executes the function using those arguments.
- You send back the result as a tool output:
- Responses API: an item with
type: "function_call_output",call_id, andoutput. [Calling custom functions] - Chat Completions: a
toolrole message withtool_call_idandcontent. [Function tool example] - Realtime: a
conversation.item.createevent withtype: "function_call_output"and matchingcall_id. [Configure function tool]
- Responses API: an item with
The model then uses that tool output to produce the final answer.
Minimal end‑to‑end example (Responses API, Python)
from openai import OpenAI
import json
client = OpenAI()
tools = [
{
"type": "function",
"name": "get_horoscope",
"description": "Get today's horoscope for an astrological sign.",
"parameters": {
"type": "object",
"properties": {
"sign": {
"type": "string",
"description": "An astrological sign like Taurus or Aquarius",
},
},
"required": ["sign"],
},
},
]
def get_horoscope(sign):
return f"{sign}: Next Tuesday you will befriend a baby otter."
input_list = [
{"role": "user", "content": "What is my horoscope? I am an Aquarius."}
]
response = client.responses.create(
model="gpt-5.5",
tools=tools,
input=input_list,
)
input_list += response.output
for item in response.output:
if item.type == "function_call" and item.name == "get_horoscope":
sign = json.loads(item.arguments)["sign"]
horoscope = get_horoscope(sign)
input_list.append({
"type": "function_call_output",
"call_id": item.call_id,
"output": horoscope,
})
response = client.responses.create(
model="gpt-5.5",
instructions="Respond only with a horoscope generated by a tool.",
tools=tools,
input=input_list,
)
print(response.output_text)
[[Function tool example](<https://developers.openai.com/api/docs/guides/function-calling#function-tool-example>)]
If you tell me which API (Responses, Chat, Realtime, Assistants) and language you’re using, I can narrow this down to the exact pattern you need.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@light quartz Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Your capability @fleet ridge
Let me check the knowledge base for you again. One moment! :books:
I’m designed to answer questions specifically about OpenAI—its products, APIs, tools (like function calling, web search, file search, Code Interpreter), and related documentation. I use only the provided OpenAI knowledge sources and:
- Explain how to use OpenAI APIs and tools (e.g., function/tools calling, Responses API, Realtime, Agents SDK). [Function calling help; Tools overview]
- Show code snippets that come directly from those docs (Python, JS, etc.). [Function tool example; Extend with tools]
- Describe how tools like web search, file search, and function tools work and how to configure them. [Extend with tools; Agents tools]
I’m not allowed to answer questions that are unrelated to OpenAI, and if the docs don’t cover something, I must say so rather than inventing details.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@light quartz Kapa.ai is still learning and improving, please let me know how I did by reacting below.