> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/reference/hi/inference/inference-sdk.md).

# Inference SDK

यह `inference-sdk` Python पैकेज प्रदान करता है `InferenceHTTPClient`, जो एक [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) से HTTP के माध्यम से बात करने के लिए एक क्लाइंट है। यही क्लाइंट Roboflow के [Serverless Hosted API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api), एक [Dedicated Deployment](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments), एक self-hosted server, या edge device पर चल रहे server के साथ काम करता है - केवल `api_url` बदलता है।

```bash
pip install inference-sdk
```

{% hint style="info" %}
`inference-sdk` एक पतला HTTP क्लाइंट है और स्वयं मॉडल नहीं चलाता। अपने स्वयं के Python process के अंदर मॉडल लोड और चलाने के लिए, [`inference` पैकेज](/reference/hi/inference/inference-python.md).
{% endhint %}

## क्विकस्टार्ट

आप URLs, file paths, PIL images, और NumPy arrays से images पर inference चला सकते हैं।

{% tabs %}
{% tab title="यूआरएल" %}

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration
import os

image_url = "https://media.roboflow.com/inference/soccer.jpg"

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))

results = client.infer(image_url, model_id="soccer-players-5fuqs/1")
print(results)
```

{% endtab %}

{% tab title="NumPy Array" %}

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration
import cv2
import os

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))

numpy_image = cv2.imread("path/to/local/image.jpg")
results = client.infer(numpy_image, model_id="soccer-players-5fuqs/1")
print(results)
```

{% endtab %}

{% tab title="PIL Image" %}

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration
from PIL import Image
import os

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))

pil_image = Image.open("path/to/local/image.jpg")
results = client.infer(pil_image, model_id="soccer-players-5fuqs/1")
print(results)
```

{% endtab %}
{% endtabs %}

यह `api_key_transport="header"` सेटिंग आपकी API key को केवल एक के रूप में भेजती है `Authorization: Bearer` header, जिससे यह URLs और logs से बाहर रहती है। इसके लिए release 1.5.0 या उससे नए inference server की आवश्यकता होती है; उपयोग करें `"both"` जब तक आप पुराने servers का उपयोग करते रहें। देखें [API key transport](/reference/hi/inference/inference-sdk/configuration.md#api-key-transport) तीनों modes के लिए।

self-hosted server के खिलाफ पहले request पर model weights डाउनलोड और सेट अप किए जाते हैं। आपकी network connection और model के आकार के आधार पर इस request में कुछ समय लग सकता है। एक बार model डाउनलोड हो जाने के बाद, बाद के requests बहुत तेज़ होते हैं। आप यह भी कर सकते हैं [मॉडलों को pre-load करना और loaded weights का प्रबंधन करना](/reference/hi/inference/inference-sdk/model-management.md) इस प्रक्रिया को नियंत्रित करने के लिए।

{% hint style="info" %}
मॉडल ID स्ट्रिंग से बनी होती है `<project_id>/<version_id>`. देखें [Workspace और Project IDs](/reference/hi/authentication/authentication/workspace-and-project-ids.md) अपने IDs खोजने के लिए।
{% endhint %}

### Self-hosted server

आप Inference Server को self-host भी कर सकते हैं (देखें [Inference CLI](/reference/hi/inference/inference-cli.md)), और फिर बदलें `api_url` में `InferenceHTTPClient`:

```python
client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key=os.environ["API_KEY"],
)
```

### AsyncIO क्लाइंट

```python
import asyncio
from inference_sdk import InferenceHTTPClient

CLIENT = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY"
)

