> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kiosapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat - Function Calling

> Use function calling / tools with chat models

# Chat - Function Calling

Enable the model to call external functions by providing a `tools` array. The model will generate structured JSON input for the function instead of a text response.

> [!NOTE]
>
> For more details, see the [OpenAI Function Calling Guide](https://platform.openai.com/docs/guides/function-calling).

## Request

### Headers

| Header | Required | Description |
| - | - | - |
| `Content-Type` | Yes | `application/json` |
| `Authorization` | Yes | `Bearer sk-xxx` |

### Request Body

| Parameter | Type | Required | Description |
| - | - | - | - |
| `model` | string | Yes | Model name (e.g. `gpt-5.5`) |
| `messages` | array | Yes | Array of message objects |
| `tools` | array | Yes | Array of tool/function definitions |
| `tools[].type` | string | Yes | Always `function` |
| `tools[].function.name` | string | Yes | Function name (a-z, A-Z, 0-9, underscores, dashes, max 64) |
| `tools[].function.description` | string | No | Function description |
| `tools[].function.parameters` | object | Yes | JSON Schema object defining parameters |
| `tools[].function.parameters.type` | string | Yes | Usually `object` |
| `tools[].function.parameters.properties` | object | Yes | Parameter definitions |
| `tools[].function.parameters.required` | array | No | Required parameter names |
| `tools[].function.strict` | boolean | No | Enable strict schema adherence |

### Example Request

```bash theme={null}
curl https://kiosapi.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxx" \
  -d '{
    "model": "gpt-5.5",
    "messages": [
      {
        "role": "user",
        "content": "What is the weather like in Paris today?"
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get current temperature for a given location.",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "City and country e.g. Paris, France"
              }
            },
            "required": ["location"],
            "additionalProperties": false
          },
          "strict": true
        }
      }
    ]
  }'
```

### Python Example

```python theme={null}
import openai
import json

openai.api_key = "sk-xxx"
openai.base_url = "https://kiosapi.com/v1/"

response = openai.chat.completions.create(
    model="gpt-5.5",
    messages=[
        {"role": "user", "content": "What is the weather like in Paris today?"}
    ],
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Get current temperature for a given location.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "City and country e.g. Paris, France"
                        }
                    },
                    "required": ["location"],
                    "additionalProperties": False
                },
                "strict": True
            }
        }
    ]
)

# The model returns a function call
tool_call = response.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
print(args)  # {"location": "Paris, France"}
```

## Response

When the model decides to call a function, the response will contain `tool_calls` instead of a text `content`:

```json theme={null}
{
  "id": "chatcmpl-Ax2bU1RFE8P0Y9uqKcErQNLcx4dDe",
  "object": "chat.completion",
  "created": 1738634724,
  "model": "gpt-5.5-2024-08-06",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_FezxjoWuDV1CL3dITVFOjUzK",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\":\"Paris, France\"}"
            }
          }
        ],
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 65,
    "completion_tokens": 16,
    "total_tokens": 81
  },
  "system_fingerprint": "fp_f3927aa00d"
}
```

> [!TIP]
>
> The `finish_reason` will be `tool_calls` when the model wants to call a function. Execute the function yourself, then send the result back in a new message with `role: "tool"`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.