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 Python SDK
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 までのファイルアップロードをサポートしています。解像度の高い画像では制限に達することがあります。問題が発生した場合は、エンタープライズサポートの担当者に連絡するか、 フォーラム.
参照 Serverless Cloud API v1 レガシー API ドキュメントを参照してください。
HTTP API
REST API で使用する
Serverless Cloud API には、すべてのモデルと Workflows に対して 1 つのエンドポイントがあります:
HTTP エンドポイント
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.
ID of a Roboflow dataset corresponding to the model to use for inference OR workspace ID
ID of a Roboflow dataset version corresponding to the model to use for inference OR model ID
Roboflow API Key that will be passed to the model during initialization for artifact retrieval
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.
0.4The confidence threshold used to filter out keypoints that are not visible based on model confidence
0One 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.
jsonThe publically accessible URL of an image to use for inference.
One of base64 or numpy. Note, numpy input is not supported for Roboflow Hosted Inference.
base64Action 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.
If true, labels will be include in any inference visualization.
falseOne 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.
accurateThe amount to tradeoff between 0='fast' and 1='accurate'
0The 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.
300The IoU threhsold that must be met for a box pair to be considered duplicate during NMS
0.3The stroke width used when visualizing predictions
1If true, disables automatic image orientation
falseIf true, disables automatic contrast adjustment
falseIf true, disables automatic grayscale conversion
falseIf true, disables automatic static crop
falseIf true, the predictions will be prevented from registration by Active Learning (if the functionality is enabled)
falseParameter to be used when Active Learning data registration should happen against different dataset than the one pointed by model_id
The source of the inference request
externalThe detailed source information of the inference request
externalThe format of the prediction mask - polygon (default) or rle - applicable for instance segmentation models.
polygon可能な値: Successful Response
Validation Error
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 をサポートします。
Serverless Cloud API の呼び出し
モデルを実行:
Workflow を実行:
ライブ動画については、 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 では敏感に反応する場合がある点に注意してください。
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
プロジェクトの安定したライブエンドポイントを通じて推論を実行します。
最終更新
役に立ちましたか?