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

# जावास्क्रिप्ट / टाइपस्क्रिप्ट

[![@sunra/client npm package](https://img.shields.io/npm/v/@sunra/client?color=%237527D7\&label=JavaScript\&style=flat-square)](https://www.npmjs.com/package/@sunra/client)

### परिचय

जावास्क्रिप्ट/टाइपस्क्रिप्ट के लिए क्लाइंट लाइब्रेरी Sunra की सेवाओं के साथ बातचीत करने के लिए एक उपयोग में आसान इंटरफ़ेस प्रदान करती है।

### स्थापना

क्लाइंट को अपने प्रोजेक्ट में एकीकृत करने के लिए, इसे npm का उपयोग करके स्थापित करें:

<CodeGroup>
  ```bash npm theme={null}
  npm install @sunra/client
  ```

  ```bash pnpm theme={null}
  pnpm add @sunra/client
  ```

  ```bash yarn theme={null}
  yarn add @sunra/client
  ```
</CodeGroup>

### सुविधाएँ

#### एंडपॉइंट्स को कॉल करना

Sunra एक कतार प्रणाली के माध्यम से एंडपॉइंट अनुरोधों का प्रबंधन करता है, जिससे विश्वसनीयता और मापनीयता सुनिश्चित होती है। अनुरोध सबमिट करने और परिणाम की प्रतीक्षा करने के लिए `subscribe` विधि का उपयोग करें।

**उदाहरण:**

```javascript theme={null}
import { sunra } from "@sunra/client";

const result = await sunra.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", {
  input: {
    prompt: "एक कांच की चायदानी जिसमें खिले हुए फूल की चाय है, जो एक लकड़ी की मेज पर एक धूप वाली खिड़की के पास रखी है, जिसमें सुबह की कोमल रोशनी है।",
    "aspect_ratio": "16:9",
    "output_format": "jpeg",
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      console.log(update.logs)
    }
  },
});

console.log(result.data);
console.log(result.requestId);
```

#### कतार प्रबंधन

इन विधियों से अपने अनुरोधों का प्रबंधन करें:

##### अनुरोध सबमिट करना

एक अनुरोध सबमिट करें और बाद में उपयोग के लिए `request_id` प्राप्त करें।

**उदाहरण:**

```javascript theme={null}
import { sunra } from "@sunra/client";

const { request_id } = await sunra.queue.submit("black-forest-labs/flux-kontext-max", {
  input: {
    prompt: "एक कांच की चायदानी जिसमें खिले हुए फूल की चाय है, जो एक लकड़ी की मेज पर एक धूप वाली खिड़की के पास रखी है, जिसमें सुबह की कोमल रोशनी है।",
    "aspect_ratio": "16:9",
    "output_format": "jpeg",
  },
});
```

##### अनुरोध की स्थिति की जाँच करना

अनुरोध की स्थिति प्राप्त करें।

**उदाहरण:**

```javascript theme={null}
import { sunra } from "@sunra/client";

const status = await sunra.queue.status({
  requestId: "pd_eTYYuw4EqYLzRBHgnAMHA8zH",
  logs: true,
});
```

##### अनुरोध के परिणाम प्राप्त करना

एक पूर्ण अनुरोध का परिणाम प्राप्त करें।

**उदाहरण:**

```javascript theme={null}
import { sunra } from "@sunra/client";

const result = await sunra.queue.result({
  requestId: "pd_eTYYuw4EqYLzRBHgnAMHA8zH",
});

console.log(result.data);
console.log(result.requestId);
```

#### भंडारण

`storage` API आपको फ़ाइलें अपलोड करने और एक URL प्राप्त करने की अनुमति देता है, जिसका उपयोग आपके मॉडल एंडपॉइंट अनुरोधों में किया जा सकता है। यह उन मॉडलों के लिए विशेष रूप से उपयोगी है जिन्हें फ़ाइल इनपुट की आवश्यकता होती है, जैसे कि इमेज-टू-वीडियो या स्पीच-टू-टेक्स्ट।

<Note>अधिकतम फ़ाइल आकार: 100MB</Note>

##### ब्राउज़र में फ़ाइलें अपलोड करना

आप उपयोगकर्ताओं को सीधे उनके ब्राउज़र से फ़ाइलें अपलोड करने की अनुमति दे सकते हैं। निम्नलिखित उदाहरण दिखाता है कि फ़ाइल का चयन करने और उसे अपलोड करने के लिए `<input type="file">` तत्व का उपयोग कैसे करें।

<CodeGroup>
  ```javascript upload.js theme={null}
  import { sunra } from "@sunra/client";

  const fileInput = document.getElementById('file-input');

  fileInput.addEventListener('change', async (event) => {
    const file = event.target.files[0];
    if (file) {
      try {
        const url = await sunra.storage.upload(file);
        console.log('फ़ाइल सफलतापूर्वक अपलोड हो गई:', url);
        // अब आप इस URL का उपयोग मॉडल एंडपॉइंट के साथ कर सकते हैं
      } catch (error) {
        console.error('अपलोड विफल:', error);
      }
    }
  });
  ```

  ```html index.html theme={null}
  <input type="file" id="file-input" />
  ```
</CodeGroup>

##### Node.js में फ़ाइलें अपलोड करना

Node.js के साथ सर्वर-साइड पर, आप स्थानीय फाइल सिस्टम से फ़ाइलें पढ़ सकते हैं और उन्हें अपलोड कर सकते हैं।

```javascript theme={null}
import { sunra } from "@sunra/client";
import { readFile } from "node:fs/promises";
import { basename } from "node:path";

async function uploadLocalFile(filePath) {
  try {
    const buffer = await readFile(filePath);
    // क्लाइंट को एक फ़ाइल ऑब्जेक्ट की आवश्यकता होती है, जिसे हम बफर से बना सकते हैं
    const file = new File([buffer], basename(filePath));

    const url = await sunra.storage.upload(file);
    console.log('फ़ाइल सफलतापूर्वक अपलोड हो गई:', url);
    return url;
  } catch (error) {
    console.error('अपलोड विफल:', error);
  }
}

uploadLocalFile("./path/to/your/image.png");
```

#### मॉडल एंडपॉइंट्स के साथ स्वचालित अपलोड

जावास्क्रिप्ट SDK आपके लिए स्वचालित रूप से फ़ाइल अपलोड को संभाल सकता है। जब आप किसी मॉडल एंडपॉइंट के इनपुट में `File` ऑब्जेक्ट, `Blob`, या बेस 64 डेटा URI पास करते हैं, तो SDK पहले इसे स्टोरेज पर अपलोड करेगा और फिर अनुरोध में परिणामी URL का उपयोग करेगा।

यह प्रक्रिया को सरल बनाता है क्योंकि आपको एक अलग अपलोड चरण करने की आवश्यकता नहीं है।

```javascript theme={null}
import { sunra } from "@sunra/client";

// ब्राउज़र फ़ाइल इनपुट से एक फ़ाइल ऑब्जेक्ट स्वचालित रूप से अपलोड हो जाएगा
const fileInput = document.getElementById('file-input');
const file = fileInput.files[0];

const result = await sunra.subscribe("some-model-that-takes-images", {
  input: {
    image: file, // SDK इस फ़ाइल को स्वचालित रूप से अपलोड करता है
    prompt: "छवि के साथ क्या करना है इसका वर्णन करने वाला एक प्रॉम्प्ट"
  }
});

// एक बेस 64 डेटा URI भी स्वचालित रूप से अपलोड हो जाएगा
const base64Image = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...";

const result2 = await sunra.subscribe("some-model-that-takes-images", {
  input: {
    image: base64Image, // SDK इसे स्वचालित रूप से एक ब्लॉब में परिवर्तित करता है और इसे अपलोड करता है
    prompt: "छवि के साथ क्या करना है इसका वर्णन करने वाला एक प्रॉम्प्ट"
  }
});
```

### सहायता

सहायता या चर्चा के लिए हमारे समुदाय में शामिल हों:

* **डिस्कॉर्ड समुदाय**: [हमसे जुड़ें](https://discord.gg/897qCzvCcU)
* **गिटहब रिपोजिटरी**: [यहां जाएं](https://github.com/sunra-ai/sunra-clients)

हम आपकी सहायता के लिए यहां हैं!
