Alibaba Cloud Model Studio は、OpenAI 互換のバッチファイル API を提供します。ファイルを用いてタスクを一括で送信できます。システムは非同期で処理を行い、タスク完了時または最大待機時間に達した時点で結果を返します。コストはリアルタイム呼び出しの50 %のみです。遅延が厳密に要求されないデータ分析、モデル評価、その他の大規模ワークロードに最適です。
コンソールを使用する場合は、「バッチ推論」をご参照ください。
ワークフロー
前提条件
OpenAI SDK(Python、Node.js)または HTTP API を使用して、バッチファイル API を呼び出します。
API キーの取得: 「Model Studio API キーを環境変数として取得および設定」をご参照ください。
SDK のインストール(任意): 使用する予定がある場合は、「OpenAI SDK」をインストールしてください。
サービスエンドポイント
中国本土:
https://dashscope.aliyuncs.com/compatible-mode/v1国際:
https://dashscope-intl.aliyuncs.com/compatible-mode/v1
可用性
国際
「国際デプロイモード」では、エンドポイントおよびデータストレージの両方がシンガポールに配置されます。モデル推論の計算リソースは、中国本土を除くグローバルなリージョン間で動的にスケジュールされます。
サポートされるモデル: qwen-max、qwen-plus、qwen-flash、qwen-turbo。
中国本土
「中国本土デプロイモード」では、エンドポイントおよびデータストレージの両方が中国(北京)に配置されます。モデル推論の計算リソースは、中国本土内でのみ利用可能です。
サポートされるモデル:
テキスト生成モデル: Qwen-Max、Plus、Flash、Long の安定版および一部の
latestバージョン。QwQ シリーズ(qwq-plus)および一部のサードパーティモデル(deepseek-r1、deepseek-v3)もサポートされます。マルチモーダルモデル: Qwen-VL-Max、Plus、Flash の安定版および一部の
latestバージョン。Qwen-OCR モデルもサポートされます。テキスト埋め込みモデル: text-embedding-v4。
一部のモデルは思考モードをサポートしています。有効化すると、このモードは思考
トークンを生成し、コストが増加します。qwen3.5シリーズ(例:qwen3.5-plusおよびqwen3.5-flash)では、思考モードがデフォルトで有効になっています。ハイブリッド思考モデルを使用する場合は、明示的にenable_thinkingパラメーター(trueまたはfalse)を設定してください。
クイックスタート
本番タスクを実行する前に、batch-test-model を使用してテストを行ってください。このテストモデルは推論をスキップし、固定の成功応答を返すことで、API 呼び出しチェーンおよびデータ形式の検証が可能です。
batch-test-model の制限事項:
テストファイルは「入力ファイルの要件」を満たす必要があります。ファイルサイズは1 MB以下、行数は100 行以内である必要があります。
同時実行数制限: 最大2並列タスクまで。
コスト: テストモデルはモデル推論料金は発生しません。
ステップ 1: 入力ファイルの準備
以下の内容で test_model.jsonl という名前のファイルを作成します:
{"custom_id":"1","method":"POST","url":"/v1/chat/ds-test","body":{"model":"batch-test-model","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Hello! How can I help you?"}]}}
{"custom_id":"2","method":"POST","url":"/v1/chat/ds-test","body":{"model":"batch-test-model","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is 2+2?"}]}}マルチモーダルモデル(例: qwen-vl-plus)では、ファイル URL および Base64 エンコードされた入力がサポートされます:
{"custom_id":"image-url","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},{"type":"text","text":"Describe this image."}]}]}}
{"custom_id":"image-base64","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA8ADwAAD..."}},{"type":"text","text":"Describe this image."}]}]}}ステップ 2: コードの実行
プログラミング言語に応じたサンプルコードスニペットを選択し、入力ファイルと同じディレクトリに保存して実行します。このコードは、アップロード、タスク作成、ステータスポーリング、結果ダウンロードの全ワークフローを処理します。
ファイルパスやその他のパラメーターを調整する場合は、必要に応じてコードを修正してください。
ステップ 3: テスト結果の確認
タスクが成功した後、結果ファイル result.jsonl には固定の応答 {"content":"This is a test result."} が含まれます:
{"id":"a2b1ae25-21f4-4d9a-8634-99a29926486c","custom_id":"1","response":{"status_code":200,"request_id":"a2b1ae25-21f4-4d9a-8634-99a29926486c","body":{"created":1743562621,"usage":{"completion_tokens":6,"prompt_tokens":20,"total_tokens":26},"model":"batch-test-model","id":"chatcmpl-bca7295b-67c3-4b1f-8239-d78323bb669f","choices":[{"finish_reason":"stop","index":0,"message":{"content":"This is a test result."}}],"object":"chat.completion"}},"error":null}
{"id":"39b74f09-a902-434f-b9ea-2aaaeebc59e0","custom_id":"2","response":{"status_code":200,"request_id":"39b74f09-a902-434f-b9ea-2aaaeebc59e0","body":{"created":1743562621,"usage":{"completion_tokens":6,"prompt_tokens":20,"total_tokens":26},"model":"batch-test-model","id":"chatcmpl-1e32a8ba-2b69-4dc4-be42-e2897eac9e84","choices":[{"finish_reason":"stop","index":0,"message":{"content":"This is a test result."}}],"object":"chat.completion"}},"error":null}本番タスクの実行
入力ファイルの要件
フォーマット: UTF-8 エンコードの JSONL(1 行につき 1 つの独立した JSON オブジェクト)。
サイズ制限: 1 ファイルあたり最大 50,000 リクエスト、ファイルサイズは最大 500 MB。
行数制限: 各 JSON オブジェクトは最大 6 MB かつモデルのコンテキストウィンドウ内であること。
一貫性: 同じファイル内のすべてのリクエストは、同じモデルおよび思考モード(該当する場合)を使用する必要があります。
一意の識別子: 各リクエストには、ファイル内で一意の custom_id フィールドを含める必要があります。これは結果とのマッチングに使用されます。
シナリオ 1: テキストチャット
サンプルファイルの内容:
{"custom_id":"1","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-plus","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Hello!"}]}}
{"custom_id":"2","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-plus","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is 2+2?"}]}}シナリオ 2: 画像および動画理解
マルチモーダルモデル(例: qwen-vl-plus)では、ファイル URL および Base64 エンコードされた入力がサポートされます。
{"custom_id":"image-url","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},{"type":"text","text":"Describe this image."}]}]}}
{"custom_id":"image-base64","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA8ADwAAD..."}},{"type":"text","text":"Describe this image."}]}]}}
{"custom_id":"video-url","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"video","video":"https://example.com/video.mp4"},{"type":"text","text":"Describe this video."}]}]}}
{"custom_id":"video-base64","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"video","video":["data:image/jpeg;base64,{frame1}","data:image/jpeg;base64,{frame2}","data:image/jpeg;base64,{frame3}"]},{"type":"text","text":"Describe this video."}]}]}}
{"custom_id":"multi-image-url","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"https://example.com/image1.jpg"}},{"type":"image_url","image_url":{"url":"https://example.com/image2.jpg"}},{"type":"text","text":"Compare these two images."}]}]}}
{"custom_id":"multi-image-base64","method":"POST","url":"/v1/chat/completions","body":{"model":"qwen-vl-plus","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,{image1_base64}"}},{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,{image2_base64}"}},{"type":"text","text":"Compare these two images."}]}]}}上記の例の Base64 文字列は省略されています。以下の Python コードを使用して、完全なエンコーディングを生成してください。
詳細(ファイル制限、MIME タイプ、エンコーディング方法を含む)については、「ローカルファイルの渡し方(Base64 エンコーディングまたはファイルパス)」をご参照ください。
JSONL バッチ生成ツール
このツールを使用して、JSONL ファイルをすばやく生成できます。
1. 入力ファイルの変更
test_model.jsonlファイルで、`model` パラメーターを使用するモデルに設定し、`url` フィールドを設定します:モデルタイプ
url
テキスト生成/マルチモーダルモデル
/v1/chat/completionsテキスト埋め込みモデル
/v1/embeddingsまたは、上記の「JSONL バッチ生成ツール」を使用して、正式なタスク用の新しいファイルを生成してください。
modelフィールドとurlフィールドが正しいことを確認してください。
2. クイックスタートコードの変更
入力ファイルパスをファイル名に変更します。
エンドポイントパラメーターを、入力ファイル内の url フィールドと一致するように設定します。
3. コードの実行と結果の待機
タスクが完了すると、成功したリクエストの結果はローカルの result.jsonl ファイルに保存されます。失敗したリクエストがある場合は、エラーの詳細が error.jsonl ファイルに保存されます。
成功した結果(
output_file_id): 各行は元のリクエスト 1 件に対応し、custom_idおよびresponseを含みます。{"id":"3a5c39d5-3981-4e4c-97f2-e0e821893f03","custom_id":"req-001","response":{"status_code":200,"request_id":"3a5c39d5-3981-4e4c-97f2-e0e821893f03","body":{"created":1768306034,"usage":{"completion_tokens":654,"prompt_tokens":14,"total_tokens":668},"model":"qwen-plus","id":"chatcmpl-3a5c39d5-3981-4e4c-97f2-e0e821893f03","choices":[{"finish_reason":"stop","index":0,"message":{"role":"assistant","content":"Hello! Hangzhou West Lake is a famous scenic spot in China, located in the western part of Hangzhou City, Zhejiang Province, hence the name \"West Lake\". It is one of China's top ten scenic spots and a World Cultural Heritage site (listed by UNESCO in 2011). It is renowned worldwide for its beautiful natural scenery and profound cultural heritage.\n\n### I. Natural Landscape\nWest Lake is surrounded by mountains on three sides and borders the city on one side, covering an area of approximately 6.39 square kilometers, shaped like a ruyi scepter with rippling blue waters. The lake is naturally or artificially divided into multiple water areas by Solitary Hill, Bai Causeway, Su Causeway, and Yanggong Causeway, forming a layout of \"one mountain, two pagodas, three islands, and three causeways\".\n\nMain attractions include the following:\n- **Spring Dawn at Su Causeway**: During the Northern Song Dynasty, the great literary figure Su Dongpo, while serving as the prefect of Hangzhou, led the dredging of West Lake and used the excavated silt to build a causeway, later named \"Su Causeway\". In spring, peach blossoms and willows create a picturesque scene.\n- **Lingering Snow on Broken Bridge**: Located at the eastern end of Bai Causeway, this is where the reunion scene from the Legend of the White Snake took place. After snowfall in winter, it is particularly famous for its silver-white appearance.\n- **Leifeng Pagoda at Sunset**: Leifeng Pagoda glows golden under the setting sun and was once one of the \"Ten Scenes of West Lake\".\n- **Three Pools Mirroring the Moon**: On Xiaoyingzhou Island in the lake, there are three stone pagodas. During the Mid-Autumn Festival, lanterns can be lit inside the pagodas, creating a harmonious interplay of moonlight, lamplight, and lake reflections.\n- **Autumn Moon over Calm Lake**: Located at the western end of Bai Causeway, it is an excellent spot for viewing the moon over the lake.\n- **Viewing Fish at Flower Harbor**: Known for viewing flowers and fish, with peonies and koi complementing each other beautifully in the garden.\n\n### II. Cultural History\nWest Lake not only boasts beautiful scenery but also carries rich historical and cultural significance:\n- Since the Tang and Song dynasties, numerous literati such as Bai Juyi, Su Dongpo, Lin Bu, and Yang Wanli have left poems here.\n- Bai Juyi oversaw the construction of \"Bai Causeway\" and dredged West Lake, benefiting the local people.\n- Around West Lake are many historical sites, including Yuewang Temple (commemorating national hero Yue Fei), Lingyin Temple (a millennium-old Buddhist temple), Liuhe Pagoda, and Longjing Village (the origin of Longjing tea, one of China's top ten famous teas).\n\n### III. Cultural Symbolism\nWest Lake is regarded as a representative of \"paradise on earth\" and a model of traditional Chinese landscape aesthetics. It embodies the philosophical concept of \"harmony between heaven and humanity\" by integrating natural beauty with cultural depth. Many poems, paintings, and operas feature West Lake, making it an important symbol of Chinese culture.\n\n### IV. Travel Recommendations\n- Best visiting seasons: Spring (March-May) for peach blossoms and willows, Autumn (September-November) for clear skies and cool weather.\n- Recommended ways: Walking, cycling (along the lakeside greenway), or boating on the lake.\n- Local cuisine: West Lake vinegar fish, Longjing shrimp, Dongpo pork, pian'erchuan noodles.\n\nIn summary, Hangzhou West Lake is not just a natural wonder but also a living cultural museum worth exploring in detail. If you ever visit Hangzhou, don't miss this earthly paradise that is \"equally charming in light or heavy makeup\"."}}],"object":"chat.completion"}},"error":null} {"id":"628312ba-172c-457d-ba7f-3e5462cc6899","custom_id":"req-002","response":{"status_code":200,"request_id":"628312ba-172c-457d-ba7f-3e5462cc6899","body":{"created":1768306035,"usage":{"completion_tokens":25,"prompt_tokens":18,"total_tokens":43},"model":"qwen-plus","id":"chatcmpl-628312ba-172c-457d-ba7f-3e5462cc6899","choices":[{"finish_reason":"stop","index":0,"message":{"role":"assistant","content":"The spring breeze brushes green willows,\nNight rain nourishes red flowers.\nBird songs fill the forest,\nMountains and rivers share the same beauty."}}],"object":"chat.completion"}},"error":null}失敗の詳細(
error_file_id): 失敗したリクエスト行およびエラー理由に関する情報を含みます。トラブルシューティングについては、「エラーコード」をご参照ください。
詳細な手順
バッチ API のワークフローは、ファイルのアップロード、タスクの作成、タスクステータスの照会、結果のダウンロードの 4 ステップで構成されます。
1. ファイルのアップロード
2. バッチタスクの作成
3. バッチタスクの照会と管理
4. バッチ結果ファイルのダウンロード
高度な機能
完了通知の設定
長時間実行されるタスクには、リソースを節約するためにポーリングの代わりに非同期通知を使用します。
完了通知は北京リージョンでのみサポートされています。
コールバック: タスク作成時に公開アクセス可能な URL を指定します。
EventBridge メッセージキュー: Alibaba Cloud エコシステムと深く統合されており、パブリック IP は不要です。
方法 1: コールバック
方法 2: EventBridge メッセージキュー
本番稼働
ファイル管理
OpenAI ファイル削除 API を使用して不要なファイルを定期的に削除し、ストレージ制限(10,000 ファイルまたは 100 GB)に達しないようにします。
大きなファイルは代わりに OSS に保存します。
タスクモニタリング
コールバックまたは EventBridge の非同期通知を使用します。
ポーリングが必要な場合は、間隔を 1 分以上に設定し、指数バックオフ戦略を使用します。
エラー処理
ネットワークエラー、API エラー、その他の例外を処理します。
error_file_idのエラー詳細をダウンロードして分析します。一般的なエラーコードについては、「エラーメッセージ」をご参照ください。
コスト最適化
小さなタスクを 1 つのバッチにまとめます。
completion_windowを適切に設定して、スケジューリングの柔軟性を高めます。
ユーティリティツール
CSV から JSONL へ
JSONL 結果を CSV に
レート制限
インターフェース | レート制限(Alibaba Cloud アカウントあたり) |
タスクの作成 | 1,000 呼び出し/分、最大 1,000 同時タスク |
タスクの照会 | 1,000 呼び出し/分 |
タスクリストの照会 | 100 呼び出し/分 |
タスクのキャンセル | 1,000 呼び出し/分 |
課金
単価: すべての成功したリクエストの入力および出力トークンは、対応するモデルのリアルタイム推論価格の50 %で課金されます。詳細については、「モデルリスト」をご参照ください。
課金範囲:
タスク内で正常に実行されたリクエストのみが課金されます。
ファイル解析エラー、タスク実行失敗、または行レベルのエラーによる失敗リクエストは課金されません。
キャンセルされたタスクについては、キャンセル前に正常に完了したリクエストは通常通り課金されます。
バッチ推論は別の課金項目です。AI 汎用節約プランをサポートしますが、サブスクリプション(その他の節約プラン)や新規ユーザー向けの無料クォータなどの割引はサポートしません。また、コンテキストキャッシュなどの機能もサポートしません。
qwen3.5-plus や qwen3.5-flash などの一部のモデルでは、思考モードがデフォルトで有効になっています。このモードは追加の思考トークンを生成し、出力トークン価格で課金され、コストが増加します。コストを管理するには、タスクの複雑さに応じて `enable_thinking` パラメーターを設定してください。詳細については、「ディープシンキング」をご参照ください。
エラーコード
呼び出しが失敗し、エラーメッセージが返された場合は、「エラーメッセージ」で解決策をご参照ください。
よくある質問
バッチチャットとバッチファイルのどちらを選ぶべきですか?
多数のリクエストを含む単一の大きなファイルを非同期で処理する必要がある場合は、バッチファイルを使用します。ビジネスロジックで多数の独立した会話リクエストを高い同時実行性で同期的に送信する必要がある場合は、バッチチャットを使用します。
バッチファイル API はどのように課金されますか?別途パッケージを購入する必要がありますか?
バッチは、成功したリクエストのトークンに基づいて従量課金されます。別途パッケージは不要です。
送信されたバッチファイルは順番に実行されますか?
いいえ。システムは計算負荷に基づいて動的スケジューリングを使用し、順序を保証しません。リソースが制約されている場合、タスクが遅延することがあります。
送信されたバッチファイルが完了するまでどのくらいかかりますか?
実行時間は、システムリソースとタスクの規模によって異なります。タスクが completion_window 内に完了しない場合、期限切れになります。期限切れのタスク内の未処理のリクエストは実行されず、課金も発生しません。
シナリオの推奨事項: 厳密なリアルタイムのモデル推論が必要なシナリオではリアルタイム呼び出しを使用します。ある程度の遅延が許容される大規模なデータ処理シナリオではバッチ呼び出しを使用します。