# Batches

## Create Batch

`BatchCreateResponse batches().create(BatchCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`

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

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

### Parameters

- `BatchCreateParams params`

  - `Optional<String> organizationId`

  - `Optional<String> projectId`

  - `Config config`

    Batch configuration snapshot to apply to this source directory.

    - `Job job`

      Job to create for each file in the source directory.

      - `String configurationId`

        Product configuration ID or built-in preset ID matching the job type.

      - `Type type`

        Product job type to run for each source directory file.

        - `PARSE_V2("parse_v2")`

        - `EXTRACT_V2("extract_v2")`

  - `String sourceDirectoryId`

    Directory whose files should be processed.

### Returns

- `class 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-PARSE_AGENTIC"
  }
  },
  "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.

  - `String id`

    Unique identifier

  - `Config config`

    Batch configuration snapshot.

    - `Job job`

      Job to create for each file in the source directory.

      - `String configurationId`

        Product configuration ID or built-in preset ID matching the job type.

      - `Type type`

        Product job type to run for each source directory file.

        - `PARSE_V2("parse_v2")`

        - `EXTRACT_V2("extract_v2")`

  - `String projectId`

    Project this batch belongs to.

  - `String sourceDirectoryId`

    Directory being processed.

  - `Status status`

    Current batch status.

    - `PENDING("PENDING")`

    - `THROTTLED("THROTTLED")`

    - `RUNNING("RUNNING")`

    - `COMPLETED("COMPLETED")`

    - `FAILED("FAILED")`

    - `CANCELLED("CANCELLED")`

  - `Optional<LocalDateTime> createdAt`

    Creation datetime

  - `Optional<List<Result>> results`

    Expanded per-file result mappings. Null unless requested with expand=results, or while the batch is still running.

    - `String sourceDirectoryFileId`

      Source directory file processed by this batch.

    - `Optional<String> errorMessage`

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

    - `Optional<JobReference> jobReference`

      Reference to a job produced by a batch.

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

      - `String id`

        Job ID, such as a parse job ID.

      - `Type type`

        Type of job produced for the file.

        - `PARSE_V2("parse_v2")`

        - `EXTRACT_V2("extract_v2")`

  - `Optional<LocalDateTime> updatedAt`

    Update datetime

### Example

```java
package com.llamacloud_prod.api.example;

