Skip to main content

Bedrock Batches

Use Amazon Bedrock Batch Inference API through LiteLLM.

PropertyDetails
DescriptionAmazon Bedrock Batch Inference allows you to run inference on large datasets asynchronously
Provider DocAWS Bedrock Batch Inference ↗
Cost Tracking✅ Supported

Overview​

Use this to:

  • Run batch inference on large datasets with Bedrock models
  • Control batch model access by key/user/team (same as chat completion models)
  • Manage S3 storage for batch input/output files

(Proxy Admin) Usage​

Here's how to give developers access to your Bedrock Batch models.

1. Setup config.yaml​

  • Specify mode: batch for each model: Allows developers to know this is a batch model
  • Configure S3 bucket and AWS credentials for batch operations
litellm_config.yaml
model_list:
- model_name: "bedrock-batch-claude"
litellm_params:
model: bedrock/us.anthropic.claude-sonnet-5
#########################################################
########## batch specific params ########################
s3_bucket_name: litellm-proxy
s3_region_name: us-west-2
s3_access_key_id: os.environ/AWS_ACCESS_KEY_ID
s3_secret_access_key: os.environ/AWS_SECRET_ACCESS_KEY
aws_batch_role_arn: arn:aws:iam::888602223428:role/service-role/AmazonBedrockExecutionRoleForAgents_BB9HNW6V4CV
# Optional: Custom KMS encryption key for the S3 input upload and the batch output
# s3_encryption_key_id: arn:aws:kms:us-west-2:123456789012:key/12345678-1234-1234-1234-123456789012
model_info:
mode: batch # 👈 SPECIFY MODE AS BATCH, to tell user this is a batch model

Required Parameters:

ParameterDescription
s3_bucket_nameS3 bucket for batch input/output files
s3_region_nameAWS region for S3 bucket
s3_access_key_idAWS access key for S3 bucket
s3_secret_access_keyAWS secret key for S3 bucket
aws_batch_role_arnIAM role ARN for Bedrock batch operations. Bedrock Batch APIs require an IAM role ARN to be set.
mode: batchIndicates to LiteLLM this is a batch model

S3 permissions the credentials need:

The AWS identity LiteLLM signs with needs s3:PutObject (upload), s3:GetObject (download results), s3:ListBucket (GET /v1/files), and s3:DeleteObject (DELETE /v1/files/{file_id}) on s3_bucket_name, and on s3_output_bucket_name when you set one. Listing and deleting only ever touch the key prefixes LiteLLM writes under (litellm-bedrock-files- for batch inputs, litellm-bedrock-files/ for other uploads, litellm-batch-outputs/ for results), so you can scope the policy to those

Optional Parameters:

ParameterDescription
s3_encryption_key_idCustom KMS encryption key ID for the batch input file LiteLLM uploads to S3 and for the batch output data. Requires kms:GenerateDataKey on that key for the credentials LiteLLM signs the upload with. If not specified, Bedrock uses AWS managed encryption keys.
s3_output_bucket_nameBucket (optionally bucket/prefix) Bedrock writes batch results to. Defaults to s3_bucket_name. GET /v1/files?purpose=batch_output lists this bucket.

2. Create Virtual Key​

create_virtual_key.sh
curl -L -X POST 'https://{PROXY_BASE_URL}/key/generate' \
-H 'Authorization: Bearer ${PROXY_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{"models": ["bedrock-batch-claude"]}'

You can now use the virtual key to access the batch models (See Developer flow).

(Developer) Usage​

Here's how to create a LiteLLM managed file and execute Bedrock Batch CRUD operations with the file.

1. Create request.jsonl​

  • Check models available via /model_group/info
  • See all models with mode: batch
  • Set model in .jsonl to the model from /model_group/info
