# Create batch task

> Common

Create a batch task using the `input_file_id` returned from step 1.
The service routes the task to the provider matching the model detected
from the input file.

## Endpoint

`POST https://api.modelverse.cn/v1/batches`

## Request Body

## Responses

- **200** — Created; returns the batch object.
- **400** — Invalid parameters (e.g. `input_file_id` not found).
- **default** — Error response.

## OpenAPI Definition

```json
{
  "openapi": "3.1.0",
  "x-language": "en-US",
  "info": {
    "title": "Batch Tasks - Create Batch",
    "version": "1.0.0",
    "description": "Step 3 of the ModelVerse **OpenAI-compatible Batch async task** flow:\ncreate the batch task using an uploaded input file.\nEndpoint: `POST /v1/batches`.\n"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "ModelVerse API endpoint."
    }
  ],
  "tags": [
    {
      "name": "Batch Async Tasks",
      "description": "OpenAI-compatible batch async task APIs."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/batches": {
      "post": {
        "tags": [
          "Batch Async Tasks"
        ],
        "operationId": "createBatch",
        "summary": "Create batch task",
        "description": "Create a batch task using the `input_file_id` returned from step 1.\nThe service routes the task to the provider matching the model detected\nfrom the input file.\n",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateBatchRequest"
              },
              "examples": {
                "default": {
                  "summary": "Create a chat-completions batch task",
                  "value": {
                    "input_file_id": "file-abc123",
                    "endpoint": "/v1/chat/completions",
                    "completion_window": "24h",
                    "metadata": {
                      "job": "demo-batch"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Created; returns the batch object.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchObject"
                },
                "examples": {
                  "success": {
                    "summary": "Created (status validating)",
                    "value": {
                      "id": "batch_abc123",
                      "object": "batch",
                      "endpoint": "/v1/chat/completions",
                      "errors": null,
                      "input_file_id": "file-abc123",
                      "completion_window": "24h",
                      "status": "validating",
                      "created_at": 1781600010,
                      "request_counts": {
                        "total": 0,
                        "completed": 0,
                        "failed": 0
                      },
                      "metadata": {
                        "job": "demo-batch"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters (e.g. `input_file_id` not found).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "error": {
                    "$ref": "#/components/examples/BatchError"
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "error": {
                    "$ref": "#/components/examples/BatchError"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "Provide the API key via the `Authorization` header as\n`Bearer <your_api_key>`.\n"
      }
    },
    "schemas": {
      "CreateBatchRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "input_file_id",
          "endpoint",
          "completion_window"
        ],
        "properties": {
          "input_file_id": {
            "type": "string",
            "description": "The input file ID returned from step 1.",
            "examples": [
              "file-abc123"
            ]
          },
          "endpoint": {
            "type": "string",
            "description": "Target endpoint that processes the batch requests.",
            "examples": [
              "/v1/chat/completions"
            ]
          },
          "completion_window": {
            "type": "string",
            "description": "Task completion window. Fixed to `24h`.",
            "const": "24h"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Custom metadata; keys and values are strings."
          }
        }
      },
      "BatchObject": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "id",
          "object",
          "endpoint",
          "input_file_id",
          "completion_window",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Batch task ID, used to query task status."
          },
          "object": {
            "type": "string",
            "const": "batch",
            "description": "Object type. Always `batch`."
          },
          "endpoint": {
            "type": "string",
            "description": "Target endpoint that processes requests."
          },
          "errors": {
            "type": [
              "object",
              "null"
            ],
            "description": "Error object; `null` when there are no errors."
          },
          "input_file_id": {
            "type": "string",
            "description": "Input file ID."
          },
          "completion_window": {
            "type": "string",
            "description": "Task completion window."
          },
          "status": {
            "type": "string",
            "description": "Task status: `validating` (validating input file),\n`in_progress` (running), `finalizing` (preparing results),\n`completed`, `failed`, `expired`, `cancelling`, `cancelled`.\n",
            "enum": [
              "validating",
              "in_progress",
              "finalizing",
              "completed",
              "failed",
              "expired",
              "cancelling",
              "cancelled"
            ]
          },
          "output_file_id": {
            "type": "string",
            "description": "Result file ID (appears when completed) for downloading successful results."
          },
          "error_file_id": {
            "type": "string",
            "description": "Error detail file ID (appears when some requests fail)."
          },
          "created_at": {
            "type": "integer",
            "format": "int64",
            "description": "Creation timestamp (seconds)."
          },
          "request_counts": {
            "$ref": "#/components/schemas/BatchRequestCounts"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Custom metadata provided at creation."
          }
        }
      },
      "BatchRequestCounts": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of requests."
          },
          "completed": {
            "type": "integer",
            "description": "Number of completed requests."
          },
          "failed": {
            "type": "integer",
            "description": "Number of failed requests."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/Error"
          }
        }
      },
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "message",
          "type"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "Error message."
          },
          "type": {
            "type": "string",
            "description": "Error type.",
            "examples": [
              "invalid_request_error"
            ]
          },
          "code": {
            "type": "string",
            "description": "Machine-readable error code."
          },
          "param": {
            "type": "string",
            "description": "The offending parameter name or request ID."
          }
        }
      }
    },
    "examples": {
      "BatchError": {
        "summary": "Standard JSON error response",
        "value": {
          "error": {
            "message": "unknown input_file_id: file-abc123",
            "type": "invalid_request_error",
            "code": "error_code",
            "param": "input_file_id"
          }
        }
      }
    }
  }
}
```
