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

# Create a chat completion

दिए गए चैट वार्तालाप के लिए मॉडल प्रतिक्रिया का अनुरोध भेजता है। स्ट्रीमिंग और नॉन-स्ट्रीमिंग दोनों मोड का समर्थन करता है। OpenAI Chat Completions API प्रारूप के साथ संगत है।

## प्रमाणीकरण

<ParamField header="Authorization" type="string" required>
  Bearer टोकन। Authorization हेडर में अपनी API कुंजी को bearer टोकन के रूप में उपयोग करें।

  प्रारूप: `Bearer <SUNRA_KEY>`
</ParamField>

## अनुरोध

यह एंडपॉइंट एक ऑब्जेक्ट स्वीकार करता है।

<ParamField body="messages" type="object[]" required>
  वार्तालाप के लिए संदेशों की सूची।

  <Expandable title="properties">
    <ParamField body="role" type="string" required>
      संदेश लेखक की भूमिका। समर्थित मान: `system`, `user`, `assistant`, `tool`।
    </ParamField>

    <ParamField body="content" type="string | object[]" required>
      संदेश की सामग्री। मल्टीमोडल इनपुट के लिए एक स्ट्रिंग या सामग्री भागों की एक सरणी हो सकती है।
    </ParamField>

    <ParamField body="name" type="string">
      प्रतिभागी के लिए एक वैकल्पिक नाम। समान भूमिका वाले प्रतिभागियों के बीच अंतर करने के लिए मॉडल को जानकारी प्रदान करता है।
    </ParamField>

    <ParamField body="tool_calls" type="object[]">
      मॉडल द्वारा उत्पन्न टूल कॉल, जैसे फ़ंक्शन कॉल। केवल `assistant` संदेशों में मौजूद।
    </ParamField>

    <ParamField body="tool_call_id" type="string">
      वह टूल कॉल जिसका यह संदेश जवाब दे रहा है। केवल `tool` संदेशों में मौजूद।
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="model" type="string" required>
  पूर्णता के लिए उपयोग किया जाने वाला मॉडल। उपलब्ध मॉडल [sunra.ai/models](https://sunra.ai/models) पर देखें।
</ParamField>

<ParamField body="stream" type="boolean" default={false}>
  यदि `true` पर सेट किया जाता है, तो आंशिक संदेश डेल्टा को server-sent events (SSE) के रूप में भेजा जाएगा।
</ParamField>

<ParamField body="max_tokens" type="integer">
  पूर्णता में उत्पन्न करने के लिए टोकन की अधिकतम संख्या। इनपुट टोकन और उत्पन्न टोकन की कुल लंबाई मॉडल की संदर्भ लंबाई द्वारा सीमित है।
</ParamField>

<ParamField body="temperature" type="number" default={1}>
  0 और 2 के बीच सैंपलिंग तापमान। 0.8 जैसे उच्च मान आउटपुट को अधिक यादृच्छिक बनाते हैं, 0.2 जैसे निम्न मान इसे अधिक केंद्रित और निर्धारक बनाते हैं।
</ParamField>

<ParamField body="top_p" type="number" default={1}>
  न्यूक्लियस सैंपलिंग पैरामीटर (0-1)। तापमान सैंपलिंग का एक विकल्प जहां मॉडल top\_p प्रायिकता द्रव्यमान वाले टोकन पर विचार करता है।
</ParamField>

<ParamField body="frequency_penalty" type="number" default={0}>
  -2.0 और 2.0 के बीच की संख्या। सकारात्मक मान नए टोकन को उनकी मौजूदा आवृत्ति के आधार पर दंडित करते हैं, जिससे मॉडल की एक ही पंक्ति को शब्दशः दोहराने की संभावना कम हो जाती है।
</ParamField>

<ParamField body="presence_penalty" type="number" default={0}>
  -2.0 और 2.0 के बीच की संख्या। सकारात्मक मान नए टोकन को इस आधार पर दंडित करते हैं कि वे अब तक के पाठ में दिखाई दिए हैं या नहीं, जिससे मॉडल की नए विषयों पर बात करने की संभावना बढ़ जाती है।
</ParamField>

<ParamField body="stop" type="string | string[]">
  अधिकतम 4 अनुक्रम जहां API आगे टोकन उत्पन्न करना बंद कर देगा।
</ParamField>

<ParamField body="n" type="integer" default={1}>
  प्रत्येक इनपुट संदेश के लिए कितने चैट पूर्णता विकल्प उत्पन्न करने हैं।
</ParamField>

<ParamField body="logprobs" type="boolean" default={false}>
  आउटपुट टोकन की लॉग प्रायिकताएं लौटानी हैं या नहीं। यदि true है, तो संदेश की सामग्री में लौटाए गए प्रत्येक आउटपुट टोकन की लॉग प्रायिकताएं लौटाता है।
</ParamField>

<ParamField body="top_logprobs" type="integer">
  0 और 20 के बीच का एक पूर्णांक जो प्रत्येक टोकन स्थिति पर लौटाए जाने वाले सबसे संभावित टोकन की संख्या निर्दिष्ट करता है। इस पैरामीटर का उपयोग करने पर `logprobs` को `true` पर सेट करना आवश्यक है।
</ParamField>

<ParamField body="response_format" type="object">
  एक ऑब्जेक्ट जो मॉडल द्वारा आउटपुट किए जाने वाले प्रारूप को निर्दिष्ट करता है।

  <Expandable title="properties">
    <ParamField body="type" type="string" required>
      प्रतिक्रिया प्रारूप का प्रकार। समर्थित मान: `text`, `json_object`, `json_schema`।
    </ParamField>

    <ParamField body="json_schema" type="object">
      JSON स्कीमा ऑब्जेक्ट। type `json_schema` होने पर आवश्यक।
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="seed" type="integer">
  यदि निर्दिष्ट किया गया है, तो सिस्टम निर्धारक रूप से सैंपल करने का सर्वोत्तम प्रयास करेगा, ताकि समान seed और पैरामीटर वाले बार-बार के अनुरोध समान परिणाम लौटाएं।
</ParamField>

<ParamField body="tools" type="object[]">
  उन टूल की सूची जिन्हें मॉडल कॉल कर सकता है। वर्तमान में, केवल फ़ंक्शन को टूल के रूप में समर्थित किया जाता है।

  <Expandable title="properties">
    <ParamField body="type" type="string" required>
      टूल का प्रकार। वर्तमान में, केवल `function` समर्थित है।
    </ParamField>

    <ParamField body="function" type="object" required>
      फ़ंक्शन परिभाषा।

      <Expandable title="properties">
        <ParamField body="name" type="string" required>
          कॉल किए जाने वाले फ़ंक्शन का नाम।
        </ParamField>

        <ParamField body="description" type="string">
          फ़ंक्शन क्या करता है इसका विवरण।
        </ParamField>

        <ParamField body="parameters" type="object">
          फ़ंक्शन द्वारा स्वीकार किए जाने वाले पैरामीटर, JSON Schema ऑब्जेक्ट के रूप में वर्णित।
        </ParamField>

        <ParamField body="strict" type="boolean" default={false}>
          सख्त स्कीमा पालन सक्षम करना है या नहीं।
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tool_choice" type="string | object">
  नियंत्रित करता है कि मॉडल द्वारा कौन सा (यदि कोई) टूल कॉल किया जाता है। `none` का अर्थ है कि मॉडल कोई टूल कॉल नहीं करेगा। `auto` का अर्थ है कि मॉडल संदेश उत्पन्न करने या टूल कॉल करने के बीच चुन सकता है। `required` का अर्थ है कि मॉडल को एक या अधिक टूल कॉल करने होंगे। `{"type": "function", "function": {"name": "my_function"}}` के माध्यम से एक विशेष फ़ंक्शन भी निर्दिष्ट कर सकते हैं।
</ParamField>

<ParamField body="parallel_tool_calls" type="boolean" default={true}>
  टूल उपयोग के दौरान समानांतर फ़ंक्शन कॉलिंग सक्षम करनी है या नहीं।
</ParamField>

<ParamField body="user" type="string">
  आपके अंतिम-उपयोगकर्ता का प्रतिनिधित्व करने वाला एक अद्वितीय पहचानकर्ता, जो दुरुपयोग की निगरानी और पहचान में मदद कर सकता है।
</ParamField>

## प्रतिक्रिया

सफल चैट पूर्णता प्रतिक्रिया।

<ResponseField name="id" type="string">
  चैट पूर्णता के लिए एक अद्वितीय पहचानकर्ता।
</ResponseField>

<ResponseField name="object" type="string">
  ऑब्जेक्ट प्रकार। हमेशा `chat.completion`।
</ResponseField>

<ResponseField name="created" type="integer">
  चैट पूर्णता बनाए जाने का Unix टाइमस्टैम्प (सेकंड में)।
</ResponseField>

<ResponseField name="model" type="string">
  चैट पूर्णता के लिए उपयोग किया गया मॉडल।
</ResponseField>

<ResponseField name="choices" type="object[]">
  चैट पूर्णता विकल्पों की सूची। यदि `n` 1 से अधिक है तो एक से अधिक हो सकते हैं।

  <Expandable title="properties">
    <ResponseField name="index" type="integer">
      विकल्पों की सूची में विकल्प का अनुक्रमांक।
    </ResponseField>

    <ResponseField name="message" type="object">
      मॉडल द्वारा उत्पन्न चैट पूर्णता संदेश।

      <Expandable title="properties">
        <ResponseField name="role" type="string">
          इस संदेश के लेखक की भूमिका। हमेशा `assistant`।
        </ResponseField>

        <ResponseField name="content" type="string | null">
          संदेश की सामग्री।
        </ResponseField>

        <ResponseField name="tool_calls" type="object[]">
          मॉडल द्वारा उत्पन्न टूल कॉल, जैसे फ़ंक्शन कॉल।

          <Expandable title="properties">
            <ResponseField name="id" type="string">
              टूल कॉल का ID।
            </ResponseField>

            <ResponseField name="type" type="string">
              टूल का प्रकार। वर्तमान में, केवल `function` समर्थित है।
            </ResponseField>

            <ResponseField name="function" type="object">
              मॉडल द्वारा कॉल किया गया फ़ंक्शन।

              <Expandable title="properties">
                <ResponseField name="name" type="string">
                  कॉल किए जाने वाले फ़ंक्शन का नाम।
                </ResponseField>

                <ResponseField name="arguments" type="string">
                  फ़ंक्शन को कॉल करने के लिए तर्क, मॉडल द्वारा JSON प्रारूप में उत्पन्न।
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="finish_reason" type="string">
      मॉडल ने टोकन उत्पन्न करना क्यों बंद किया। `stop`, `length`, `tool_calls`, या `content_filter` हो सकता है।
    </ResponseField>

    <ResponseField name="logprobs" type="object | null">
      विकल्प के लिए लॉग प्रायिकता जानकारी।
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  पूर्णता अनुरोध के लिए उपयोग आँकड़े।

  <Expandable title="properties">
    <ResponseField name="prompt_tokens" type="integer">
      प्रॉम्प्ट में टोकन की संख्या।
    </ResponseField>

    <ResponseField name="completion_tokens" type="integer">
      उत्पन्न पूर्णता में टोकन की संख्या।
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      अनुरोध में उपयोग किए गए कुल टोकन की संख्या (प्रॉम्प्ट + पूर्णता)।
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="system_fingerprint" type="string | null">
  यह फिंगरप्रिंट उस बैकएंड कॉन्फ़िगरेशन का प्रतिनिधित्व करता है जिसके साथ मॉडल चलता है। `seed` पैरामीटर के साथ उपयोग करके यह समझा जा सकता है कि बैकएंड में कब परिवर्तन किए गए हैं।
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api-llm.sunra.ai/v1/chat/completions \
    -H "Authorization: Bearer <SUNRA_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "openai/gpt-4o",
      "messages": [
        {
          "role": "system",
          "content": "You are a helpful assistant."
        },
        {
          "role": "user",
          "content": "What is the capital of France?"
        }
      ]
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api-llm.sunra.ai/v1/chat/completions",
      headers={
          "Authorization": "Bearer <SUNRA_KEY>",
          "Content-Type": "application/json"
      },
      json={
          "model": "openai/gpt-4o",
          "messages": [
              {"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "What is the capital of France?"}
          ]
      }
  )
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api-llm.sunra.ai/v1/chat/completions", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <SUNRA_KEY>",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "openai/gpt-4o",
      messages: [
        { role: "system", content: "You are a helpful assistant." },
        { role: "user", content: "What is the capital of France?" }
      ]
    })
  });
  const data = await response.json();
  console.log(data);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "chatcmpl-abc123",
    "object": "chat.completion",
    "created": 1677652288,
    "model": "openai/gpt-4o",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "The capital of France is Paris."
        },
        "finish_reason": "stop",
        "logprobs": null
      }
    ],
    "system_fingerprint": "fp_44709d6fcb",
    "usage": {
      "prompt_tokens": 25,
      "completion_tokens": 8,
      "total_tokens": 33
    }
  }
  ```
</ResponseExample>
