#.......

20 messages · Page 1 of 1 (latest)

fleet ridgeBOT
#

Hi @light quartz. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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.

light quartz
#

@fleet ridge tell me about your functions tools calls

fleet ridgeBOT
#

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
}

[Defining functions]

How function/tool calling works

#
  1. You define tools (functions) with JSON Schema and send them in the request (tools parameter). [Function calling in API]
  2. Model decides to call a tool: instead of plain text, it returns a tool call with:
    • tool/function name
    • JSON arguments string that matches your schema
    • a call_id (or tool_call_id in chat) to correlate responses. [How it works; Detect function call]
  3. Your code runs the function using those arguments.
  4. You send the function result back:

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
#

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.

light quartz
#

Your functions @fleet ridge

fleet ridgeBOT
#

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 call
  • description: when/how to use it
  • parameters: JSON Schema describing the arguments
  • optional strict: true to 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
}

[Defining functions]

How function calling works

#
  1. You send tools with your request (tools=[{...}]). [How it works]
  2. Model may return a tool call instead of plain text:
    • function name
    • JSON arguments
    • an ID (call_id / tool_call_id). [How it works]
  3. Your code executes the function using those arguments.
  4. You send back the result as a tool output:

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.

light quartz
#

Your capability @fleet ridge

fleet ridgeBOT
#

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:

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.