--- title: "anyllm_batch_engine" description: "Reference for the HTTP-agnostic batch orchestration crate, including job types, submission flow, and JSONL validation." --- Source files: `crates/batch_engine/src/lib.rs`, `crates/batch_engine/src/engine.rs`, `crates/batch_engine/src/job.rs`, `crates/batch_engine/src/validation.rs` ## Import Path ```rust use anyllm_batch_engine::{ BatchEngine, BatchId, ItemId, BatchJob, BatchItem, BatchStatus, ItemStatus, RequestCounts, BatchSubmission, SubmissionItem, ExecutionMode, SourceFormat, validate_jsonl, ValidatedJsonl, }; ``` ## `BatchEngine` ```rust pub struct BatchEngine { pub queue: Arc, pub file_store: FileStore, pub webhook_queue: Arc, pub global_webhook_urls: Vec, pub webhook_signing_secret: Option, } pub async fn submit(&self, submission: BatchSubmission) -> Result pub async fn get(&self, id: &BatchId) -> Result, EngineError> pub async fn list( &self, key_id: Option, cursor: Option<&str>, limit: u32, ) -> Result, EngineError> pub async fn cancel(&self, id: &BatchId) -> Result pub async fn get_items(&self, id: &BatchId) -> Result, EngineError> ``` ### Method summary | Method | Parameters | Return type | Description | |---|---|---|---| | `submit` | `submission: BatchSubmission` | `Result` | Validates file existence, builds job and items, enqueues work, emits `batch.queued`. | | `get` | `id: &BatchId` | `Result, EngineError>` | Loads one job. | | `list` | `key_id`, `cursor`, `limit` | `Result, EngineError>` | Lists jobs for admin or user views. | | `cancel` | `id: &BatchId` | `Result` | Cancels the job and emits `batch.cancelled` when applicable. | | `get_items` | `id: &BatchId` | `Result, EngineError>` | Loads item-level results. | ## Core Job Types ```rust pub struct BatchId(pub String) pub struct ItemId(pub String) pub enum BatchStatus { Queued, Processing, Completed, Failed, Cancelling, Cancelled, Expired, } pub enum ExecutionMode { Native { provider: String }, ProxyNative, } pub struct BatchSubmission { pub items: Vec, pub execution_mode: ExecutionMode, pub input_file_id: String, pub key_id: Option, pub webhook_url: Option, pub metadata: Option, pub priority: u8, } ``` ## Validation API ```rust pub struct ValidatedJsonl { pub line_count: usize, } pub fn validate_jsonl( reader: impl std::io::BufRead, ) -> Result ``` `validate_jsonl` rejects files larger than 100 MB, longer than 50,000 non-blank lines, empty files, duplicate `custom_id` values, missing `body`, and missing `body.model`. ## Example ```rust use anyllm_batch_engine::{validate_jsonl, BatchId}; use std::io::Cursor; let data = br#"{"custom_id":"a","body":{"model":"gpt-4o-mini"}}"#; let validated = validate_jsonl(Cursor::new(&data[..]))?; let id = BatchId::new(); assert_eq!(validated.line_count, 1); assert!(id.0.starts_with("batch_")); # Ok::<(), String>(()) ```