For the complete documentation index, see llms.txt. This page is also available as Markdown.

Serverless Cloud API

Roboflow Cloud の GPU アクセラレーション付きオートスケーリングインフラストラクチャ上で Workflow とモデル推論を実行します。

概要

Roboflow にデプロイされたモデルには REST API があり、それを通じて画像に対して推論を実行できます。このデプロイ方法は、デプロイ先デバイスで常時インターネット接続がある環境に最適です。

アプリ内では、このエンドポイントは「Serverless Cloud API」、またはスペースが限られている場合(例: Workflow エディタのランタイムピッカー)には「Cloud API」と表示されます。A 専用デプロイ エンドポイント(*.roboflow.cloud)は「Dedicated Cloud API」と表示され、旧来の v1 エンドポイントは「Hosted API (Legacy)」と表示されます。これらのラベルは、以前の「Serverless Hosted API」と「Serverless API V2」という名称に置き換わるものです。

Serverless Cloud API は以下で使用できます:

Inference サーバー

私たちの Serverless Cloud API は、 Inference Serverによって支えられています。つまり、以下に示すように、Serverless Cloud API とセルフホスティングの विकल्पを簡単に切り替えることができます。

from inference_sdk import InferenceHTTPClient, InferenceConfiguration

CLIENT = InferenceHTTPClient(
    # api_url="http://localhost:9001" # セルフホストの Inference サーバー
    api_url="https://serverless.roboflow.com", # 私たちの Serverless Cloud API
    api_key="API_KEY" # プライベートなモデルとデータにアクセスするためのオプション
).configure(InferenceConfiguration(api_key_transport="header"))

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

その api_key_transport="header" 設定はキーを次の形式でのみ送信します: Authorization: Bearer ヘッダー。URL やログに鍵を残さないようにします。新規コードではこれが推奨です。Inference 1.5.0 より前のサーバーはこのヘッダーを読み取れないため、 api_key_transport="both" を使いつつ、呼び出しはそのままにしてください。参照先は API キーの送信.

制限

私たちの Serverless Cloud API は、最大 20MB までのファイルアップロードをサポートしています。解像度の高い画像では制限に達することがあります。問題が発生した場合は、エンタープライズサポートの担当者に連絡するか、 フォーラム.

リクエストが大きすぎる場合は、添付画像を縮小することを推奨します。画像はサーバーで受信された後、モデルアーキテクチャが受け付ける入力サイズに自動で縮小されるため、通常これは性能の低下にはつながりません。 Python SDK などの一部の SDK では、API に送信する前に画像をモデルアーキテクチャの入力サイズへ自動的に縮小します。


参照 Serverless Cloud API v1 レガシー API ドキュメントを参照してください。

HTTP API

REST API で使用する

Serverless Cloud API には、すべてのモデルと Workflows に対して 1 つのエンドポイントがあります:

HTTP エンドポイント

Legacy Infer From Request

post

Legacy inference endpoint for object detection, instance segmentation, and classification.

Args: background_tasks: (BackgroundTasks) pool of fastapi background tasks dataset_id (str): ID of a Roboflow dataset corresponding to the model to use for inference OR workspace ID version_id (str): ID of a Roboflow dataset version corresponding to the model to use for inference OR model ID api_key (Optional[str], default None): Roboflow API Key passed to the model during initialization for artifact retrieval. # Other parameters described in the function signature...

Returns: Union[InstanceSegmentationInferenceResponse, KeypointsDetectionInferenceRequest, ObjectDetectionInferenceResponse, ClassificationInferenceResponse, MultiLabelClassificationInferenceResponse, SemanticSegmentationInferenceResponse, Any]: The response containing the inference results.

パスパラメータ
dataset_idstring必須

ID of a Roboflow dataset corresponding to the model to use for inference OR workspace ID

version_idstring必須

ID of a Roboflow dataset version corresponding to the model to use for inference OR model ID

クエリパラメータ
api_keystring · ヌル許容オプション

Roboflow API Key that will be passed to the model during initialization for artifact retrieval

confidenceany ofオプション

The confidence threshold used to filter out predictions. Pass a float in [0, 1], or "best" to use F1-optimal thresholds from model evaluation, or "default" to use the model's built-in default.