bedrock_batch_completions.jsonl
{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "bedrock-batch-claude", "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello world!"}], "max_tokens": 1000}}
{"custom_id": "request-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "bedrock-batch-claude", "messages": [{"role": "system", "content": "You are an unhelpful assistant."}, {"role": "user", "content": "Hello world!"}], "max_tokens": 1000}}

Expectation:

  • LiteLLM translates this to the bedrock deployment specific value (e.g. bedrock/us.anthropic.claude-sonnet-5)

2. Upload File​

Specify target_model_names: "<model-name>" to enable LiteLLM managed files and request validation.

model-name should be the same as the model-name in the request.jsonl

bedrock_batch.py
from openai import OpenAI

client = OpenAI(
base_url="http://0.0.0.0:4000",
api_key="sk-1234",
)

# Upload file
batch_input_file = client.files.create(
file=open("./bedrock_batch_completions.jsonl", "rb"), # {"model": "bedrock-batch-claude"} <-> {"model": "bedrock/us.anthropic.claude-sonnet-5"}
purpose="batch",
extra_body={"target_model_names": "bedrock-batch-claude"}
)
print(batch_input_file)

Where is the file written?:

The file is written to S3 bucket specified in your config and prepared for Bedrock batch inference.

3. Create the batch​

bedrock_batch.py
...
# Create batch
batch = client.batches.create(
input_file_id=batch_input_file.id,
endpoint="/v1/chat/completions",
completion_window="24h",
metadata={"description": "Test batch job"},
)
print(batch)

4. Retrieve batch results​

Once the batch job is completed, download the results from S3:

bedrock_batch.py
...
# Wait for batch completion (check status periodically)
batch_status = client.batches.retrieve(batch_id=batch.id)

if batch_status.status == "completed":
# Download the output file
result = client.files.content(
file_id=batch_status.output_file_id,
extra_headers={"custom-llm-provider": "bedrock"}
)

# Save or process the results
with open("batch_output.jsonl", "wb") as f:
f.write(result.content)

# Parse JSONL results
for line in result.text.strip().split('\n'):
record = json.loads(line)
print(f"Record ID: {record['recordId']}")
print(f"Output: {record.get('modelOutput', {})}")

Output Format:

The batch output file is in JSONL format with each line containing:

{
"recordId": "request-1",
"modelInput": {
"messages": [...],
"max_tokens": 1000
},
"modelOutput": {
"content": [...],
"id": "msg_abc123",
"model": "us.anthropic.claude-sonnet-5",
"role": "assistant",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 15,
"output_tokens": 10
}
}
}

5. List and delete files​

GET /v1/files with target_model_names lists what LiteLLM has written under the deployment's bucket, straight from S3. purpose=batch lists the inputs you uploaded, purpose=batch_output lists the results finished batch jobs wrote (both <jobId>/input.jsonl.out and <jobId>/manifest.json.out), and leaving purpose out lists both when they share a bucket. Any other purpose returns an empty list: every upload lands under the same prefixes and is listed as batch whatever purpose it was uploaded with, and job results are batch_output. The response is the same page shape OpenAI returns (object: list, data, has_more), and it stops at 10,000 files, OpenAI's own ceiling; limit and after are not applied

DELETE /v1/files/{file_id} removes the S3 object behind a LiteLLM managed file id (and forgets the id), or, for proxy admin keys, with ?model=<model-name>, the raw s3:// object a batch result points at. Other keys get a 403 on a raw id, and an id outside the deployment's configured bucket is answered with a 400 rather than touched

bedrock_batch.py
...
# List the inputs uploaded for this deployment
page = client.files.list(
purpose="batch",
extra_query={"target_model_names": "bedrock-batch-claude"},
)
print([f.id for f in page.data])

# List the results finished batch jobs wrote
outputs = client.files.list(
purpose="batch_output",
extra_query={"target_model_names": "bedrock-batch-claude"},
)

# Delete a managed file (the S3 object goes with it)
deleted = client.files.delete(batch_input_file.id)
print(deleted.deleted) # True

Listing by target_model_names is scoped to the deployment, not to the caller, the same way OpenAI's file list is org-wide: any key allowed to call the model sees every file under the deployment's prefixes, raw s3:// ids included. Deleting by a raw s3:// id is limited to proxy admin keys, so that listing is inventory for everyone else. The LiteLLM managed file ids that POST /v1/files with target_model_names returns are checked against the uploading user, so hand end users those ids and keep the batch model itself on the keys that should see its bucket

FAQ​

Where are my files written?​

When a target_model_names is specified, the file is written to the S3 bucket configured in your Bedrock batch model configuration.

What models are supported?​

LiteLLM only supports Bedrock Anthropic Models for Batch API. If you want other bedrock models file an issue here.

How do I use a custom KMS encryption key?​

If your S3 bucket requires a custom KMS encryption key, you can specify it in your configuration using s3_encryption_key_id. This is useful for enterprise customers with specific encryption requirements.

The key covers both objects LiteLLM touches: the batch input file it uploads to your bucket, and the batch output Bedrock writes back. The input upload is signed with x-amz-server-side-encryption: aws:kms and this key ARN, so the AWS identity LiteLLM uploads with needs kms:GenerateDataKey on the key. Grant that before setting the key, otherwise POST /v1/files fails with an S3 AccessDenied

You can set the encryption key in 2 ways:

  1. In config.yaml (recommended):
model_list:
- model_name: "bedrock-batch-claude"
litellm_params:
model: bedrock/us.anthropic.claude-sonnet-5
s3_encryption_key_id: arn:aws:kms:us-west-2:123456789012:key/12345678-1234-1234-1234-123456789012
# ... other params
  1. As an environment variable:
export AWS_S3_ENCRYPTION_KEY_ID=arn:aws:kms:us-west-2:123456789012:key/12345678-1234-1234-1234-123456789012

Further Reading​