> ## 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.

```python Python (OpenAI SDK) icon="python" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
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":"catppuccin-latte","dark":"ayu-dark"}}
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"]
          }
        }
      }
    ]
  }'
```

## 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-coder-next` | Alibaba Cloud | 262k tokens | Tools, JSON | $0.5 / $1.2 |
| `qwen3.6-35b-a3b-mtp` | Alibaba Cloud | 32k tokens | Tools, JSON | Rp 150 / Rp 600 |
| `amazon-nova-2-lite` | Amazon | 1M tokens | Tools, Vision, Reasoning | $0.33 / $2.75 |
| `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-fable-5.1` | 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-opus-5.5` | Anthropic | 1M tokens | Tools, Vision, Reasoning, JSON | $4 / $20 |
| `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 |
| `command-a` | Cohere | 288k tokens | Tools, JSON | Free / Included |
| `command-a-plus` | Cohere | 436k tokens | Tools, Reasoning, JSON | Free / Included |
| `north-mini-code` | Cohere | 256k tokens | Tools, Reasoning, JSON | Free / Included |
| `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 |
| `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 |
| `muse-spark-1.2` | Meta | 1M tokens | Tools, Vision, Reasoning | $1.25 / $4.25 |
| `muse-spark-1.2-contributor` | Meta | 1M tokens | Tools, Vision, Reasoning | $0.1 / $0.2 |
| `muse-spark-1.3` | Meta | 1M tokens | Tools, Vision, Reasoning | $1.25 / $4.25 |
| `muse-spark-1.3-contributor` | Meta | 1M tokens | Tools, Vision, Reasoning | $0.1 / $0.2 |
| `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 |
| `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 | $2 / $6 |
| `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-6-astra` | OpenAI | 1M tokens | Tools, Vision, Reasoning, JSON | $10 / $50 |
| `gpt-6-luna` | OpenAI | 1M tokens | Tools, Vision, Reasoning, JSON | $0.1 / $0.5 |
| `gpt-6-sol` | OpenAI | 1M tokens | Tools, Vision, Reasoning, JSON | $2 / $10 |
| `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 |
| `hy4-preview` | Tencent | 1M tokens | Tools, Reasoning | $0.85 / $2.55 |
| `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.3` | xAI | 1M tokens | Tools, Vision, 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-free` | Xiaomi | 262k tokens | Tools, Reasoning, JSON | Free / Included |
| `mimo-v2.5-pro` | Xiaomi | 1M tokens | Tools, Vision, Reasoning, JSON | $0.435 / $0.87 |
| `mimo-v2.5-pro-free` | Xiaomi | 1M tokens | Tools, Reasoning, JSON | Free / Included |
| `mimo-v2.6-flash-free` | Xiaomi | 262k tokens | Tools, Reasoning, JSON | Free / Included |
| `mimo-v2.6-pro-free` | Xiaomi | 1M tokens | Tools, Reasoning, JSON | Free / Included |
| `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` | zAI | 202k tokens | Tools, Reasoning, JSON | $1 / $3.2 |
| `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 |
| `glm-5.3-flash-free` | zAI | 128k tokens | Tools, JSON | Free / Included |
| `glm-5.3-flashx-free` | zAI | 128k tokens | Tools, Reasoning, JSON | Free / Included |

## Next Steps

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


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