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

# Function Calling (Tools)

> Connect AI models to external functions, databases, and APIs using OpenAI Tool Calling.

Function Calling on `/v1/chat/completions` allows models to intelligently detect when external functions should be invoked and generate structured JSON arguments matching your specified schema.

<CodeGroup>
  ```python Python (OpenAI SDK) icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
  from openai import OpenAI
  import json
  import os

  client = OpenAI(
      base_url="https://api.neosantara.xyz/v1",
      api_key=os.environ["NEOSANTARA_API_KEY"]
  )

  tools = [
      {
          "type": "function",
          "function": {
              "name": "get_stock_price",
              "description": "Fetch real-time stock price by ticker symbol.",
              "parameters": {
                  "type": "object",
                  "properties": {
                      "ticker": {"type": "string", "description": "Stock ticker (e.g. BBCA)"}
                  },
                  "required": ["ticker"]
              }
          }
      }
  ]

  # Step 1: Model evaluates request
  response = client.chat.completions.create(
      model="deepseek-v4.1-flash",
      messages=[{"role": "user", "content": "What is the stock price of BBCA today?"}],
      tools=tools,
      tool_choice="auto"
  )

  message = response.choices[0].message

  # Step 2: Check if model generated tool calls
  if message.tool_calls:
      for tool_call in message.tool_calls:
          print(f"Function: {tool_call.function.name}")
          print(f"Arguments: {tool_call.function.arguments}")
          
          # Step 3: Execute local function
          tool_result = json.dumps({"ticker": "BBCA", "price": 9850, "currency": "IDR"})
          
          # Step 4: Supply result back to model
          final_response = client.chat.completions.create(
              model="deepseek-v4.1-flash",
              messages=[
                  {"role": "user", "content": "What is the stock price of BBCA today?"},
                  message,
                  {
                      "role": "tool",
                      "tool_call_id": tool_call.id,
                      "content": tool_result
                  }
              ]
          )
          print("Final Answer:", final_response.choices[0].message.content)
  ```

  ```bash cURL icon="terminal" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
  curl -X POST https://api.neosantara.xyz/v1/chat/completions \
    -H "Authorization: Bearer $NEOSANTARA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "deepseek-v4.1-flash",
      "messages": [{"role": "user", "content": "Check BBCA price"}],
      "tools": [
        {
          "type": "function",
          "function": {
            "name": "get_stock_price",
            "description": "Fetch stock price",
            "parameters": {
              "type": "object",
              "properties": {
                "ticker": {"type": "string"}
              },
              "required": ["ticker"]
            }
          }
        }
      ]
    }'
  ```
</CodeGroup>

## The `tool_choice` Parameter

| Value                                                           | Behavior                                                                 |
| :-------------------------------------------------------------- | :----------------------------------------------------------------------- |
| `"auto"`                                                        | Model decides whether to call a function or respond with text (default). |
| `"none"`                                                        | Forces model to respond with text without invoking any function.         |
| `"required"`                                                    | Forces model to invoke at least one function from the provided list.     |
| `{"type": "function", "function": {"name": "get_stock_price"}}` | Forces model to call that specific function.                             |

## Models Supporting Tool Calling

