Skip to main content

Overview

Batch processing allows you to send asynchronous requests at significantly reduced costs. LiteLLM supports batch APIs across providers including OpenAI and Anthropic.

Quick Start

When to Use Batching

  • 50% lower cost compared to synchronous API
  • Ideal for non-urgent, high-volume tasks
  • Best for offline processing
  • Data classification and labeling
  • Content generation for datasets
  • Evaluation and testing
  • Embedding large corpora
  • Bulk data transformation
  • Real-time applications
  • User-facing features
  • Time-sensitive tasks
  • Interactive workflows

OpenAI Batch API

Anthropic Batch API

Complete Workflow

List Batches

Batch with Different Request Types

Error Handling

Monitoring Progress

Cost Calculation

Best Practices

  • Use descriptive custom_id values for tracking
  • Validate requests before creating batch
  • Keep batch size reasonable (1000-50000 requests)
  • Include metadata for organization
  • Poll status periodically (every 1-5 minutes)
  • Set up alerts for completion/failure
  • Monitor request counts for progress
  • Log batch IDs for tracking
  • Check for errors in individual results
  • Implement retry logic for failed requests
  • Save partial results before processing
  • Have fallback for batch failures
  • Use batching for all non-urgent tasks
  • Combine similar requests into batches
  • Use cheaper models when appropriate
  • Monitor and optimize batch sizes

Limitations

  • Completion time is not guaranteed (usually within 24h)
  • Cannot cancel individual requests
  • No real-time status updates
  • Results available for limited time (check provider docs)
  • Some features may not be available in batch mode

Supported Features

LiteLLM Proxy with Batching