# Batches ## Create Batch `client.Batches.New(ctx, params) (*BatchNewResponse, error)` **post** `/api/v2/batches` Create a batch over a source directory and start processing asynchronously. ### Parameters - `params BatchNewParams` - `Config param.Field[BatchNewParamsConfig]` Body param: Batch configuration snapshot to apply to this source directory. - `Job BatchNewParamsConfigJob` Job to create for each file in the source directory. - `ConfigurationID string` Product configuration ID or built-in preset ID matching the job type. - `Type BatchNewParamsConfigJobType` Product job type to run for each source directory file. - `const BatchNewParamsConfigJobTypeParseV2 BatchNewParamsConfigJobType = "parse_v2"` - `const BatchNewParamsConfigJobTypeExtractV2 BatchNewParamsConfigJobType = "extract_v2"` - `SourceDirectoryID param.Field[string]` Body param: Directory whose files should be processed. - `OrganizationID param.Field[string]` Query param - `ProjectID param.Field[string]` Query param ### Returns - `type BatchNewResponse struct{…}` 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. - `ID string` Unique identifier - `Config BatchNewResponseConfig` Batch configuration snapshot. - `Job BatchNewResponseConfigJob` Job to create for each file in the source directory. - `ConfigurationID string` Product configuration ID or built-in preset ID matching the job type. - `Type BatchNewResponseConfigJobType` Product job type to run for each source directory file. - `const BatchNewResponseConfigJobTypeParseV2 BatchNewResponseConfigJobType = "parse_v2"` - `const BatchNewResponseConfigJobTypeExtractV2 BatchNewResponseConfigJobType = "extract_v2"` - `ProjectID string` Project this batch belongs to. - `SourceDirectoryID string` Directory being processed. - `Status BatchNewResponseStatus` Current batch status. - `const BatchNewResponseStatusPending BatchNewResponseStatus = "PENDING"` - `const BatchNewResponseStatusThrottled BatchNewResponseStatus = "THROTTLED"` - `const BatchNewResponseStatusRunning BatchNewResponseStatus = "RUNNING"` - `const BatchNewResponseStatusCompleted BatchNewResponseStatus = "COMPLETED"` - `const BatchNewResponseStatusFailed BatchNewResponseStatus = "FAILED"` - `const BatchNewResponseStatusCancelled BatchNewResponseStatus = "CANCELLED"` - `CreatedAt Time` Creation datetime - `Results []BatchNewResponseResult` Expanded per-file result mappings. Null unless requested with expand=results, or while the batch is still running. - `SourceDirectoryFileID string` Source directory file processed by this batch. - `ErrorMessage string` Batch-level mapping error if the system could not create or associate a job for this source file. - `JobReference BatchNewResponseResultJobReference` 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 BatchNewResponseResultJobReferenceType` Type of job produced for the file. - `const BatchNewResponseResultJobReferenceTypeParseV2 BatchNewResponseResultJobReferenceType = "parse_v2"` - `const BatchNewResponseResultJobReferenceTypeExtractV2 BatchNewResponseResultJobReferenceType = "extract_v2"` - `UpdatedAt Time` Update datetime ### Example ```go package main import ( "context" "fmt" "github.com/run-llama/llama-parse-go" "github.com/run-llama/llama-parse-go/option" ) func main() { client := llamacloudprod.NewClient( option.WithAPIKey("My API Key"), ) batch, err := client.Batches.New(context.TODO(), llamacloudprod.BatchNewParams{ Config: llamacloudprod.BatchNewParamsConfig{ Job: llamacloudprod.BatchNewParamsConfigJob{ ConfigurationID: "cfg-PARSE_AGENTIC", Type: llamacloudprod.BatchNewParamsConfigJobTypeParseV2, }, }, SourceDirectoryID: "dir-aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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" } ``` ## List Batches `client.Batches.List(ctx, query) (*PaginatedCursor[BatchListResponse], error)` **get** `/api/v2/batches` List batches for the current project. ### Parameters - `query BatchListParams` - `CreatedAtOnOrAfter param.Field[Time]` - `CreatedAtOnOrBefore param.Field[Time]` - `OrganizationID param.Field[string]` - `PageSize param.Field[int64]` - `PageToken param.Field[string]` - `ProjectID param.Field[string]` - `SourceDirectoryID param.Field[string]` - `Status param.Field[BatchListParamsStatus]` - `const BatchListParamsStatusPending BatchListParamsStatus = "PENDING"` - `const BatchListParamsStatusThrottled BatchListParamsStatus = "THROTTLED"` - `const BatchListParamsStatusRunning BatchListParamsStatus = "RUNNING"` - `const BatchListParamsStatusCompleted BatchListParamsStatus = "COMPLETED"` - `const BatchListParamsStatusFailed BatchListParamsStatus = "FAILED"` - `const BatchListParamsStatusCancelled BatchListParamsStatus = "CANCELLED"` ### Returns - `type BatchListResponse struct{…}` 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. - `ID string` Unique identifier - `Config BatchListResponseConfig` Batch configuration snapshot. - `Job BatchListResponseConfigJob` Job to create for each file in the source directory. - `ConfigurationID string` Product configuration ID or built-in preset ID matching the job type. - `Type BatchListResponseConfigJobType` Product job type to run for each source directory file. - `const BatchListResponseConfigJobTypeParseV2 BatchListResponseConfigJobType = "parse_v2"` - `const BatchListResponseConfigJobTypeExtractV2 BatchListResponseConfigJobType = "extract_v2"` - `ProjectID string` Project this batch belongs to. - `SourceDirectoryID string` Directory being processed. - `Status BatchListResponseStatus` Current batch status. - `const BatchListResponseStatusPending BatchListResponseStatus = "PENDING"` - `const BatchListResponseStatusThrottled BatchListResponseStatus = "THROTTLED"` - `const BatchListResponseStatusRunning BatchListResponseStatus = "RUNNING"` - `const BatchListResponseStatusCompleted BatchListResponseStatus = "COMPLETED"` - `const BatchListResponseStatusFailed BatchListResponseStatus = "FAILED"` - `const BatchListResponseStatusCancelled BatchListResponseStatus = "CANCELLED"` - `CreatedAt Time` Creation datetime - `Results []BatchListResponseResult` Expanded per-file result mappings. Null unless requested with expand=results, or while the batch is still running. - `SourceDirectoryFileID string` Source directory file processed by this batch. - `ErrorMessage string` Batch-level mapping error if the system could not create or associate a job for this source file. - `JobReference BatchListResponseResultJobReference` 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 BatchListResponseResultJobReferenceType` Type of job produced for the file. - `const BatchListResponseResultJobReferenceTypeParseV2 BatchListResponseResultJobReferenceType = "parse_v2"` - `const BatchListResponseResultJobReferenceTypeExtractV2 BatchListResponseResultJobReferenceType = "extract_v2"` - `UpdatedAt Time` Update datetime ### Example ```go package main import ( "context" "fmt" "github.com/run-llama/llama-parse-go" "github.com/run-llama/llama-parse-go/option" ) func main() { client := llamacloudprod.NewClient( option.WithAPIKey("My API Key"), ) page, err := client.Batches.List(context.TODO(), llamacloudprod.BatchListParams{ }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### 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 `client.Batches.Get(ctx, batchID, query) (*BatchGetResponse, error)` **get** `/api/v2/batches/{batch_id}` Get a batch by ID. ### Parameters - `batchID string` - `query BatchGetParams` - `Expand param.Field[[]string]` Fields to expand. Supported value: results. - `OrganizationID param.Field[string]` - `ProjectID param.Field[string]` ### Returns - `type BatchGetResponse struct{…}` 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. - `ID string` Unique identifier - `Config BatchGetResponseConfig` Batch configuration snapshot. - `Job BatchGetResponseConfigJob` Job to create for each file in the source directory. - `ConfigurationID string` Product configuration ID or built-in preset ID matching the job type. - `Type BatchGetResponseConfigJobType` Product job type to run for each source directory file. - `const BatchGetResponseConfigJobTypeParseV2 BatchGetResponseConfigJobType = "parse_v2"` - `const BatchGetResponseConfigJobTypeExtractV2 BatchGetResponseConfigJobType = "extract_v2"` - `ProjectID string` Project this batch belongs to. - `SourceDirectoryID string` Directory being processed. - `Status BatchGetResponseStatus` Current batch status. - `const BatchGetResponseStatusPending BatchGetResponseStatus = "PENDING"` - `const BatchGetResponseStatusThrottled BatchGetResponseStatus = "THROTTLED"` - `const BatchGetResponseStatusRunning BatchGetResponseStatus = "RUNNING"` - `const BatchGetResponseStatusCompleted BatchGetResponseStatus = "COMPLETED"` - `const BatchGetResponseStatusFailed BatchGetResponseStatus = "FAILED"` - `const BatchGetResponseStatusCancelled BatchGetResponseStatus = "CANCELLED"` - `CreatedAt Time` Creation datetime - `Results []BatchGetResponseResult` Expanded per-file result mappings. Null unless requested with expand=results, or while the batch is still running. - `SourceDirectoryFileID string` Source directory file processed by this batch. - `ErrorMessage string` Batch-level mapping error if the system could not create or associate a job for this source file. - `JobReference BatchGetResponseResultJobReference` 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 BatchGetResponseResultJobReferenceType` Type of job produced for the file. - `const BatchGetResponseResultJobReferenceTypeParseV2 BatchGetResponseResultJobReferenceType = "parse_v2"` - `const BatchGetResponseResultJobReferenceTypeExtractV2 BatchGetResponseResultJobReferenceType = "extract_v2"` - `UpdatedAt Time` Update datetime ### Example ```go package main import ( "context" "fmt" "github.com/run-llama/llama-parse-go" "github.com/run-llama/llama-parse-go/option" ) func main() { client := llamacloudprod.NewClient( option.WithAPIKey("My API Key"), ) batch, err := client.Batches.Get( context.TODO(), "batch_id", llamacloudprod.BatchGetParams{ }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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" } ```