| Model ID                            | Provider      | Context Window | Capabilities                   | Pricing (Input/Output per 1M) |
| :---------------------------------- | :------------ | :------------- | :----------------------------- | :---------------------------- |
| `agnes-2.5-flash`                   | Agnes AI      | 1M tokens      | Tools, Vision, Reasoning, JSON | Free / Included               |
| `qwen3.6-35b-a3b-mtp`               | Alibaba Cloud | 32k tokens     | Tools, JSON                    | Rp 150 / Rp 600               |
| `amazon-nova-lite`                  | Amazon        | 300k tokens    | Tools, Vision, JSON            | $0.06 / $0.24                 |
| `amazon-nova-micro`                 | Amazon        | 300k tokens    | Tools, JSON                    | $0.035 / $0.14                |
| `amazon-nova-pro`                   | Amazon        | 300k tokens    | Tools, Vision, JSON            | $0.8 / $3.2                   |
| `claude-4-5-haiku`                  | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $1 / $5                       |
| `claude-4.5-opus`                   | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $5 / $25                      |
| `claude-4.5-sonnet`                 | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $3 / $15                      |
| `claude-fable-5`                    | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $10 / $50                     |
| `claude-opus-4-6`                   | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $5 / $25                      |
| `claude-opus-4-7`                   | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $5 / $25                      |
| `claude-opus-4-8`                   | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $5 / $25                      |
| `claude-opus-5`                     | Anthropic     | 1M tokens      | Tools, Vision, Reasoning       | $5 / $25                      |
| `claude-sonnet-4-6`                 | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $3 / $15                      |
| `claude-sonnet-5`                   | Anthropic     | 200k tokens    | Tools, Vision, Reasoning, JSON | $3 / $15                      |
| `deepseek-v4-flash`                 | DeepSeek      | 1M tokens      | Tools, Reasoning               | $0.22 / $0.66                 |
| `deepseek-v4-flash-0731`            | DeepSeek      | 1M tokens      | Tools, Reasoning, JSON         | $0.14 / $0.28                 |
| `deepseek-v4-pro`                   | DeepSeek      | 1M tokens      | Tools, Reasoning               | $0.66 / $1.98                 |
| `deepseek-v4-pro-0813`              | DeepSeek      | 1M tokens      | Tools, Reasoning, JSON         | $1.32 / $3.96                 |
| `deepseek-v4.1-flash`               | DeepSeek      | 1M tokens      | Tools, Vision, Reasoning, JSON | $0.15 / $0.6                  |
| `gemini-3-flash`                    | Google        | 1M tokens      | Tools, Vision, JSON            | $0.5 / $3                     |
| `gemini-3.1-flash-lite`             | Google        | 1M tokens      | Tools, Vision, Reasoning, JSON | $0.25 / $1.5                  |
| `gemini-3.1-pro`                    | Google        | 1M tokens      | Tools, Vision, Reasoning, JSON | $2 / $12                      |
| `gemini-3.5-flash`                  | Google        | 1M tokens      | Tools, Vision, Reasoning, JSON | $1.5 / $9                     |
| `gemini-3.6-flash`                  | Google        | 1M tokens      | Tools, Vision, Reasoning, JSON | $1.5 / $7.5                   |
| `gemini-3.7-flash`                  | Google        | 1M tokens      | Tools, Vision, Reasoning, JSON | $1.5 / $7.5                   |
| `gemini-3.8-flash`                  | Google        | 1M tokens      | Tools, Vision, Reasoning, JSON | $0.75 / $3.75                 |
| `gemma-4-e2b-it`                    | Google        | 32k tokens     | Tools, Vision, JSON            | Rp 100 / Rp 400               |
| `granite-3-8b-instruct`             | IBM           | 128k tokens    | Tools, JSON                    | Rp 2,880 / Rp 11,520          |
| `ling-3.0-flash-fin`                | InclusionAI   | 256k tokens    | Tools, Reasoning               | Free / Included               |
| `longcat-2.0`                       | Meituan       | 1M tokens      | Tools, Reasoning, JSON         | Free / Included               |
| `llama-3-2-11b-vision`              | Meta          | 128k tokens    | Tools, Vision, JSON            | $0.16 / $0.16                 |
| `muse-glimmer-30b`                  | Meta          | 131k tokens    | Tools, Vision, Reasoning, JSON | $0.35 / $1.5                  |
| `muse-spark-1.1`                    | Meta          | 1M tokens      | Tools, Vision, Reasoning       | $1.25 / $4.25                 |
| `minimax-m2.7`                      | MiniMax       | 204k tokens    | Tools, Reasoning, JSON         | $0.3 / $1.2                   |
| `minimax-m2.7-free`                 | MiniMax       | 196k tokens    | Tools, Reasoning, JSON         | Free / Included               |
| `minimax-m3`                        | MiniMax       | 1M tokens      | Tools, Vision, Reasoning, JSON | $0.6 / $1.2                   |
| `minimax-m3-free`                   | MiniMax       | 1M tokens      | Tools, Vision, Reasoning, JSON | Free / Included               |
| `codestral-2`                       | Mistral AI    | 256k tokens    | Tools                          | $0.3 / $0.9                   |
| `devstral-2`                        | Mistral AI    | 256k tokens    | Tools                          | $0.4 / $2                     |
| `hermes-2-pro-mistral-7b`           | Mistral AI    | 24k tokens     | Tools, JSON                    | Rp 450 / Rp 1,200             |
| `mistral-large-latest`              | Mistral AI    | 128k tokens    | Tools, JSON                    | $0.5 / $1.5                   |
| `mistral-small-latest`              | Mistral AI    | 128k tokens    | Tools, JSON                    | $0.15 / $0.6                  |
| `kimi-k2-thinking`                  | Moonshot      | 256k tokens    | Tools, Reasoning               | $0.6 / $2.5                   |
| `kimi-k2.5`                         | Moonshot      | 256k tokens    | Tools, Vision, Reasoning       | $0.6 / $3                     |
| `kimi-k2.6`                         | Moonshot      | 262k tokens    | Tools, Vision, Reasoning, JSON | $0.95 / $4                    |
| `kimi-k3`                           | Moonshot      | 1M tokens      | Tools, Vision, Reasoning, JSON | $3 / $15                      |
| `garda-core`                        | Neosantara    | 1M tokens      | Tools, Reasoning, JSON         | Rp 300 / Rp 1,500             |
| `llama-3.3-nemotron-super-49b-v1.5` | NVIDIA        | 132k tokens    | Tools, Reasoning, JSON         | Rp 4,560 / Rp 31,991          |
| `gpt-5-nano`                        | OpenAI        | 128k tokens    | Tools, Vision, Reasoning, JSON | Rp 810 / Rp 6,485             |
| `gpt-5.4`                           | OpenAI        | 270k tokens    | Tools, Vision, Reasoning, JSON | $2.5 / $15                    |
| `gpt-5.4-mini`                      | OpenAI        | 128k tokens    | Tools, Vision, Reasoning, JSON | $0.75 / $4.5                  |
| `gpt-5.4-nano`                      | OpenAI        | 400k tokens    | Tools, Vision, Reasoning, JSON | Rp 3,240 / Rp 20,250          |
| `gpt-5.5`                           | OpenAI        | 270k tokens    | Tools, Vision, Reasoning, JSON | $5 / $30                      |
| `gpt-5.6-luna`                      | OpenAI        | 272k tokens    | Tools, Reasoning               | $0.2 / $1.2                   |
| `gpt-5.6-sol`                       | OpenAI        | 272k tokens    | Tools, Reasoning               | $5 / $30                      |
| `gpt-5.6-terra`                     | OpenAI        | 272k tokens    | Tools, Vision, Reasoning       | $2 / $12                      |
| `gpt-oss-120b`                      | OpenAI        | 131k tokens    | Tools, Reasoning, JSON         | $0.15 / $0.6                  |
| `gpt-oss-20b`                       | OpenAI        | 131k tokens    | Tools, Reasoning, JSON         | Rp 400 / Rp 1,600             |
| `laguna-s-2.1`                      | Poolside      | 262k tokens    | Tools, Reasoning               | Free / Included               |
| `laguna-xs-2.1`                     | Poolside      | 262k tokens    | Tools, Reasoning               | Free / Included               |
| `bonsai-27b`                        | Prism ML      | 262k tokens    | Tools, Vision, Reasoning, JSON | Free / Included               |
| `step-3.5-flash`                    | StepFun       | 256k tokens    | Tools, Reasoning, JSON         | Rp 3,000 / Rp 9,000           |
| `grok-4.1-fast-non-reasoning`       | xAI           | 1M tokens      | Tools                          | $1.25 / $2.5                  |
| `grok-4.1-fast-reasoning`           | xAI           | 1M tokens      | Tools, Reasoning               | $1.25 / $2.5                  |
| `grok-4.5`                          | xAI           | 500k tokens    | Tools, Vision, Reasoning, JSON | $2 / $6                       |
| `mimo-v2.5`                         | Xiaomi        | 1M tokens      | Tools, Vision, Reasoning       | $0.14 / $0.28                 |
| `mimo-v2.5-pro`                     | Xiaomi        | 1M tokens      | Tools, Vision, Reasoning, JSON | $0.435 / $0.87                |
| `glm-4.5-flash`                     | zAI           | 128k tokens    | Tools, Reasoning               | Rp 250 / Rp 750               |
| `glm-4.6v-flash`                    | zAI           | 128k tokens    | Tools, Vision, Reasoning       | Rp 250 / Rp 750               |
| `glm-4.7`                           | zAI           | 200k tokens    | Tools, Reasoning               | Rp 10,000 / Rp 30,000         |
| `glm-4.7-flash`                     | zAI           | 1M tokens      | Tools, Reasoning               | Free / Included               |
| `glm-5.3`                           | zAI           | 1M tokens      | Tools, Vision, Reasoning, JSON | $1.4 / $4.4                   |
| `glm-5.3-flash`                     | zAI           | 1M tokens      | Tools, Vision, Reasoning, JSON | $0.15 / $0.5                  |

## Next Steps

| Task                      | Guide                                                                 |
| :------------------------ | :-------------------------------------------------------------------- |
| Enforce Schema Compliance | [Structured Outputs](/en/gateway/chat-completions/structured-outputs) |
| Token Streaming           | [Streaming Responses](/en/gateway/chat-completions/streaming)         |
| Anthropic Tool Use        | [Anthropic Tool Use](/en/gateway/anthropic-messages/tool-use)         |


## Related topics

- [Chat Completions](/en/gateway/chat-completions.md)
- [Anthropic Tool Use](/en/gateway/anthropic-messages/tool-use.md)
- [Server Tools & MCP Integration](/en/gateway/responses-api/tools.md)
- [MCP Connector](/en/agents/mcp-connector.md)
