Skip to content

Bogda01m/OpenAI batch mode #2367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/batches/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Batch Processing

Pydantic AI supports batch processing through provider-specific implementations that allow you to process multiple requests cost-effectively with only one request.

!!! info "About batch processing"
*Batch processing is very useful when you want to process large datasets and make multiple calls to an LLM provider. You don't need to process them with loops - just create a batch, save `batch_id` somewhere and forget about it until it's ready. Alternatively, it's also useful if you're willing to wait up to 24 hours for a response.*

## OpenAI Batch API

The OpenAI Batch API provides 50% cost savings compared to default API calls with a 24-hour processing window. Batch jobs require at least 2 requests.

[Learn more about OpenAI Batch API →](openai.md)

## Key Benefits

- **Cost Savings**: Up to 50% reduction in API costs
- **Bulk Processing**: Handle hundreds or thousands of requests efficiently
- **Async Processing**: Submit jobs and retrieve results when ready
- **Tool Support**: Full support for tools
- **Structured Output**: All output modes (native, tool, prompted) supported

!!! warning "Important: Tool Usage with Batch API"
When using tools with batch processing, the AI model returns tool call **requests** rather than executing tools automatically. You need to:

1. **Check batch results** for `tool_calls` instead of direct responses
2. **Execute the tools manually** in your application code
3. **Submit follow-up requests** with tool responses to get final AI answers

This differs from the regular Agent API which handles tool execution automatically.

## Use Cases

Batch processing is ideal for:

- **Data Analysis**: Processing large datasets with LLM analysis
- **Content Generation**: Bulk content creation and transformation
- **Evaluation**: Running evaluations across multiple test cases
- **A/B Testing**: Comparing different prompts or models
- **Bulk Translation**: Translating multiple documents
- **Report Generation**: Creating reports from structured data

## Available Providers

Currently supported batch processing providers:

- **OpenAI**: batch API support with tools and structured outputs

Additional providers may be added in future releases.
Loading