Skip to main content

Documentation Index

Fetch the complete documentation index at: https://student-213fb9fc.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Function calling (also called tool use) allows models to request external function execution. The model decides when and how to call functions based on user input.
Function calling is available on the OpenAI-compatible API (/v1/chat/completions). Models that support tools include qwen3-coder:480b, deepseek-v3.2, gemma3:27b, and other instruction-tuned models.

Basic Example

from openai import OpenAI
import json

client = OpenAI(
    base_url="https://api.ajstudioz.co.in/v1",
    api_key="YOUR_API_KEY"
)

# Define your tools
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_stock_price",
            "description": "Get the current stock price for a given ticker symbol",
            "parameters": {
                "type": "object",
                "properties": {
                    "ticker": {
                        "type": "string",
                        "description": "Stock ticker symbol, e.g. AAPL, TSLA"
                    }
                },
                "required": ["ticker"]
            }
        }
    }
]

# First call: model decides to call a function
response = client.chat.completions.create(
    model="qwen3-coder:480b",
    messages=[{"role": "user", "content": "What is the current price of Apple stock?"}],
    tools=tools,
    tool_choice="auto"
)

message = response.choices[0].message

# Check if a tool was called
if message.tool_calls:
    tool_call = message.tool_calls[0]
    function_name = tool_call.function.name
    arguments = json.loads(tool_call.function.arguments)
    
    print(f"Model wants to call: {function_name}")
    print(f"Arguments: {arguments}")
    
    # Simulate function execution
    result = {"ticker": arguments["ticker"], "price": 189.45, "currency": "USD"}
    
    # Second call: provide the function result
    messages = [
        {"role": "user", "content": "What is the current price of Apple stock?"},
        message,
        {
            "role": "tool",
            "tool_call_id": tool_call.id,
            "content": json.dumps(result)
        }
    ]
    
    final_response = client.chat.completions.create(
        model="qwen3-coder:480b",
        messages=messages
    )
    
    print(final_response.choices[0].message.content)

Multiple Tools

tools = [
    {
        "type": "function",
        "function": {
            "name": "search_web",
            "description": "Search the web for current information",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string", "description": "Search query"},
                    "num_results": {"type": "integer", "description": "Number of results", "default": 5}
                },
                "required": ["query"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "calculate",
            "description": "Perform mathematical calculations",
            "parameters": {
                "type": "object",
                "properties": {
                    "expression": {"type": "string", "description": "Math expression to evaluate"}
                },
                "required": ["expression"]
            }
        }
    }
]

tool_choice Options

ValueDescription
"auto"Model decides whether to call a function (default)
"none"Model never calls functions
"required"Model must call at least one function
{"type": "function", "function": {"name": "my_func"}}Force specific function

Parallel Tool Calls

Models can call multiple tools simultaneously:
response = client.chat.completions.create(
    model="deepseek-v3.2",
    messages=[{"role": "user", "content": "Get me the weather in Paris and the stock price of AAPL."}],
    tools=tools,
    tool_choice="auto",
    parallel_tool_calls=True
)

for tool_call in response.choices[0].message.tool_calls:
    print(f"Tool: {tool_call.function.name}, Args: {tool_call.function.arguments}")