import com.llamacloud_prod.api.client.LlamaCloudClient;
import com.llamacloud_prod.api.client.okhttp.LlamaCloudOkHttpClient;
import com.llamacloud_prod.api.models.batches.BatchCreateParams;
import com.llamacloud_prod.api.models.batches.BatchCreateResponse;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        LlamaCloudClient client = LlamaCloudOkHttpClient.fromEnv();

        BatchCreateParams params = BatchCreateParams.builder()
            .config(BatchCreateParams.Config.builder()
                .job(BatchCreateParams.Config.Job.builder()
                    .configurationId("cfg-PARSE_AGENTIC")
                    .type(BatchCreateParams.Config.Job.Type.PARSE_V2)
                    .build())
                .build())
            .sourceDirectoryId("dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
            .build();
        BatchCreateResponse batch = client.batches().create(params);
    }
}
```

#### Response

```json
{
  "id": "id",
  "config": {
    "job": {
      "configuration_id": "cfg-PARSE_AGENTIC",
      "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

`BatchListPage batches().list(BatchListParamsparams = BatchListParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

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

List batches for the current project.

### Parameters

- `BatchListParams params`

  - `Optional<LocalDateTime> createdAtOnOrAfter`

  - `Optional<LocalDateTime> createdAtOnOrBefore`

  - `Optional<String> organizationId`

  - `Optional<Long> pageSize`

  - `Optional<String> pageToken`

  - `Optional<String> projectId`

  - `Optional<String> sourceDirectoryId`

  - `Optional<Status> status`

    - `PENDING("PENDING")`

    - `THROTTLED("THROTTLED")`

    - `RUNNING("RUNNING")`

    - `COMPLETED("COMPLETED")`

    - `FAILED("FAILED")`

    - `CANCELLED("CANCELLED")`

### Returns

- `class 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-PARSE_AGENTIC"
  }
  },
  "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.

  - `String id`

    Unique identifier

  - `Config config`

    Batch configuration snapshot.

    - `Job job`

      Job to create for each file in the source directory.

      - `String configurationId`

        Product configuration ID or built-in preset ID matching the job type.

      - `Type type`

        Product job type to run for each source directory file.

        - `PARSE_V2("parse_v2")`

        - `EXTRACT_V2("extract_v2")`

  - `String projectId`

    Project this batch belongs to.

  - `String sourceDirectoryId`

    Directory being processed.

  - `Status status`

    Current batch status.

    - `PENDING("PENDING")`

    - `THROTTLED("THROTTLED")`

    - `RUNNING("RUNNING")`

    - `COMPLETED("COMPLETED")`

    - `FAILED("FAILED")`

    - `CANCELLED("CANCELLED")`

  - `Optional<LocalDateTime> createdAt`

    Creation datetime

  - `Optional<List<Result>> results`

    Expanded per-file result mappings. Null unless requested with expand=results, or while the batch is still running.

    - `String sourceDirectoryFileId`

      Source directory file processed by this batch.

    - `Optional<String> errorMessage`

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

    - `Optional<JobReference> jobReference`

      Reference to a job produced by a batch.

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

      - `String id`

        Job ID, such as a parse job ID.

      - `Type type`

        Type of job produced for the file.

        - `PARSE_V2("parse_v2")`

        - `EXTRACT_V2("extract_v2")`

  - `Optional<LocalDateTime> updatedAt`

    Update datetime

### Example

```java
package com.llamacloud_prod.api.example;

import com.llamacloud_prod.api.client.LlamaCloudClient;
import com.llamacloud_prod.api.client.okhttp.LlamaCloudOkHttpClient;
import com.llamacloud_prod.api.models.batches.BatchListPage;
import com.llamacloud_prod.api.models.batches.BatchListParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        LlamaCloudClient client = LlamaCloudOkHttpClient.fromEnv();

        BatchListPage page = client.batches().list();
    }
}
```

#### Response

```json
{
  "items": [
    {
      "id": "id",
      "config": {
        "job": {
          "configuration_id": "cfg-PARSE_AGENTIC",
          "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

`BatchGetResponse batches().get(BatchGetParamsparams = BatchGetParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

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

Get a batch by ID.

### Parameters

- `BatchGetParams params`

  - `Optional<String> batchId`

  - `Optional<List<String>> expand`

    Fields to expand. Supported value: results.

  - `Optional<String> organizationId`

  - `Optional<String> projectId`

### Returns

- `class 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-PARSE_AGENTIC"
  }
  },
  "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.

  - `String id`

    Unique identifier

  - `Config config`

    Batch configuration snapshot.

    - `Job job`

      Job to create for each file in the source directory.

      - `String configurationId`

        Product configuration ID or built-in preset ID matching the job type.

      - `Type type`

        Product job type to run for each source directory file.

        - `PARSE_V2("parse_v2")`

        - `EXTRACT_V2("extract_v2")`

  - `String projectId`

    Project this batch belongs to.

  - `String sourceDirectoryId`

    Directory being processed.

  - `Status status`

    Current batch status.

    - `PENDING("PENDING")`

    - `THROTTLED("THROTTLED")`

    - `RUNNING("RUNNING")`

    - `COMPLETED("COMPLETED")`

    - `FAILED("FAILED")`

    - `CANCELLED("CANCELLED")`

  - `Optional<LocalDateTime> createdAt`

    Creation datetime

  - `Optional<List<Result>> results`

    Expanded per-file result mappings. Null unless requested with expand=results, or while the batch is still running.

    - `String sourceDirectoryFileId`

      Source directory file processed by this batch.

    - `Optional<String> errorMessage`

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

    - `Optional<JobReference> jobReference`

      Reference to a job produced by a batch.

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

      - `String id`

        Job ID, such as a parse job ID.

      - `Type type`

        Type of job produced for the file.

        - `PARSE_V2("parse_v2")`

        - `EXTRACT_V2("extract_v2")`

  - `Optional<LocalDateTime> updatedAt`

    Update datetime

### Example

```java
package com.llamacloud_prod.api.example;

import com.llamacloud_prod.api.client.LlamaCloudClient;
import com.llamacloud_prod.api.client.okhttp.LlamaCloudOkHttpClient;
import com.llamacloud_prod.api.models.batches.BatchGetParams;
import com.llamacloud_prod.api.models.batches.BatchGetResponse;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        LlamaCloudClient client = LlamaCloudOkHttpClient.fromEnv();

        BatchGetResponse batch = client.batches().get("batch_id");
    }
}
```

#### Response

```json
{
  "id": "id",
  "config": {
    "job": {
      "configuration_id": "cfg-PARSE_AGENTIC",
      "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"
}
```
