> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# バッチを作成

> 非同期バッチジョブを作成し、上流のバッチオブジェクトを返します。指定した`model`を通じてOpenAI、Anthropic、Google Gemini、Mistral、xAI、Groq、Together AIに対応します。ゲートウェイはモデルから上流プロバイダーを推定し、可観測性と非同期通知用に`session_id`と`webhook`も受け付けます。`provider`は高度なルーティング制約としてのみ使用してください。

ワークスペースのプレビュー機能へのアクセスが必要です。設定、Webhook、結果の処理については、[動画とバッチのジョブ](../../guides/async-video-and-batch.mdx)を参照してください。


## OpenAPI

````yaml ja/openapi/v1/openapi.localized.yaml POST /batches
openapi: 3.0.3
info:
  title: Phaseo Gateway API
  description: OpenAI互換のエンドポイントを通じて、さまざまなAIモデルにアクセスするためのゲートウェイAPI。
  version: 1.0.0
  contact:
    name: Phaseo
    url: https://phaseo.app
    email: danielbutler500@gmail.com
servers:
  - url: https://api.phaseo.app/v1
    description: グローバルルーティング
security:
  - BearerAuth: []
tags:
  - name: Gateway
    description: Core Phaseo Gateway operations.
paths:
  /batches:
    post:
      tags:
        - Gateway
      summary: バッチを作成
      description: >-
        非同期バッチジョブを作成し、上流のバッチオブジェクトを返します。指定した`model`を通じてOpenAI、Anthropic、Google
        Gemini、Mistral、xAI、Groq、Together
        AIに対応します。ゲートウェイはモデルから上流プロバイダーを推定し、可観測性と非同期通知用に`session_id`と`webhook`も受け付けます。`provider`は高度なルーティング制約としてのみ使用してください。
      operationId: createBatch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BatchRequest'
      responses:
        '200':
          description: バッチ状態のレスポンス
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchResponse'
        '401':
          description: 認証されていません
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    BatchRequest:
      type: object
      properties:
        provider_options:
          type: object
          description: >-
            正規プロバイダーIDごとの拡張。OpenAIはoutput_expires_after、Mistralはmetadataを受け付けます。選択したプロバイダーのオプションのみ適用されます。最上位で同じオプションを重複指定しないでください。オプションで価格計算済みの行、モデル、ファイルを上書きすることはできません。
          additionalProperties:
            type: object
            additionalProperties: true
        model:
          type: string
          description: 上流バッチプロバイダーを推定するモデルID。リクエスト行にもbody.modelを指定できますが、最上位のモデルが優先されます。
        prompts:
          type: array
          description: 単純なプロンプトの省略形式。Phaseoは各プロンプトを選択モデル用のプロバイダー固有バッチ行に変換します。
          items:
            type: string
        items:
          type: array
          description: >-
            構造化プロンプトの省略形式。項目に`id`、`custom_id`、`prompt`、`messages`、`input`、`system`、`max_tokens`、`temperature`、または高度な`body`を含められます。
          items:
            type: object
            additionalProperties: true
        system:
          type: string
          description: プロンプト省略形式の行に適用する任意のシステム指示。
        max_tokens:
          type: integer
          description: プロンプト省略形式の行に適用する任意の最大トークン数。
        temperature:
          type: number
          description: プロンプト省略形式の行に適用する任意のサンプリング温度。
        input_file_id:
          type: string
          description: ファイルアップロードによるバッチ作成に使用する既存のプロバイダーファイルID。
        requests:
          type: array
          description: >-
            高度なバッチリクエスト行。`prompts`、`items`、`requests`、`input_file_id`のいずれか1つだけを指定してください。
          items:
            $ref: '#/components/schemas/BatchRequestItem'
        endpoint:
          type: string
          enum:
            - /v1/chat/completions
            - /v1/responses
            - /v1/messages
            - /v1/embeddings
            - /v1/generateContent
          description: >-
            呼び出し元向けのリクエスト形式。バッチ内の全リクエストはこのエンドポイントを使用します。省略時はPhaseoがモデルからプロバイダー固有の既定値を選択します。
        completion_window:
          type: string
        metadata:
          type: object
          additionalProperties: true
        session_id:
          type: string
          maxLength: 256
          description: 関連するリクエスト（会話やエージェントのワークフローなど）を可観測性のためにまとめる一意の識別子です。
        webhook:
          type: object
          required:
            - endpoint_id
          additionalProperties: false
          properties:
            endpoint_id:
              type: string
              description: ワークスペース管理のWebhookエンドポイントID。
            events:
              type: array
              description: >-
                任意のイベント購読。汎用job.*イベント、または対応するbatch.*イベント（例：batch.progress、batch.completed）を使用します。省略時は終端のjob.*イベントが使用されます。リクエスト数の進捗コールバックにはjob.progressまたはbatch.progressを明示してください。指定する場合、少なくとも1つはバッチジョブに有効なイベントである必要があります。他種のイベントのみのリストや不正なリストは拒否されます。
              items:
                type: string
        webhook_endpoint_id:
          type: string
          description: webhook.endpoint_idの便利なエイリアス。
        debug:
          $ref: '#/components/schemas/DebugOptions'
        provider:
          allOf:
            - $ref: '#/components/schemas/ProviderRoutingOptions'
          description: 高度なルーティング制約。ほとんどのリクエストではモデルに基づくプロバイダー推定を使用してください。
    BatchResponse:
      type: object
      properties:
        id:
          type: string
        native_batch_id:
          type: string
          nullable: true
          description: ゲートウェイが所有するIDと異なる場合の、プロバイダー固有のバッチID。
        object:
          type: string
        endpoint:
          type: string
        errors:
          type: object
        input_file_id:
          type: string
        completion_window:
          type: string
        status:
          type: string
        lifecycle_status:
          type: string
          enum:
            - pending
            - running
            - completed
            - failed
            - cancelled
            - expired
          description: ポーリング、WebSocket、Webhookの利用側向けに正規化された非同期ライフサイクル状態。
        progress:
          type: integer
          minimum: 0
          maximum: 100
          description: プロバイダーのリクエスト数から算出するバッチのおおよその完了率（取得できる場合）。完了したバッチは100を報告します。
        polling_url:
          type: string
          format: uri
        websocket_url:
          type: string
          format: uri
          description: 非同期ジョブの正規化されたライフサイクル更新を購読するWebSocket URL。
        cancel_url:
          type: string
          format: uri
          nullable: true
          description: 互換性のために予約されています。現在は常にnullです。
        results_url:
          type: string
          format: uri
          nullable: true
          description: >-
            対応する終端状態バッチ用の認証付きPhaseo
            JSONLダウンロードURL。処理中はnullです。終端状態のバッチに出力がない場合もあります。所有ワークスペースのAPIキーを使用してください。プロバイダーの保持期限が適用されます。
        output_file_id:
          type: string
        error_file_id:
          type: string
        created_at:
          type: integer
        in_progress_at:
          type: integer
        expires_at:
          type: integer
        finalizing_at:
          type: integer
        completed_at:
          type: integer
        failed_at:
          type: integer
        expired_at:
          type: integer
        cancelling_at:
          type: integer
        cancelled_at:
          type: integer
        request_counts:
          $ref: '#/components/schemas/BatchRequestCounts'
        metadata:
          type: object
        request_id:
          type: string
        provider:
          type: string
        session_id:
          type: string
        webhook:
          $ref: '#/components/schemas/AsyncWebhookPublicState'
        next_webhook_retry_at:
          type: string
          nullable: true
        last_webhook_progress:
          type: number
          nullable: true
        last_webhook_progress_at:
          type: string
          nullable: true
        last_webhook_dispatched_at:
          type: string
          nullable: true
        finalized_at:
          type: string
          nullable: true
        pricing_lines:
          type: array
          items:
            type: object
            additionalProperties: true
        usage:
          type: object
          description: 確定後の正規化された集計使用量とコスト。
          properties:
            requests:
              type: integer
              nullable: true
            input_tokens:
              type: integer
              nullable: true
            output_tokens:
              type: integer
              nullable: true
            total_tokens:
              type: integer
              nullable: true
            cost_nanos:
              type: integer
              nullable: true
            cost_usd:
              type: number
              nullable: true
            currency:
              type: string
        billing:
          $ref: '#/components/schemas/BatchBillingSummary'
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        ok:
          type: boolean
          example: false
        error:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
          example: error_type
        message:
          type: string
          example: Human-readable error message
        description:
          type: string
          example: Additional error details.
        generation_id:
          type: string
          example: G-abc123
        status_code:
          type: integer
          example: 502
        error_type:
          type: string
          enum:
            - user
            - system
          example: system
        error_origin:
          type: string
          enum:
            - user
            - gateway
            - upstream
          example: upstream
        reason:
          type: string
          example: all_candidates_failed
        attempt_count:
          type: integer
          example: 2
        failed_providers:
          type: array
          items:
            type: string
          example:
            - google-ai-studio
            - openai
        failed_statuses:
          type: array
          items:
            type: integer
          example:
            - 403
            - 429
        upstream_error:
          $ref: '#/components/schemas/ErrorUpstreamError'
        failure_sample:
          type: array
          items:
            $ref: '#/components/schemas/ErrorFailureSampleItem'
        provider_failure_diagnostics:
          $ref: '#/components/schemas/ErrorProviderFailureDiagnostics'
        routing_diagnostics:
          $ref: '#/components/schemas/ErrorRoutingDiagnostics'
        provider_candidate_diagnostics:
          $ref: '#/components/schemas/ErrorProviderCandidateDiagnostics'
        provider_enablement:
          $ref: '#/components/schemas/ErrorProviderEnablementDiagnostics'
        missing_pricing_providers:
          type: array
          items:
            type: string
        provider_payment_required_provider:
          type: string
          example: openai
        provider_payment_required_support_notice:
          type: string
          example: >-
            Our upstream provider billing appears to be unavailable. If this
            persists, contact support.
        details:
          type: array
          items:
            type: object
            additionalProperties: true
      additionalProperties: true
    BatchRequestItem:
      type: object
      required:
        - body
      properties:
        custom_id:
          type: string
        method:
          type: string
          default: POST
          enum:
            - POST
        url:
          type: string
          description: この行のエンドポイントパス。指定時は親バッチのエンドポイントと一致する必要があります。既定は親バッチのエンドポイントです。
        body:
          type: object
          additionalProperties: true
    DebugOptions:
      type: object
      description: ゲートウェイのデバッグ設定です。これらのフラグがプロバイダーに転送されることはありません。
      properties:
        enabled:
          type: boolean
        return_upstream_request:
          type: boolean
        return_upstream_response:
          type: boolean
        trace:
          type: boolean
        trace_level:
          type: string
          enum:
            - summary
            - full
    ProviderRoutingOptions:
      type: object
      description: ゲートウェイでの選択に使用するプロバイダーのルーティング設定。
      properties:
        order:
          type: array
          items:
            type: string
        only:
          type: array
          items:
            type: string
        ignore:
          type: array
          items:
            type: string
        include_alpha:
          type: boolean
          description: ルーティングに alpha プロバイダーを含める（既定ではオフ）。
        allow_fallbacks:
          type: boolean
          nullable: true
          description: 失敗後に別の対象プロバイダーへフォールバックすることを許可します。
        require_parameters:
          type: boolean
          nullable: true
          description: ルーティング前に、要求されたパラメーターにプロバイダーが対応していることを必須にします。
        required_execution_region:
          type: string
          nullable: true
          description: 指定された実行リージョンに対応するプロバイダーにルーティングを限定します。
        required_data_region:
          type: string
          nullable: true
          description: 指定されたデータリージョンに対応するプロバイダーにルーティングを限定します。
        require_zero_data_retention:
          type: boolean
          nullable: true
          description: ゼロデータ保持に対応するプロバイダーにルーティングを限定します。
        data_collection:
          type: string
          nullable: true
          enum:
            - allow
            - deny
        zdr:
          type: boolean
          nullable: true
        enforce_distillable_text:
          type: boolean
          nullable: true
        quantizations:
          type: array
          nullable: true
          items:
            type: string
        sort:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
          description: このリクエストのプロバイダーを、価格、レイテンシ、スループットなどで並べ替えます。
        max_price:
          type: object
          properties:
            prompt:
              oneOf:
                - type: number
                - type: string
            completion:
              oneOf:
                - type: number
                - type: string
            image:
              oneOf:
                - type: number
                - type: string
            audio:
              oneOf:
                - type: number
                - type: string
            request:
              oneOf:
                - type: number
                - type: string
        preferred_min_throughput:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
        preferred_max_latency:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
    BatchRequestCounts:
      type: object
      properties:
        total:
          type: integer
        completed:
          type: integer
        failed:
          type: integer
    AsyncWebhookPublicState:
      type: object
      description: >-
        機密情報を除去した非同期Webhook設定と配信状態。シークレットは返されません。`has_secret`は署名付き配信が有効かを示します。署名付き配信にはx-phaseo-signature、x-phaseo-timestamp、x-phaseo-event-id、x-phaseo-event-type、x-phaseo-delivery-key、x-phaseo-attempt、x-phaseo-max-attemptsヘッダーが含まれます。
      properties:
        url:
          type: string
          format: uri
          nullable: true
        events:
          type: array
          items:
            type: string
        has_secret:
          type: boolean
        delivery:
          $ref: '#/components/schemas/AsyncWebhookDeliverySummary'
        attempts:
          type: array
          items:
            $ref: '#/components/schemas/AsyncWebhookDeliveryAttempt'
    BatchBillingSummary:
      type: object
      properties:
        currency:
          type: string
        billed:
          type: boolean
        charged:
          type: boolean
        reason:
          type: string
        state:
          type: string
          enum:
            - pending
            - estimated
            - settled
            - void
        reservation_id:
          type: string
          nullable: true
        reservation_status:
          type: string
          nullable: true
        estimated_provider_cost:
          type: string
          nullable: true
        estimated_user_cost:
          type: string
          nullable: true
        settled_provider_cost:
          type: string
          nullable: true
        settled_user_cost:
          type: string
          nullable: true
        estimated_nanos:
          type: integer
          nullable: true
        reserved_nanos:
          type: integer
          nullable: true
        estimation_truncated:
          type: boolean
          nullable: true
          description: より大きなバッチ入力ファイルの限定サンプルから予約額の推定を拡大算出した場合はTrue。
        estimation_sample_size:
          type: integer
          nullable: true
          description: 予約額の推定で直接価格計算した入力行数。
        estimation_total_rows:
          type: integer
          nullable: true
          description: 予約額の推定が対象とする入力行の総数。
        total_nanos:
          type: integer
          nullable: true
        cost_nanos:
          type: integer
          nullable: true
        cost_usd:
          type: number
          nullable: true
        finalized_at:
          type: string
          nullable: true
        pricing_breakdown:
          type: object
          additionalProperties: true
    ErrorUpstreamError:
      type: object
      properties:
        code:
          type: string
          nullable: true
          example: PERMISSION_DENIED
        message:
          type: string
          nullable: true
          example: The caller does not have permission.
        description:
          type: string
          nullable: true
        param:
          type: string
          nullable: true
    ErrorFailureSampleItem:
      type: object
      properties:
        provider:
          type: string
          nullable: true
        type:
          type: string
          nullable: true
        status:
          type: integer
          nullable: true
        upstream_error_code:
          type: string
          nullable: true
        upstream_error_message:
          type: string
          nullable: true
        upstream_error_description:
          type: string
          nullable: true
        upstream_error_param:
          type: string
          nullable: true
        upstream_payload_preview:
          type: string
          nullable: true
        retryable:
          type: boolean
          nullable: true
      additionalProperties: true
    ErrorProviderFailureDiagnostics:
      type: object
      properties:
        category:
          type: string
          enum:
            - credentials_not_configured
            - credentials_invalid_or_forbidden
            - provider_access_missing
            - region_or_project_restriction
            - model_unavailable_for_endpoint
            - rate_limited
            - server_error
        hint:
          type: string
        provider:
          type: string
          nullable: true
    ErrorRoutingDiagnostics:
      type: object
      properties:
        filterStages:
          type: array
          items:
            type: object
            properties:
              stage:
                type: string
              beforeCount:
                type: integer
              afterCount:
                type: integer
              droppedProviders:
                type: array
                items:
                  type: object
                  properties:
                    providerId:
                      type: string
                      nullable: true
                    reason:
                      type: string
                      nullable: true
                  additionalProperties: true
            additionalProperties: true
      additionalProperties: true
    ErrorProviderCandidateDiagnostics:
      type: object
      properties:
        totalProviders:
          type: integer
        supportsEndpointCount:
          type: integer
        candidateCount:
          type: integer
        droppedUnsupportedEndpoint:
          type: array
          items:
            type: string
        droppedMissingAdapter:
          type: array
          items:
            type: object
            properties:
              providerId:
                type: string
                nullable: true
              endpoint:
                type: string
                nullable: true
            additionalProperties: true
      additionalProperties: true
    ErrorProviderEnablementDiagnostics:
      type: object
      properties:
        capability:
          type: string
        providersBefore:
          type: array
          items:
            type: string
        providersAfter:
          type: array
          items:
            type: string
        dropped:
          type: array
          items:
            type: object
            properties:
              providerId:
                type: string
                nullable: true
              reason:
                type: string
                nullable: true
            additionalProperties: true
      additionalProperties: true
    AsyncWebhookDeliverySummary:
      type: object
      description: ゲートウェイ管理の非同期Webhookの公開配信サマリー。ジョブの実行状態とWebhook配信の正常性を区別するために使用します。
      properties:
        total_attempts:
          type: integer
          description: このジョブで記録された配信試行の総数。
        delivered_events:
          type: integer
          description: 配信済み状態に達した配信キーの数。
        delivered_event_types:
          type: array
          description: 少なくとも1回配信された配信キー。
          items:
            type: string
          example:
            - video.completed
        pending_retries:
          type: integer
          description: 現在再試行が予定されている配信キーの数。
        next_retry_at:
          type: string
          nullable: true
          description: 次の予定された再試行のISOタイムスタンプ（存在する場合）。
        last_attempt_at:
          type: string
          nullable: true
          description: 直近の配信試行のISOタイムスタンプ。
        last_attempt_status:
          type: string
          nullable: true
          enum:
            - delivered
            - scheduled_retry
            - failed_permanently
          description: 直近の配信試行の結果。
        last_response_status:
          type: integer
          nullable: true
          description: Webhookの送信先が返したHTTPステータス（取得できる場合）。
        last_delivered_at:
          type: string
          nullable: true
          description: 直近の成功した配信のISOタイムスタンプ。
        last_failure_at:
          type: string
          nullable: true
          description: 直近の失敗した、または再試行中の試行のISOタイムスタンプ。
        last_error_message:
          type: string
          nullable: true
          description: 直近の配信エラーメッセージ（取得できる場合）。
    AsyncWebhookDeliveryAttempt:
      type: object
      description: ゲートウェイ管理の非同期Webhookの最近の配信試行。
      properties:
        id:
          type: string
          description: 監査とデバッグ用の安定した試行識別子。
        delivery_key:
          type: string
          description: このイベント配信用の冪等性キー。
          example: video.completed
        event_type:
          type: string
          description: Webhookの送信先に配信されたイベントの種類。
          example: video.completed
        status:
          type: string
          enum:
            - delivered
            - scheduled_retry
            - failed_permanently
        attempt_number:
          type: integer
          description: この配信キーの1から始まる試行番号。
        max_attempts:
          type: integer
          description: 配信を恒久的な失敗としてマークするまでの最大試行回数。
        tried_at:
          type: string
          description: この試行を行ったISOタイムスタンプ。
        delivered_at:
          type: string
          nullable: true
          description: この試行が正常に配信されたISOタイムスタンプ。
        next_retry_at:
          type: string
          nullable: true
          description: この試行後の次回再試行のISOタイムスタンプ（予定されている場合）。
        response_status:
          type: integer
          nullable: true
          description: Webhookの送信先が返したHTTPステータス（取得できる場合）。
        error_message:
          type: string
          nullable: true
          description: 配信エラーメッセージ（取得できる場合）。
        response_body_preview:
          type: string
          nullable: true
          description: Webhookの送信先からのレスポンス本文の、機密情報を伏せたプレビュー。
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Bearer トークンによる認証

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.