हम cookies इस्तेमाल करते हैं. Cookies और ब्राउज़र स्टोरेज आपको साइन इन रखते हैं और आपकी प्राथमिकताएं याद रखते हैं। आपकी अनुमति से हम यह भी मापते हैं कि साइट कैसे इस्तेमाल होती है। आप कभी भी । हमारी cookie नीति देखें।

टूल कॉलिंग

Endpoints

टूल कॉलिंग

OpenAI tools फ़ॉर्मेट से मॉडल को अपने फ़ंक्शन कॉल करने दें। टूल लूप, पैरामीटर, tool_choice, उदाहरण और स्ट्रीमिंग के सुझाव यहाँ हैं।

playground में आज़माएं

टूल कॉलिंग (function calling) मॉडल को आपके कोड से कोई फ़ंक्शन चलवाने और फिर उसके नतीजे को अपने उत्तर में इस्तेमाल करने देती है। api14 टूल सपोर्ट करने वाले हर मॉडल के लिए OpenAI tools फ़ॉर्मेट इस्तेमाल करता है: OpenAI, Anthropic, Google, Mistral, Qwen, DeepSeek और अन्य। टूल-सक्षम मॉडल खोजने के लिए मॉडल सूची में समर्थित पैरामीटर से फ़िल्टर करें (supported_parameters में tools शामिल हो)।

अनुरोध पैरामीटर

पैरामीटरप्रकारविवरण
toolsarray[{ "type": "function", "function": { "name", "description", "parameters" } }], जहाँ parameters एक JSON Schema है।
tool_choicestring | object"auto" (डिफ़ॉल्ट), "none", "required", या { "type": "function", "function": { "name": "get_weather" } }।
parallel_tool_callsbooleanएक टर्न में कई टूल कॉल की अनुमति दें (जहाँ समर्थित हो डिफ़ॉल्ट true)।
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
});

const result = await client.chat.completions.create({
  "model": "openai/gpt-5-mini",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Istanbul?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    }
  ]
});
console.log(result.choices[0].message.tool_calls);

लूप

  1. messages और tools भेजें।
  2. यदि प्रतिक्रिया में finish_reason: "tool_calls" है, तो message.tool_calls की हर प्रविष्टि चलाएँ।
  3. असिस्टेंट मैसेज जोड़ें, फिर हर कॉल के लिए एक { "role": "tool", "tool_call_id", "content" } मैसेज, और अनुरोध दोबारा भेजें।
  4. तब तक दोहराएँ जब तक मॉडल सादे कंटेंट में उत्तर न दे।

टूल कॉल वाली प्रतिक्रिया:

{
  "id": "gen-1760000000-tool1",
  "model": "anthropic/claude-sonnet-4.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "tool_calls",
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_01",
            "type": "function",
            "function": { "name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}" }
          }
        ]
      }
    }
  ],
  "usage": { "prompt_tokens": 182, "completion_tokens": 21, "total_tokens": 203, "cost": 0.000861 }
}

अगले अनुरोध में टूल का नतीजा शामिल होता है:

{
  "model": "anthropic/claude-sonnet-4.5",
  "tools": [ ... same tools ... ],
  "messages": [
    { "role": "user", "content": "What's the weather in Istanbul?" },
    { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_01", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\":\"Istanbul\"}" } } ] },
    { "role": "tool", "tool_call_id": "call_01", "content": "{\"temp_c\": 21, \"sky\": \"clear\"}" }
  ]
}

लूप के हर अनुरोध में tools भेजते रहें। कई प्रोवाइडर ऐसे अनुरोध में tool मैसेज अस्वीकार कर देते हैं जिसमें tools परिभाषाएँ नहीं होतीं।

सुझाव

  • arguments JSON की एक स्ट्रिंग है। उसे पार्स और validate करें, क्योंकि मॉडल अमान्य JSON बना सकते हैं।
  • स्ट्रीमिंग में टूल कॉल index से कुंजीबद्ध delta.tool_calls के टुकड़ों में आते हैं। पार्स करने से पहले arguments स्ट्रिंग को जोड़ लें।
  • केवल टूल सपोर्ट करने वाले प्रोवाइडर तक रूट करने के लिए provider: { "require_parameters": true } सेट करें। देखें प्रोवाइडर रूटिंग।
  • लूप का हर इटरेशन एक अलग बिल होने वाला अनुरोध है।

त्रुटियाँ

जो मॉडल टूल सपोर्ट नहीं करता वह अपस्ट्रीम 400 या 404 ("No endpoints found that support tool use") लौटा सकता है। अन्य त्रुटियाँ चैट कंप्लीशन्स जैसी ही हैं। देखें त्रुटियाँ।