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

# Function Calling

Some models can call functions to extend their capabilities. Filter the [model catalog](https://geekai.co/models) by `Function Calling` to find them.

Send the function name, description, and expected arguments along with the user's question. If the question matches the function and the required arguments are available, the model returns a function call with a name, arguments, and a call ID. If arguments are missing, it asks the user for them. Run the named function on the client, then send the result and call ID back to the model so it can answer the original question.

This example uses a function that looks up the local weather:

```bash curl theme={null}
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-6.1-sol",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful customer service assistant. Use the provided tools to assist the user."
        },
        {
            "role": "user",
            "content": "Hello, what is the weather like in Hangzhou today?"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "Get the weather for a given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "City or region, such as Hangzhou, Zhejiang"
                        },
                        "unit": {
                            "type": "string",
                            "enum": ["℃","℉"]
                        }
                    },
                    "required": [
                        "location"
                    ]
                }
            }
        }
    ],
    "tool_choice": "auto"
}'
```

Include `tools` to specify the function name, description, and parameters. Use `tool_choice` to control whether the model can select a function automatically based on the user's intent.

The request above returns the following message fields:

```json theme={null}
"choices": [
    {
        "index": 0,
        "message": {
            "role": "assistant",
            "content": "",
            "tool_calls": [
                {
                    "id": "call_wrpN3RNE7AYlFRxEwaD5DSWA",
                    "type": "function",
                    "function": {
                        "name": "get_current_weather",
                        "arguments": "{\"location\":\"Hangzhou, China\"}"
                    }
                }
            ]
        },
        "finish_reason": "tool_calls"
    }
],
```

The `tool_calls` field contains the call ID and arguments. Use them to call the local `get_current_weather` function, then send the result and call ID back to the model:

```bash curl theme={null}
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-6.1-sol",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful customer service assistant. Use the provided tools to assist the user."
        },
        {
            "role": "user",
            "content": "Hello, what is the weather like in Hangzhou today?"
        },
        {
            "role":"assistant",
            "tool_calls": [
                {
                    "id": "call_wrpN3RNE7AYlFRxEwaD5DSWA",
                    "type": "function",
                    "function": {
                        "name": "get_current_weather",
                        "arguments": "{\"location\":\"Hangzhou, China\"}"
                    }
                }
            ]
        },
        {
            "role": "tool",
            "content": "{\"location\":\"Hangzhou, China\", \"weather\":\"Sunny, becoming cloudy\"}",
            "tool_call_id": "call_wrpN3RNE7AYlFRxEwaD5DSWA"
        }
    ]
}'
```

The model uses the function result and the conversation context to answer the original question:

![Answer based on a function call](https://static.geekai.co/storage/2025/03/24/image-20250324170626188.png)


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