Skip to main content

Run Swarm

POST 

/v1/swarms

Start a swarm: one worker per slice of a batch, in parallel, within a budget.

The batch is input.files (fileIds, or every file of a folderId and/or a period you may see) or input.items (rows or pages given inline). sliceSize items go to one worker. Every worker is given the same task and only its own slice: a picture as the small preview made at upload, any other file as its extracted text. Its answer must match outputSchema; one that does not is asked for once more, then the slice is reported failed. The answers of the slices that succeeded become one list, in slice order or sorted by merge.sortBy.

preset: "describe_photos" over a month's folder describes each photo (file_id, description, tags, quality_score from 0 to 5, caption), best picture first.

Answers 202 at once with the swarm queued: read it with GET /v1/swarms/{id} until its status is done or done_with_failures. The same request again answers the same swarm (replayed: true) instead of starting another; pass your own idempotencyKey to name a run, or a new one to run a batch again.

Budget. Every model call is billed in credits, like an assistant model call. Before anything starts the swarm is estimated: over maxSpendUsd or over what the account has left it is refused, 402 swarm_over_budget with estimateUsd and availableUsd, and an account with no credits is refused 402 no_credits. While it runs, no call is made past maxSpendUsd: the slices left are reported skipped. At most 500 slices (422 too_many_slices).

outputSchema is JSON Schema, an object at the root, with type, properties, required, additionalProperties, items, enum, const, minimum, maximum, minLength, maxLength, minItems and maxItems; another keyword is refused (422 unsupported_schema) so that a matching answer has really been checked. A file you may not see refuses the swarm (404 file_not_found, with fileIds), and so does a folder none of whose files you may see (404 folder_not_found).

Request​

Responses​

Successful Response