image_url = "https://source.roboflow.com/pwYAXv9BTpqLyFfgQoPZ/u48G0UpWfk8giSw7wrU8/original.jpg"
loop = asyncio.get_event_loop()
result = loop.run_until_complete(
  CLIENT.infer_async(image_url, model_id="soccer-players-5fuqs/1")
)
```

## समानांतर और बैच inference

आप एक ही call में कई images पर prediction चलाना चाह सकते हैं। इसके दो parameters [`InferenceConfiguration`](/reference/hi/inference/inference-sdk/configuration.md) batching और parallelism को नियंत्रित करते हैं:

* `max_concurrent_requests` - concurrent requests की अधिकतम संख्या जिन्हें शुरू किया जा सकता है
* `max_batch_size` - elements की अधिकतम संख्या जिन्हें एक ही request में inject किया जा सकता है

यह निम्न सुधार सक्षम करता है:

* यदि आप inference container को एक शक्तिशाली on-prem GPU machine पर चलाते हैं, तो `max_batch_size` को सही ढंग से सेट करना throughput लाभ दे सकता है
* यदि आप hosted Roboflow API के विरुद्ध inference चलाते हैं, तो `max_concurrent_requests` से एक साथ कई images served की जाती हैं, जिससे throughput लाभ मिलता है
* दोनों विकल्पों का संयोजन उन clients के लिए लाभकारी हो सकता है जो inference container को machines के cluster पर चला रहे हैं: एक single node का load optimize किया जा सकता है और अलग-अलग nodes के लिए parallel requests एक ही समय में की जा सकती हैं

```python
from inference_sdk import InferenceHTTPClient

image_url = "https://source.roboflow.com/pwYAXv9BTpqLyFfgQoPZ/u48G0UpWfk8giSw7wrU8/original.jpg"

# ROBOFLOW_API_KEY को अपने Roboflow API Key से बदलें
CLIENT = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY"
)
predictions = CLIENT.infer([image_url] * 5, model_id="soccer-players-5fuqs/1")

print(predictions)
```

वे methods जो batching और parallelism का समर्थन करते हैं:

* `infer(...)` और `infer_async(...)`
* `ocr_image(...)` और `ocr_image_async(...)` (enforcing `max_batch_size=1`)
* `detect_gazes(...)` और `detect_gazes_async(...)` - **deprecated**, हमेशा फेंकता है `inference_sdk.http.errors.FeatureDeprecatedError`
* `get_clip_image_embeddings(...)` और `get_clip_image_embeddings_async(...)`

क्लाइंट यह भी समर्थन करता है [core foundation models](/reference/hi/inference/inference-sdk/core-models.md) (CLIP, DocTR), [Workflows चलाना](/reference/hi/inference/inference-sdk/workflows.md) multi-step pipelines के लिए, और [WebRTC streaming](/reference/hi/inference/inference-sdk/webrtc.md) real-time video inference के लिए। Webcams, camera streams, और video files को किसी model या Workflow के साथ process करने के लिए WebRTC का उपयोग करें।

## वास्तव में prediction के रूप में क्या लौटाया जाता है?

`InferenceHTTPClient` model serving API से responses के रूप में plain Python dictionaries लौटाता है। संशोधन केवल `visualization` key के संदर्भ में किया जाता है, जो server द्वारा generated prediction visualisation को बनाए रखता है और जिसे पसंदीदा format में transcode किया जा सकता है। Client-side rescaling केवल input size को समायोजित करता है।

## अगले चरण

* [कॉन्फ़िगरेशन](/reference/hi/inference/inference-sdk/configuration.md) - client और model parameters, context managers, और defaults.
* [मॉडल प्रबंधन](/reference/hi/inference/inference-sdk/model-management.md) - server पर models को pre-load, list, और unload करना.
* [कोर मॉडल्स](/reference/hi/inference/inference-sdk/core-models.md) - CLIP और DocTR endpoints.
* [वर्कफ़्लोज़](/reference/hi/inference/inference-sdk/workflows.md) - client के माध्यम से एक Workflow चलाएँ.
* [WebRTC Streaming](/reference/hi/inference/inference-sdk/webrtc.md) - model या Workflow के माध्यम से video stream करें.
