# Batches

## Create Batch

`client.batches.create(BatchCreateParamsparams, RequestOptionsoptions?): BatchCreateResponse`

**post** `/api/v2/batches`

Create a batch over a source directory and start processing asynchronously.

### Parameters

- `params: BatchCreateParams`

  - `config: Config`

    Body param: Batch configuration snapshot to apply to this source directory.

    - `job: Job`

      Job to create for each file in the source directory.

      - `configuration_id: string`

        Saved product configuration ID matching the job type.

      - `type: "parse_v2" | "extract_v2"`

        Product job type to run for each source directory file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `source_directory_id: string`

    Body param: Directory whose files should be processed.

  - `organization_id?: string | null`

    Query param

  - `project_id?: string | null`

    Query param

### Returns

- `BatchCreateResponse`

  A top-level batch.

  Example:
  {
  "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "project_id": "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "source_directory_id": "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "config": {
  "job": {
  "type": "parse_v2",
  "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  }
  },
  "status": "COMPLETED",
  "results": [
  {
  "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "job_reference": {
  "type": "parse_v2",
  "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  },
  "error_message": null
  }
  ]
  }

  Batch-level `FAILED` means the orchestration failed and cannot provide a
  reliable per-file result set. `results` is only populated when explicitly
  requested with `expand=results` and may be `null` while a batch is still
  running or before result mappings are available.

  - `id: string`

    Unique identifier

  - `config: Config`

    Batch configuration snapshot.

    - `job: Job`

      Job to create for each file in the source directory.

      - `configuration_id: string`

        Saved product configuration ID matching the job type.

      - `type: "parse_v2" | "extract_v2"`

        Product job type to run for each source directory file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `project_id: string`

    Project this batch belongs to.

  - `source_directory_id: string`

    Directory being processed.

  - `status: "PENDING" | "THROTTLED" | "RUNNING" | 3 more`

    Current batch status.

    - `"PENDING"`

    - `"THROTTLED"`

    - `"RUNNING"`

    - `"COMPLETED"`

    - `"FAILED"`

    - `"CANCELLED"`

  - `created_at?: string | null`

    Creation datetime

  - `results?: Array<Result> | null`

    Expanded per-file result mappings. Null unless requested with expand=results, or until result mappings are available.

    - `source_directory_file_id: string`

      Source directory file processed by this batch.

    - `error_message?: string | null`

      Batch-level mapping error if the system could not create or associate a job for this source file.

    - `job_reference?: JobReference | null`

      Reference to a job produced by a batch.

      Example:
      {
      "type": "parse_v2",
      "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      }

      - `id: string`

        Job ID, such as a parse job ID.

      - `type: "parse_v2" | "extract_v2"`

        Type of job produced for the file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `updated_at?: string | null`

    Update datetime

### Example

```typescript
import LlamaCloud from '@llamaindex/llama-cloud';

const client = new LlamaCloud({
  apiKey: process.env['LLAMA_CLOUD_API_KEY'], // This is the default and can be omitted
});

const batch = await client.batches.create({
  config: {
    job: { configuration_id: 'cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', type: 'parse_v2' },
  },
  source_directory_id: 'dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
});

console.log(batch.id);
```

#### Response

```json
{
  "id": "id",
  "config": {
    "job": {
      "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
      "type": "parse_v2"
    }
  },
  "project_id": "project_id",
  "source_directory_id": "source_directory_id",
  "status": "PENDING",
  "created_at": "2019-12-27T18:11:19.117Z",
  "results": [
    {
      "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
      "error_message": "error_message",
      "job_reference": {
        "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
        "type": "parse_v2"
      }
    }
  ],
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```

## List Batches

`client.batches.list(BatchListParamsquery?, RequestOptionsoptions?): PaginatedCursor<BatchListResponse>`

**get** `/api/v2/batches`

List batches for the current project.

### Parameters

- `query: BatchListParams`

  - `created_at_on_or_after?: string | null`

  - `created_at_on_or_before?: string | null`

  - `organization_id?: string | null`

  - `page_size?: number | null`

  - `page_token?: string | null`

  - `project_id?: string | null`

  - `source_directory_id?: string | null`

  - `status?: "PENDING" | "THROTTLED" | "RUNNING" | 3 more | null`

    - `"PENDING"`

    - `"THROTTLED"`

    - `"RUNNING"`

    - `"COMPLETED"`

    - `"FAILED"`

    - `"CANCELLED"`

### Returns

- `BatchListResponse`

  A top-level batch.

  Example:
  {
  "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "project_id": "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "source_directory_id": "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "config": {
  "job": {
  "type": "parse_v2",
  "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  }
  },
  "status": "COMPLETED",
  "results": [
  {
  "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "job_reference": {
  "type": "parse_v2",
  "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  },
  "error_message": null
  }
  ]
  }

  Batch-level `FAILED` means the orchestration failed and cannot provide a
  reliable per-file result set. `results` is only populated when explicitly
  requested with `expand=results` and may be `null` while a batch is still
  running or before result mappings are available.

  - `id: string`

    Unique identifier

  - `config: Config`

    Batch configuration snapshot.

    - `job: Job`

      Job to create for each file in the source directory.

      - `configuration_id: string`

        Saved product configuration ID matching the job type.

      - `type: "parse_v2" | "extract_v2"`

        Product job type to run for each source directory file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `project_id: string`

    Project this batch belongs to.

  - `source_directory_id: string`

    Directory being processed.

  - `status: "PENDING" | "THROTTLED" | "RUNNING" | 3 more`

    Current batch status.

    - `"PENDING"`

    - `"THROTTLED"`

    - `"RUNNING"`

    - `"COMPLETED"`

    - `"FAILED"`

    - `"CANCELLED"`

  - `created_at?: string | null`

    Creation datetime

  - `results?: Array<Result> | null`

    Expanded per-file result mappings. Null unless requested with expand=results, or until result mappings are available.

    - `source_directory_file_id: string`

      Source directory file processed by this batch.

    - `error_message?: string | null`

      Batch-level mapping error if the system could not create or associate a job for this source file.

    - `job_reference?: JobReference | null`

      Reference to a job produced by a batch.

      Example:
      {
      "type": "parse_v2",
      "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      }

      - `id: string`

        Job ID, such as a parse job ID.

      - `type: "parse_v2" | "extract_v2"`

        Type of job produced for the file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `updated_at?: string | null`

    Update datetime

### Example

```typescript
import LlamaCloud from '@llamaindex/llama-cloud';

const client = new LlamaCloud({
  apiKey: process.env['LLAMA_CLOUD_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const batchListResponse of client.batches.list()) {
  console.log(batchListResponse.id);
}
```

#### Response

```json
{
  "items": [
    {
      "id": "id",
      "config": {
        "job": {
          "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
          "type": "parse_v2"
        }
      },
      "project_id": "project_id",
      "source_directory_id": "source_directory_id",
      "status": "PENDING",
      "created_at": "2019-12-27T18:11:19.117Z",
      "results": [
        {
          "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
          "error_message": "error_message",
          "job_reference": {
            "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
            "type": "parse_v2"
          }
        }
      ],
      "updated_at": "2019-12-27T18:11:19.117Z"
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
```

## Get Batch

`client.batches.get(stringbatchID, BatchGetParamsquery?, RequestOptionsoptions?): BatchGetResponse`

**get** `/api/v2/batches/{batch_id}`

Get a batch by ID.

### Parameters

- `batchID: string`

- `query: BatchGetParams`

  - `expand?: Array<string> | null`

    Fields to expand. Supported value: results.

  - `organization_id?: string | null`

  - `project_id?: string | null`

### Returns

- `BatchGetResponse`

  A top-level batch.

  Example:
  {
  "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "project_id": "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "source_directory_id": "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "config": {
  "job": {
  "type": "parse_v2",
  "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  }
  },
  "status": "COMPLETED",
  "results": [
  {
  "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "job_reference": {
  "type": "parse_v2",
  "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  },
  "error_message": null
  }
  ]
  }

  Batch-level `FAILED` means the orchestration failed and cannot provide a
  reliable per-file result set. `results` is only populated when explicitly
  requested with `expand=results` and may be `null` while a batch is still
  running or before result mappings are available.

  - `id: string`

    Unique identifier

  - `config: Config`

    Batch configuration snapshot.

    - `job: Job`

      Job to create for each file in the source directory.

      - `configuration_id: string`

        Saved product configuration ID matching the job type.

      - `type: "parse_v2" | "extract_v2"`

        Product job type to run for each source directory file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `project_id: string`

    Project this batch belongs to.

  - `source_directory_id: string`

    Directory being processed.

  - `status: "PENDING" | "THROTTLED" | "RUNNING" | 3 more`

    Current batch status.

    - `"PENDING"`

    - `"THROTTLED"`

    - `"RUNNING"`

    - `"COMPLETED"`

    - `"FAILED"`

    - `"CANCELLED"`

  - `created_at?: string | null`

    Creation datetime

  - `results?: Array<Result> | null`

    Expanded per-file result mappings. Null unless requested with expand=results, or until result mappings are available.

    - `source_directory_file_id: string`

      Source directory file processed by this batch.

    - `error_message?: string | null`

      Batch-level mapping error if the system could not create or associate a job for this source file.

    - `job_reference?: JobReference | null`

      Reference to a job produced by a batch.

      Example:
      {
      "type": "parse_v2",
      "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      }

      - `id: string`

        Job ID, such as a parse job ID.

      - `type: "parse_v2" | "extract_v2"`

        Type of job produced for the file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `updated_at?: string | null`

    Update datetime

### Example

```typescript
import LlamaCloud from '@llamaindex/llama-cloud';

const client = new LlamaCloud({
  apiKey: process.env['LLAMA_CLOUD_API_KEY'], // This is the default and can be omitted
});

const batch = await client.batches.get('batch_id');

console.log(batch.id);
```

#### Response

```json
{
  "id": "id",
  "config": {
    "job": {
      "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
      "type": "parse_v2"
    }
  },
  "project_id": "project_id",
  "source_directory_id": "source_directory_id",
  "status": "PENDING",
  "created_at": "2019-12-27T18:11:19.117Z",
  "results": [
    {
      "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
      "error_message": "error_message",
      "job_reference": {
        "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
        "type": "parse_v2"
      }
    }
  ],
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```

## Domain Types

### Batch Create Response

- `BatchCreateResponse`

  A top-level batch.

  Example:
  {
  "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "project_id": "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "source_directory_id": "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "config": {
  "job": {
  "type": "parse_v2",
  "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  }
  },
  "status": "COMPLETED",
  "results": [
  {
  "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "job_reference": {
  "type": "parse_v2",
  "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  },
  "error_message": null
  }
  ]
  }

  Batch-level `FAILED` means the orchestration failed and cannot provide a
  reliable per-file result set. `results` is only populated when explicitly
  requested with `expand=results` and may be `null` while a batch is still
  running or before result mappings are available.

  - `id: string`

    Unique identifier

  - `config: Config`

    Batch configuration snapshot.

    - `job: Job`

      Job to create for each file in the source directory.

      - `configuration_id: string`

        Saved product configuration ID matching the job type.

      - `type: "parse_v2" | "extract_v2"`

        Product job type to run for each source directory file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `project_id: string`

    Project this batch belongs to.

  - `source_directory_id: string`

    Directory being processed.

  - `status: "PENDING" | "THROTTLED" | "RUNNING" | 3 more`

    Current batch status.

    - `"PENDING"`

    - `"THROTTLED"`

    - `"RUNNING"`

    - `"COMPLETED"`

    - `"FAILED"`

    - `"CANCELLED"`

  - `created_at?: string | null`

    Creation datetime

  - `results?: Array<Result> | null`

    Expanded per-file result mappings. Null unless requested with expand=results, or until result mappings are available.

    - `source_directory_file_id: string`

      Source directory file processed by this batch.

    - `error_message?: string | null`

      Batch-level mapping error if the system could not create or associate a job for this source file.

    - `job_reference?: JobReference | null`

      Reference to a job produced by a batch.

      Example:
      {
      "type": "parse_v2",
      "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      }

      - `id: string`

        Job ID, such as a parse job ID.

      - `type: "parse_v2" | "extract_v2"`

        Type of job produced for the file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `updated_at?: string | null`

    Update datetime

### Batch List Response

- `BatchListResponse`

  A top-level batch.

  Example:
  {
  "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "project_id": "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "source_directory_id": "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "config": {
  "job": {
  "type": "parse_v2",
  "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  }
  },
  "status": "COMPLETED",
  "results": [
  {
  "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "job_reference": {
  "type": "parse_v2",
  "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  },
  "error_message": null
  }
  ]
  }

  Batch-level `FAILED` means the orchestration failed and cannot provide a
  reliable per-file result set. `results` is only populated when explicitly
  requested with `expand=results` and may be `null` while a batch is still
  running or before result mappings are available.

  - `id: string`

    Unique identifier

  - `config: Config`

    Batch configuration snapshot.

    - `job: Job`

      Job to create for each file in the source directory.

      - `configuration_id: string`

        Saved product configuration ID matching the job type.

      - `type: "parse_v2" | "extract_v2"`

        Product job type to run for each source directory file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `project_id: string`

    Project this batch belongs to.

  - `source_directory_id: string`

    Directory being processed.

  - `status: "PENDING" | "THROTTLED" | "RUNNING" | 3 more`

    Current batch status.

    - `"PENDING"`

    - `"THROTTLED"`

    - `"RUNNING"`

    - `"COMPLETED"`

    - `"FAILED"`

    - `"CANCELLED"`

  - `created_at?: string | null`

    Creation datetime

  - `results?: Array<Result> | null`

    Expanded per-file result mappings. Null unless requested with expand=results, or until result mappings are available.

    - `source_directory_file_id: string`

      Source directory file processed by this batch.

    - `error_message?: string | null`

      Batch-level mapping error if the system could not create or associate a job for this source file.

    - `job_reference?: JobReference | null`

      Reference to a job produced by a batch.

      Example:
      {
      "type": "parse_v2",
      "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      }

      - `id: string`

        Job ID, such as a parse job ID.

      - `type: "parse_v2" | "extract_v2"`

        Type of job produced for the file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `updated_at?: string | null`

    Update datetime

### Batch Get Response

- `BatchGetResponse`

  A top-level batch.

  Example:
  {
  "id": "bat-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "project_id": "prj-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "source_directory_id": "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "config": {
  "job": {
  "type": "parse_v2",
  "configuration_id": "cfg-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  }
  },
  "status": "COMPLETED",
  "results": [
  {
  "source_directory_file_id": "dfl-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "job_reference": {
  "type": "parse_v2",
  "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
  },
  "error_message": null
  }
  ]
  }

  Batch-level `FAILED` means the orchestration failed and cannot provide a
  reliable per-file result set. `results` is only populated when explicitly
  requested with `expand=results` and may be `null` while a batch is still
  running or before result mappings are available.

  - `id: string`

    Unique identifier

  - `config: Config`

    Batch configuration snapshot.

    - `job: Job`

      Job to create for each file in the source directory.

      - `configuration_id: string`

        Saved product configuration ID matching the job type.

      - `type: "parse_v2" | "extract_v2"`

        Product job type to run for each source directory file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `project_id: string`

    Project this batch belongs to.

  - `source_directory_id: string`

    Directory being processed.

  - `status: "PENDING" | "THROTTLED" | "RUNNING" | 3 more`

    Current batch status.

    - `"PENDING"`

    - `"THROTTLED"`

    - `"RUNNING"`

    - `"COMPLETED"`

    - `"FAILED"`

    - `"CANCELLED"`

  - `created_at?: string | null`

    Creation datetime

  - `results?: Array<Result> | null`

    Expanded per-file result mappings. Null unless requested with expand=results, or until result mappings are available.

    - `source_directory_file_id: string`

      Source directory file processed by this batch.

    - `error_message?: string | null`

      Batch-level mapping error if the system could not create or associate a job for this source file.

    - `job_reference?: JobReference | null`

      Reference to a job produced by a batch.

      Example:
      {
      "type": "parse_v2",
      "id": "pjb-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
      }

      - `id: string`

        Job ID, such as a parse job ID.

      - `type: "parse_v2" | "extract_v2"`

        Type of job produced for the file.

        - `"parse_v2"`

        - `"extract_v2"`

  - `updated_at?: string | null`

    Update datetime
