> 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/get-started/ja/gaido/run-model-serverless-api.md).

# モデル API エンドポイントを使用する

その [Serverless Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api) Roboflow のクラウド上の GPU でモデルとワークフローを実行します。画像を送信すると結果が返ってきます。セットアップするハードウェアも、稼働し続けるサーバーも必要ありません。

このガイドでは、ゼロから5分でモデルを実行できるようになります。画像内のオブジェクトは名前を付けるだけで見つけられ、既製のモデルで日常的な物体を検出し、自分のモデルも実行できます。すべて同じ Serverless Cloud API エンドポイントに対して行います。

## 名前を付けてオブジェクトを見つける

モデルに次のようないくつかの語を与えます `「taxi」`, `「blue bus」`、または `「bush」` とすると、画像内の一致するオブジェクトすべてを輪郭で示します。最初にセットアップや学習は不要です。これは [SAM3](https://docs.roboflow.com/models/supported-models/sam3).

{% tabs %}
{% tab title="HTTP（Python）" icon="webhook" %}
{% stepper %}
{% step %}

### APIキーを取得する

Roboflowアカウントを作成し、キーを次で見つけてください [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) そしてシェルから使えるようにします:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### 依存関係をインストールする

`supervision` は次を取り込みます `cv2` と `numpy`:

```bash
pip install -U supervision
```

{% endstep %}

{% step %}

### モデルを実行する

次にPOSTリクエストを送信します `/sam3/concept_segment` モデルを実行するために。 `sv.Detections.from_sam3` は、それらの結果を描画可能な形式に変換します [`supervision`](https://supervision.roboflow.com) 描画できます:

```python
import os
import base64
import cv2
import requests
import supervision as sv

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/traffic.jpg")
image_b64 = base64.b64encode(content).decode("utf-8")
h, w = image.shape[:2]

response = requests.post(
    "https://serverless.roboflow.com/sam3/concept_segment",
    headers={"Authorization": f"Bearer {os.environ['ROBOFLOW_API_KEY']}"},
    json={
        "image": {"type": "base64", "value": image_b64},
        "prompts": [
            {"type": "text", "text": "taxi"},
            {"type": "text", "text": "blue bus"},
            {"type": "text", "text": "bush"},
        ],
    },
)

detections = sv.Detections.from_sam3(response.json(), (w, h))
annotated = sv.MaskAnnotator().annotate(image.copy(), detections)
cv2.imwrite("sam3.jpg", annotated)
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="SDK（Python）" icon="python" %}
{% stepper %}
{% step %}

### APIキーを取得する

Roboflowアカウントを作成し、キーを次で見つけてください [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) そしてシェルから使えるようにします:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### 依存関係をインストールする

この2つのパッケージはモデルを呼び出し、その結果を描画します:

```bash
pip install -U inference-sdk supervision
```

{% endstep %}

{% step %}

### モデルを実行する

その [Inference SDK](https://docs.roboflow.com/reference/inference/inference-sdk) 画像をクラウドに送信し、結果を返します。 `sv.Detections.from_sam3` は、それらの結果を描画可能な形式に変換します [`supervision`](https://supervision.roboflow.com) 描画できます:

```python
import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/traffic.jpg")
h, w = image.shape[:2]

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

data = client.sam3_concept_segment(
    image,
    prompts=[
        {"type": "text", "text": "taxi"},
        {"type": "text", "text": "blue bus"},
        {"type": "text", "text": "bush"},
    ],
)

detections = sv.Detections.from_sam3(data, (w, h))
annotated = sv.MaskAnnotator().annotate(image.copy(), detections)
annotated = sv.BoxAnnotator().annotate(annotated, detections)
cv2.imwrite("sam3.jpg", annotated)
```

{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

応答には、各プロンプトで見つかった輪郭が一覧表示され、それぞれに信頼度スコアが付きます。 `sv.Detections.from_sam3` そのすべてを読み取ってくれます。

<figure><img src="/files/86db0a5230fef4246e56b13cff137935387fe1b0" alt="Outlines around taxis, a blue bus, and bushes from text prompts"><figcaption><p>テキストプロンプトから輪郭を抽出したオブジェクト</p></figcaption></figure>

視覚的プロンプト、例示ボックス、RLE出力を含む完全な SAM3 API については、 [SAM3 ドキュメント](https://docs.roboflow.com/models/supported-models/sam3).

## 既製のモデルで日常的なオブジェクトを検出する

{% tabs %}
{% tab title="HTTP（Python）" icon="webhook" %}
名前を付けた対象を輪郭で示す代わりに、一般的なオブジェクトの周囲にボックスを描画するには、 `POST /{project}/{version}` を呼び出します。これは `POST /sam3/concept_segment`の代わりにモデル ID を使う例です。この例では既製の [RF-DETR](https://docs.roboflow.com/models/supported-models/rf-detr) モデルを使用しており、車両、人、ペットなどの一般的なオブジェクトを検出できます:

```python
result = requests.post(
    "https://serverless.roboflow.com/coco/40",  # coco/40 は rfdetr-medium のエイリアスです
    data=image_b64,  # ボディに生の base64 を入れます。JSONではありません
    headers={
        "Authorization": f"Bearer {os.environ['ROBOFLOW_API_KEY']}",
        "Content-Type": "application/x-www-form-urlencoded",
    },
).json()
detections = sv.Detections.from_inference(result)

print(f"{len(detections)} 個のオブジェクトを検出しました")

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("rf-detr.jpg", annotated)
```

{% endtab %}

{% tab title="SDK（Python）" icon="python" %}
名前を付けた対象を輪郭で示す代わりに、一般的なオブジェクトの周囲にボックスを描画するには、 `client.infer()` を呼び出します。これは `client.sam3_concept_segment()`の代わりにモデル ID を使う例です。この例では既製の [RF-DETR](https://docs.roboflow.com/models/supported-models/rf-detr) モデルを使用しており、車両、人、ペットなどの一般的なオブジェクトを検出できます:

```python
result = client.infer(image, model_id="rfdetr-medium")
detections = sv.Detections.from_inference(result)

print(f"{len(detections)} 個のオブジェクトを検出しました")

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("rf-detr.jpg", annotated)
```

{% endtab %}
{% endtabs %}

<figure><img src="/files/f893ac8ee103dba7bf6bee7d9486692cd70be913" alt="RF-DETR bounding boxes for cars, buses, people, and motorcycles"><figcaption><p>RF-DETR は車、バス、人、バイクを検出します</p></figcaption></figure>

## 自分のモデル、または別のモデルを実行する

同じ `client.infer()` または `POST /{project}/{version}` の呼び出しで、任意のモデルをその `model_id`:

* で実行できます。Roboflow で学習したモデル。モデル ID をコピーします（形式は `{project}/{version}`です）を、次の場所にあるあなたのプロジェクトから取得します [Roboflow アプリ](https://app.roboflow.com)
* 次の公開モデル [Roboflow Universe](https://docs.roboflow.com/datasets/universe/universe/what-is-roboflow-universe)
* の既製の [学習済みモデル](https://docs.roboflow.com/models/pretrained-aliases) を、次のようなエイリアスで指定します `rfdetr-nano`, `rfdetr-seg-medium`、または `yolo26l-640` （inference SDK のみ）

## 次に進むには

クラウドでモデルを実行しています。ここからできることは次のとおりです:

* 同じモデルを自分のハードウェアで実行します。参照 [モデルをローカルで実行する](/get-started/ja/gaido/run-a-model-locally.md)
* 大規模モデルや安定したトラフィック向けに、専用のシングルテナントエンドポイントを取得します [Dedicated Deployments](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments)
* モデルとロジックをつないでアプリケーションにします [Workflows](https://docs.roboflow.com/workflows)
* 各リクエストのコストを次で確認します [Serverless の料金ページ](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/pricing)
