TypeScript SDK: Batches
Asynchronous processing at the batch price.
import Syntic from '@syntic/sdk'
const client = new Syntic() // reads SYNTIC_API_KEY| Method | Endpoint | Returns |
|---|---|---|
batches.create | POST /v1/batches | Batch |
batches.list | GET /v1/batches | SyncPage[Batch] |
batches.retrieve | GET /v1/batches/{batch_id} | Batch |
batches.wait | (helper; polls GET /v1/batches/{batch_id}) | Batch |
batches.results | GET /v1/batches/{batch_id}/results | Iterator of BatchResult |
batches.cancel | POST /v1/batches/{batch_id}/cancel | Batch |
batches.delete | DELETE /v1/batches/{batch_id} | BatchDeleted |
Methods
batches.create
From an uploaded JSONL input_file_id, or up to 1,000 inline requests. Maps to POST /v1/batches.
const result = await client.batches.create({
input_file_id: "file_01JBXF1Z"
})batches.list
List batches. Maps to GET /v1/batches.
for await (const item of client.batches.list({
limit: 20
})) {
console.log(item)
}batches.retrieve
Status and counts. Maps to GET /v1/batches/{batch_id}.
const result = await client.batches.retrieve("batch_01JBXF3P8K")batches.wait
Helper: poll until the batch ends, with back-off. Returns the final batch.
const result = await client.batches.wait("batch_01JBXF3P8K", {
poll_interval: 30
})batches.results
Iterate result lines as typed objects, streaming from the server. Maps to GET /v1/batches/{batch_id}/results.
for await (const item of client.batches.results("batch_01JBXF3P8K")) {
console.log(item)
}batches.cancel
Cancel a running batch. Maps to POST /v1/batches/{batch_id}/cancel.
const result = await client.batches.cancel("batch_01JBXF3P8K")batches.delete
Delete an ended batch and its result files. Maps to DELETE /v1/batches/{batch_id}.
const result = await client.batches.delete("batch_01JBXF3P8K")Conventions
Every method accepts a final options object with headers, query, timeout, maxRetries and signal (an AbortSignal). List methods return pages that work with for await across all pages.
See the TypeScript SDK overview for installation, errors and retries.