> 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/roboflow/roboflow-jp/deploy/serverless-hosted-api-v2/use-with-python-sdk.md).

# 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 Models では敏感に反応する場合があることに注意してください。

{% 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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