Default: 0.4
numberオプション
または
string · enumオプション可能な値:
keypoint_confidencenumberオプション

The confidence threshold used to filter out keypoints that are not visible based on model confidence

Default: 0
formatstringオプション

One of 'json' or 'image'. If 'json' prediction data is return as a JSON string. If 'image' prediction data is visualized and overlayed on the original input image.

Default: json
imagestring · ヌル許容オプション

The publically accessible URL of an image to use for inference.

image_typestring · ヌル許容オプション

One of base64 or numpy. Note, numpy input is not supported for Roboflow Hosted Inference.

Default: base64
class_filterstring · ヌル許容オプション

Action recognition only: comma separated classes. The subset of a fine-tuned model's classes to report. A zero-shot model answers in its own words and ignores it.

labelsboolean · ヌル許容オプション

If true, labels will be include in any inference visualization.

Default: false
mask_decode_modestring · ヌル許容オプション

One of 'accurate' or 'fast'. If 'accurate' the mask will be decoded using the original image size. If 'fast' the mask will be decoded using the original mask size. 'accurate' is slower but more accurate.

Default: accurate
tradeoff_factornumber · ヌル許容オプション

The amount to tradeoff between 0='fast' and 1='accurate'

Default: 0
max_detectionsintegerオプション

The maximum number of detections to return. This is used to limit the number of predictions returned by the model. The model may return more predictions than this number, but only the top max_detections predictions will be returned.

Default: 300
overlapnumberオプション

The IoU threhsold that must be met for a box pair to be considered duplicate during NMS

Default: 0.3
strokeintegerオプション

The stroke width used when visualizing predictions

Default: 1
disable_preproc_auto_orientboolean · ヌル許容オプション

If true, disables automatic image orientation

Default: false
disable_preproc_contrastboolean · ヌル許容オプション

If true, disables automatic contrast adjustment

Default: false
disable_preproc_grayscaleboolean · ヌル許容オプション

If true, disables automatic grayscale conversion

Default: false
disable_preproc_static_cropboolean · ヌル許容オプション

If true, disables automatic static crop

Default: false
disable_active_learningboolean · ヌル許容オプション

If true, the predictions will be prevented from registration by Active Learning (if the functionality is enabled)

Default: false
active_learning_target_datasetstring · ヌル許容オプション

Parameter to be used when Active Learning data registration should happen against different dataset than the one pointed by model_id

sourcestring · ヌル許容オプション

The source of the inference request

Default: external
source_infostring · ヌル許容オプション

The detailed source information of the inference request

Default: external
response_mask_formatstring · enum · ヌル許容オプション

The format of the prediction mask - polygon (default) or rle - applicable for instance segmentation models.

Default: polygon可能な値:
レスポンス
200

Successful Response

