> For the documentation index, fetch https://sync.so/docs/llms.txt. Append .md to a page URL for Markdown. Documentation-search MCP: https://sync.so/docs/_mcp/server. # Create Batch POST https://api.sync.so/v2/batch Content-Type: multipart/form-data Create a batch processing job from a JSONL file. Requires the Scale plan. Send the file in multipart field `input` (or the accepted `file` alias); it must be 5 MB or smaller and contain 20-500 records by default. Each line must contain `request_id`, endpoint exactly `/v2/generate`, and a generation `payload`. Reference: https://sync.so/docs/api-reference/api/batch-api/create ## Authentication - `x-api-key` header (required) — API Key authentication via header ## Servers - `https://api.sync.so` (Default, default) - `https://dev-api.sync.so` (dev) - `http://localhost:3001` (local) ## Request ### Body (multipart/form-data) This endpoint expects a multipart form containing a file. - `input` (file, required) — JSONL file containing batch requests. Send it in multipart field `input` (or `file` alias). Each non-empty line must contain `request_id`, endpoint exactly `/v2/generate`, and `payload` as a CreateGenerationDto object. Minimum 20 records required, maximum 500 records by default, no duplicate request_id values, and maximum file size 5 MB. - `webhook_url` (string, optional) — Optional webhook URL to receive batch completion notifications. A POST request will be sent when the batch completes or fails, with a Sync-Signature header (`t=,v1=`) signed with the organization webhook secret. - `dry_run` (boolean, optional) — When true, validates the JSONL file and returns `{ "status": "VALIDATED" }` without creating a batch. ## Response ### 200 - `CreateBatchResponse` ## Errors ### 400 Bad Request Error Bad Request - Invalid input or unsupported model - `message` (GenerationErrorMessage, required) — A message describing the error. - `statusCode` (double, required) — The type of error that occurred. - `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors. - `suggestion` (string, optional) — A suggested fix an agent can act on. - `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId). - `docsUrl` (string, optional) — Link to the documentation page for the failing operation. - `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly. - `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN. ### 401 Unauthorized Error Unauthorized - Invalid or missing authentication - `message` (GenerationErrorMessage, required) — A message describing the error. - `statusCode` (double, required) — The type of error that occurred. - `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors. - `suggestion` (string, optional) — A suggested fix an agent can act on. - `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId). - `docsUrl` (string, optional) — Link to the documentation page for the failing operation. - `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly. - `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN. ### 402 Payment Required Error Payment Required - Feature requires higher plan - `message` (GenerationErrorMessage, required) — A message describing the error. - `statusCode` (double, required) — The type of error that occurred. - `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors. - `suggestion` (string, optional) — A suggested fix an agent can act on. - `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId). - `docsUrl` (string, optional) — Link to the documentation page for the failing operation. - `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly. - `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN. ### 429 Too Many Requests Error Too Many Requests - Batch concurrency limit reached - `statusCode` (double, required) — The HTTP status code (429). - `message` (GenerationErrorMessage, required) — A human-readable description of the error. - `errorCode` (string, optional) — Machine-readable error code (`concurrency_limit_reached`). - `activeBatches` (double, optional) — The number of batches you currently have in progress. - `concurrencyLimit` (double, optional) — The maximum number of concurrent batches allowed on your plan. - `retryAfterSeconds` (double, optional) — Suggested number of seconds to wait before retrying. Mirrors the `Retry-After` header. ### 500 Internal Server Error Internal Server Error - An unexpected failure on our side. The body carries errorCode internal_error and a requestId; include the requestId when contacting support. - `message` (GenerationErrorMessage, required) — A message describing the error. - `statusCode` (double, required) — The type of error that occurred. - `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors. - `suggestion` (string, optional) — A suggested fix an agent can act on. - `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId). - `docsUrl` (string, optional) — Link to the documentation page for the failing operation. - `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly. - `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN. ## Types ### BatchResponse - `id` (string, required) — A unique identifier for the batch. - `created_at` (datetime, required) — The date and time the batch was created. - `status` (enum, required) — The current status of the batch. - Allowed values: `PENDING`, `JOBS_CREATED`, `PROCESSING`, `COMPLETED`, `FAILED` - `metrics` (BatchMetrics, required) — Metrics about the batch processing progress. - `outputUrl` (string, required) — The URL to download the batch results file when completed. A GET request follows a 302 redirect to a signed JSONL result URL. - `webhookUrl` (string, optional) — The webhook URL for batch status notifications. Deliveries include a Sync-Signature header signed with the organization webhook secret. ### ValidationResponse - `status` ("VALIDATED", required) — Validation status for dry run requests. ### GenerationErrorMessage A message describing the error. ### BatchMetrics - `total_generations` (integer, required) — Total number of generation requests in the batch. - `success_count` (integer, required) — Number of successfully completed generations. - `failed_count` (integer, required) — Number of failed generations. - `pending_count` (integer, required) — Number of generations still pending or processing. ## Examples ### CreateBatch **Request** ```json { "input": ">", "webhook_url": "https://your-webhook-url.com/batch-webhook", "dry_run": false } ``` **Response** ```json { "id": "batch_abc123", "created_at": "2024-01-15T10:30:00Z", "status": "PENDING", "metrics": { "total_generations": 5, "success_count": 0, "failed_count": 0, "pending_count": 0 }, "webhookUrl": "https://your-webhook-url.com/batch-webhook", "outputUrl": "" } ``` **SDK Code** ```python CreateBatch import requests url = "https://api.sync.so/v2/batch" files = { "input": "open('', 'rb')" } payload = { "webhook_url": "https://your-webhook-url.com/batch-webhook", "dry_run": "false" } headers = {"x-api-key": ""} response = requests.post(url, data=payload, files=files, headers=headers) print(response.json()) ``` ```javascript CreateBatch const url = 'https://api.sync.so/v2/batch'; const form = new FormData(); form.append('input', ''); form.append('webhook_url', 'https://your-webhook-url.com/batch-webhook'); form.append('dry_run', 'false'); const options = {method: 'POST', headers: {'x-api-key': ''}}; options.body = form; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go CreateBatch package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.sync.so/v2/batch" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://your-webhook-url.com/batch-webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\nfalse\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby CreateBatch require 'uri' require 'net/http' url = URI("https://api.sync.so/v2/batch") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["x-api-key"] = '' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://your-webhook-url.com/batch-webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\nfalse\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body ``` ```java CreateBatch import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.sync.so/v2/batch") .header("x-api-key", "") .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://your-webhook-url.com/batch-webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\nfalse\r\n-----011000010111000001101001--\r\n") .asString(); ``` ```php CreateBatch request('POST', 'https://api.sync.so/v2/batch', [ 'multipart' => [ [ 'name' => 'input', 'filename' => '', 'contents' => null ], [ 'name' => 'webhook_url', 'contents' => 'https://your-webhook-url.com/batch-webhook' ], [ 'name' => 'dry_run', 'contents' => 'false' ] ] 'headers' => [ 'x-api-key' => '', ], ]); echo $response->getBody(); ``` ```csharp CreateBatch using RestSharp; var client = new RestClient("https://api.sync.so/v2/batch"); var request = new RestRequest(Method.POST); request.AddHeader("x-api-key", ""); request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttps://your-webhook-url.com/batch-webhook\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\nfalse\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift CreateBatch import Foundation let headers = ["x-api-key": ""] let parameters = [ [ "name": "input", "fileName": "" ], [ "name": "webhook_url", "value": "https://your-webhook-url.com/batch-webhook" ], [ "name": "dry_run", "value": "false" ] ] let boundary = "---011000010111000001101001" var body = "" var error: NSError? = nil for param in parameters { let paramName = param["name"]! body += "--\(boundary)\r\n" body += "Content-Disposition:form-data; name=\"\(paramName)\"" if let filename = param["fileName"] { let contentType = param["content-type"]! let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8) if (error != nil) { print(error as Any) } body += "; filename=\"\(filename)\"\r\n" body += "Content-Type: \(contentType)\r\n\r\n" body += fileContent } else if let paramValue = param["value"] { body += "\r\n\r\n\(paramValue)" } } let request = NSMutableURLRequest(url: NSURL(string: "https://api.sync.so/v2/batch")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ### DryRunValidation **Request** ```json { "input": ">", "dry_run": true } ``` **Response** ```json { "status": "VALIDATED" } ``` **SDK Code** ```python DryRunValidation import requests url = "https://api.sync.so/v2/batch" files = { "input": "open('', 'rb')" } payload = { "webhook_url": , "dry_run": "true" } headers = {"x-api-key": ""} response = requests.post(url, data=payload, files=files, headers=headers) print(response.json()) ``` ```javascript DryRunValidation const url = 'https://api.sync.so/v2/batch'; const form = new FormData(); form.append('input', ''); form.append('webhook_url', ''); form.append('dry_run', 'true'); const options = {method: 'POST', headers: {'x-api-key': ''}}; options.body = form; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go DryRunValidation package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.sync.so/v2/batch" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\ntrue\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby DryRunValidation require 'uri' require 'net/http' url = URI("https://api.sync.so/v2/batch") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["x-api-key"] = '' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\ntrue\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body ``` ```java DryRunValidation import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.sync.so/v2/batch") .header("x-api-key", "") .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\ntrue\r\n-----011000010111000001101001--\r\n") .asString(); ``` ```php DryRunValidation request('POST', 'https://api.sync.so/v2/batch', [ 'multipart' => [ [ 'name' => 'input', 'filename' => '', 'contents' => null ], [ 'name' => 'dry_run', 'contents' => 'true' ] ] 'headers' => [ 'x-api-key' => '', ], ]); echo $response->getBody(); ``` ```csharp DryRunValidation using RestSharp; var client = new RestClient("https://api.sync.so/v2/batch"); var request = new RestRequest(Method.POST); request.AddHeader("x-api-key", ""); request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"input\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dry_run\"\r\n\r\ntrue\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift DryRunValidation import Foundation let headers = ["x-api-key": ""] let parameters = [ [ "name": "input", "fileName": "" ], [ "name": "webhook_url", "value": ], [ "name": "dry_run", "value": "true" ] ] let boundary = "---011000010111000001101001" var body = "" var error: NSError? = nil for param in parameters { let paramName = param["name"]! body += "--\(boundary)\r\n" body += "Content-Disposition:form-data; name=\"\(paramName)\"" if let filename = param["fileName"] { let contentType = param["content-type"]! let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8) if (error != nil) { print(error as Any) } body += "; filename=\"\(filename)\"\r\n" body += "Content-Type: \(contentType)\r\n\r\n" body += fileContent } else if let paramValue = param["value"] { body += "\r\n\r\n\(paramValue)" } } let request = NSMutableURLRequest(url: NSURL(string: "https://api.sync.so/v2/batch")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```