# Python SDK で使用

Python で作業している場合、Serverless API とやり取りする最も便利な方法は Inference Python SDK を使用することです。

を使用するには [Inference SDK](https://inference.roboflow.com/inference_helpers/inference_sdk/)、まずインストールします:

```
pip install inference-sdk
```

Serverless Hosted API にリクエストを送るには、次のコードを使用します:

<pre class="language-python"><code class="lang-python"><strong>from inference_sdk import InferenceHTTPClient
</strong>
CLIENT = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key="API_KEY"
)

result = CLIENT.infer("image.jpg", model_id="model-id/1")
print(result)
</code></pre>

上記では、 [model ID](https://docs.roboflow.com/developer/authentication/workspace-and-project-ids) および [API key](https://docs.roboflow.com/developer/authentication/find-your-roboflow-api-key)を指定します。このコードはモデルを実行し、結果を返します。

#### Roboflow Instant Model

Serverless API は Roboflow の実行もサポートしています [Instant Model](/roboflow/roboflow-jp/train/roboflow-instant.md)。Instant Model は他のモデルと同様に実行できますが、confidence threshold は Instant Model では影響を受けやすい点に注意してください。

{% hint style="info" %}
最適な confidence は、モデルが学習した画像の枚数によって異なります。最適な confidence threshold は通常 0.85 から 0.99 の範囲です。
{% endhint %}

```python
configuration = InferenceConfiguration(
    confidence_threshold=0.95
)
CLIENT.configure(configuration)

result = CLIENT.infer("image.jpg", model_id="roboflow-instant-model-id/1")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roboflow.com/roboflow/roboflow-jp/deploy/serverless-hosted-api-v2/use-with-python-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