application/json
または
または
または
または
または
または
または
anyオプション
post/{dataset_id}/{version_id}
POST /{dataset_id}/{version_id} HTTP/1.1
Accept: */*
{
  "visualization": "text",
  "inference_id": "text",
  "frame_id": 1,
  "time": 1,
  "image": [
    {
      "width": 1,
      "height": 1
    }
  ],
  "predictions": [
    {
      "x": 1,
      "y": 1,
      "width": 1,
      "height": 1,
      "confidence": 1,
      "class": "text",
      "class_id": 1,
      "detection_id": "text",
      "parent_id": "text",
      "class_confidence": 1,
      "points": [
        {
          "x": 1,
          "y": 1
        }
      ],
      "mask_format": "polygon"
    }
  ]
}

画像上でモデルを実行

Roboflow は複数のランタイムで推論を公開しています。正しい選択は、単一のモデルを呼び出すのか Workflow を呼び出すのか、必要なスループット、そしてワークロードがどこで実行されるかによって決まります。

このページは簡単な概要です。詳細な推論リファレンスは、 製品ドキュメントにあります。これは同じドキュメントサイトの一部です。より詳しい内容がある場所へのクロスリンクを用意しています。

推論ランタイム

ランタイム
次の場合に使用
参照

Serverless Cloud API (serverless.roboflow.com)

デフォルト。ホスト型、自動スケーリング対応、モデルと Workflows をサポートします。

専用デプロイメント

予測可能なレイテンシ、高いスループット、または固定 GPU タイプが必要な場合。Roboflow が管理します。

Roboflow Inference (セルフホスト)

オンプレミス、エッジデバイス、エアギャップ環境、または VPC の外に出せないワークロード。オープンソースです。

Serverless Cloud API の呼び出し

モデルを実行:

Workflow を実行:

キーを ?api_key= クエリパラメータまたは api_key body フィールドとして送る方法はレガシーな手段です。今でも動作しますが、 Authorization: Bearer ヘッダーを使えば、キーを URL やログに残さずに済みます。参照は REST API で認証する.

ライブ動画については、 Serverless Video Streaming APIをご覧ください。大規模な画像・動画セットの非同期処理については、 バッチ処理.

非推奨: Serverless v1

旧来のタスク固有エンドポイント - detect.roboflow.com, classify.roboflow.com, outline.roboflow.com, segment.roboflow.com - は 非推奨です. 後方互換性のため今でも応答しますが、新しいコードでは serverless.roboflow.com を使うべきです。

もしスニペットが *.roboflow.com のタスクホストを指しているなら、それはレガシーとして扱い、上記の Serverless Cloud API 形式に置き換えてください。

Python SDK

Python SDK で使用する

Python で作業しているなら、Serverless Cloud API とやり取りする最も簡単な方法は Inference Python SDK を使うことです。

使用するには Inference SDK、まずインストールします:

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

上では、 モデル ID および API キーを指定します。このコードはモデルを実行し、結果を返します。

Roboflow Instant Model

Serverless Cloud API は Roboflow の Instant Modelの実行もサポートしています。Instant Model も他のモデルと同様に実行できますが、信頼度しきい値は Instant Model では敏感に反応する場合がある点に注意してください。

最適な confidence は、モデルが学習された画像枚数によって異なります。最適なしきい値は通常 0.85 から 0.99 の範囲です。

configure(...) は設定全体を置き換えるため、 api_key_transport を、適用するすべての設定に含めてください。

Python SDK で動画をストリーミングする

Inference SDK の WebRTC クライアントを使って、動画上で物体検出モデルを実行します。Serverless Video Streaming API は Roboflow Cloud で動画を処理し、各フレームごとの予測を返します。

SDK とその WebRTC 依存関係をインストールして supervision:

置き換えてください API_KEY および model-id/1 を API キーとモデル ID に置き換えてください。Web カメラや RTSP カメラからのストリーミング、各フレームの処理、または Workflow の実行方法は、 Serverless Video Streaming API ガイド.

CLI

Roboflow 上で学習したモデル、または Roboflow Universe.

で利用できるオープンソースモデルを実行するには、 roboflow infer をコマンドラインで実行すると、CLI は画像を Roboflow API に送信し、予測を出力します。

コマンド

オプション

フラグ
説明

-m, --model

のモデル ID project/version 形式(必須)

-c, --confidence

信頼度しきい値、0.0–1.0(デフォルト: 0.5)

-o, --overlap

重なり/NMS しきい値、0.0–1.0(デフォルト: 0.5)

-t, --type

モデルタイプ(自動検出を省略): object-detection, classification, instance-segmentation, semantic-segmentation, keypoint-detection

Roboflow Universe のオープンソースモデルを使って推論を実行します。たとえば、 poker-cards データセット:

ワークスペースは、設定済みのワークスペースがデフォルトになります。別のワークスペースのモデルを使うには:

自動検出 API 呼び出しを省略するにはモデルタイプを指定します:

JSON出力

使用 --json して、スクリプトや自動化のための構造化された予測データを取得します:

対応しているすべてのパラメータは、 roboflow infer --help.

MCP サーバー

AI エージェントを MCP サーバー に接続すると、これらのツールで画像上のモデルを実行できます:

ツール
説明

models_infer

学習済みモデルを使って、画像に対してホスト型推論を実行します。

workflows_run

1 枚または複数の画像に対して保存済みの Workflow を実行します。

project_deployment_run

プロジェクトの安定したライブエンドポイントを通じて推論を実行します。

最終更新

役に立ちましたか?