Skip to content

fix(bedrock): resolve aliases in batch file records - #36159

Merged
mateo-berri merged 2 commits into
BerriAI:litellm_internal_stagingfrom
daleselaji-dev:codex/bedrock-alias-36156
Aug 15, 2026
Merged

mateo-berri merged 2 commits into
BerriAI:litellm_internal_stagingfrom
daleselaji-dev:codex/bedrock-alias-36156

Conversation

@daleselaji-dev

@daleselaji-dev daleselaji-dev commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Bedrock batch records naming a proxy model alias reach AWS untransformed
  • The batch then reports Completed while every record failed validation

How it solves it:

  • Resolve model_alias_map aliases before picking each record's provider transform
  • Fall back to the batch's own deployment model when a record's model matches no Bedrock provider

User Flow

Before: the batch reports Completed, but the output holds only anthropic_version: Field required errors and no model replies

  1. The proxy admin lists bedrock-batch -> bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0 in model_list, plus the batch S3 bucket and job role
  2. A developer uploads their JSONL with POST http://litellm-domain/v1/files (multipart: purpose=batch, model=bedrock-batch), each line's body carrying "model": "bedrock-batch", and gets back a long encoded file id
  3. They create the batch with POST http://litellm-domain/v1/batches sending {"input_file_id": "<that id>", "endpoint": "/v1/chat/completions", "completion_window": "24h", "model": "bedrock-batch"} and get a batch id with status validating
  4. They poll GET http://litellm-domain/v1/batches/{batch_id} until "status": "completed" (~10-15 minutes)
  5. They download results via GET http://litellm-domain/v1/files/{output_file_id}/content and every line is an error naming anthropic_version: Field required; not one record contains a model reply

After: the same upload now returns a model reply for every record

  1. The proxy admin lists bedrock-batch -> bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0 in model_list, plus the batch S3 bucket and job role
  2. A developer uploads their JSONL with POST http://litellm-domain/v1/files (multipart: purpose=batch, model=bedrock-batch), each line's body carrying "model": "bedrock-batch", and gets back a long encoded file id
  3. They create the batch with POST http://litellm-domain/v1/batches sending {"input_file_id": "<that id>", "endpoint": "/v1/chat/completions", "completion_window": "24h", "model": "bedrock-batch"} and get a batch id with status validating
  4. They poll GET http://litellm-domain/v1/batches/{batch_id} until "status": "completed" (~10-15 minutes)
  5. GET http://litellm-domain/v1/files/{output_file_id}/content now returns one modelOutput with assistant content per record and no validation errors

Relevant issues

Fixes #36156

Linear ticket

Resolves LIT-5304

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Two live proxies, one per leg, each booted with the same config (bedrock-batch -> bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0, an SSE-KMS-enforced S3 bucket, and a Bedrock batch job role) and fed the same 110-record JSONL whose every line's body says "model": "bedrock-batch". Real Bedrock model-invocation jobs in us-west-2, no mocks. Before leg at merge base f03df1b, after leg at this PR's head e8c1fe8

Before (f03df1b, proxy on port 60641): batch says Completed, every record failed

Upload and batch create:

curl http://localhost:60641/v1/files -H "Authorization: Bearer sk-1234" \
  -F purpose=batch -F model=bedrock-batch -F "file=@batch_alias.jsonl"
# -> {"id":"file-bGl0ZWxsbTpzMzovL2xpdGVsbG0ta21zLXFhLTM1MTQ4...","object":"file","purpose":"batch","status":"uploaded",...}

curl http://localhost:60641/v1/batches -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"input_file_id": "<that id>", "endpoint": "/v1/chat/completions", "completion_window": "24h", "model": "bedrock-batch"}'
# -> {"id":"batch_bGl0ZWxsbTphcm46YXdzOmJlZHJvY2s6dXMtd2VzdC0yOjQzOTE1ODA3NDY1Mjptb2RlbC1pbnZvY2F0aW9uLWpvYi9rZTg2MDAza2gwajU...","status":"validating",...}

Final batch object after polling (validating -> in_progress -> completed):

curl "http://localhost:60641/v1/batches/{batch_id}?model=bedrock-batch" -H "Authorization: Bearer sk-1234"
# -> {"status":"completed","completed_at":1786753624,"error_file_id":null,"errors":null,
#     "metadata":{"job_arn":"arn:aws:bedrock:us-west-2:439158074652:model-invocation-job/ke86003kh0j5","failure_message":""},
#     "output_file_id":"file-bGl0ZWxsbTpzMzovL2xpdGVsbG0ta21zLXFhLTM1MTQ4L2xpdGVsbG0tYmF0Y2gtb3V0cHV0cy8...",...}

Output content through the proxy (HTTP 200, 110 lines), first records verbatim:

curl "http://localhost:60641/v1/files/{output_file_id}/content?model=bedrock-batch" -H "Authorization: Bearer sk-1234"
{"modelInput":{"messages":[{"role":"user","content":"Reply with the number 7 and nothing else."}],"max_tokens":16},"error":{"errorCode":400,"errorMessage":"anthropic_version: Field required","expired":false,"retryable":false},"recordId":"req-17"}
{"modelInput":{"messages":[{"role":"user","content":"Reply with the number 0 and nothing else."}],"max_tokens":16},"error":{"errorCode":400,"errorMessage":"anthropic_version: Field required","expired":false,"retryable":false},"recordId":"req-30"}

Counts over all 110 records: 110 anthropic_version: Field required errors, 0 other errors, 0 model replies. The rejected modelInput lines still carry the raw OpenAI-shaped body, untransformed

After (e8c1fe8, proxy on port 57789): same flow, every record answered

Same upload and batch create against port 57789 (file litellm-bedrock-files-bedrock-batch-0ef2cc3f-..., job arn:aws:bedrock:us-west-2:439158074652:model-invocation-job/bco4nk5uh1hn), polled to "status":"completed" with "error_file_id":null and empty failure_message. Output content through the proxy (HTTP 200), first record verbatim:

curl "http://localhost:57789/v1/files/{output_file_id}/content?model=bedrock-batch" -H "Authorization: Bearer sk-1234"
{"modelInput":{"messages":[{"role":"user","content":[{"type":"text","text":"Reply with the number 6 and nothing else."}]}],"max_tokens":16,"anthropic_version":"bedrock-2023-05-31"},"modelOutput":{"model":"claude-haiku-4-5-20251001","id":"msg_bdrk_01WCAn5P5adweBWVA9KwQiLV","type":"message","role":"assistant","content":[{"type":"text","text":"6"}],"stop_reason":"end_turn","usage":{"input_tokens":18,"output_tokens":5}},"recordId":"req-46"}

Counts over all 110 records: 110 assistant modelOutput replies, 0 errors of any kind, recordIds exactly req-1..req-110. Each modelInput shows the proxy rewrote the alias body into Bedrock-native form with anthropic_version: "bedrock-2023-05-31" injected, which is precisely the fix under test

Surprises hit during QA:

  • Batch reports completed with request_counts all zero
  • error_file_id stays null; errors live inside output file
  • Bedrock reorders output records (req-46 first)
  • Batches finished in ~10-12 min, not 30-50
  • Short-lived SSO creds expire mid-batch; static key needed

Type

🐛 Bug Fix

Caveats (if any)

  • Records naming some other router alias still need model_alias_map
  • Alias names containing a provider word (e.g. "team-meta-proxy") are still inferred as that provider, exactly as on the base branch; model_alias_map covers those too

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@CLAassistant

CLAassistant commented Aug 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mateo-berri
❌ daleselaji-dev
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR resolves Bedrock batch-record model aliases before provider-specific request transformation and adds deployment-model fallback behavior

  • Threads the selected model explicitly through chat and embedding transformations
  • Adds regression coverage for aliases, embeddings, provider precedence, and upload-time deployment fallback

Confidence Score: 5/5

The PR appears safe to merge

No blocking failure remains

Important Files Changed

Filename Overview
litellm/llms/bedrock/files/transformation.py Resolves record aliases and deployment fallbacks before selecting Bedrock request transformations
tests/test_litellm/llms/bedrock/files/test_bedrock_files_transformation.py Adds focused regression coverage for chat and embedding aliases, fallback behavior, and upload integration

Reviews (2): Last reviewed commit: "fix(bedrock): fall back to the batch dep..." | Re-trigger Greptile

import litellm

_model: Final = openai_request_body.get("model", "")
_model = litellm.model_alias_map.get(_model, _model)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Alias resolution rebinds locals

Both alias-resolution sites reassign their model variable, violating the repository's immutable-local convention and obscuring the distinction between original and resolved identifiers

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/bedrock/files/transformation.py 96.15% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing daleselaji-dev:codex/bedrock-alias-36156 (e8c1fe8) with litellm_internal_staging (29fe342)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (f99d0a4) during the generation of this report, so 29fe342 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@mateo-berri
mateo-berri force-pushed the codex/bedrock-alias-36156 branch from ce5f3cf to e8c1fe8 Compare August 15, 2026 00:11
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e8c1fe8. Configure here.

) -> tuple[str, BEDROCK_INVOKE_PROVIDERS_LITERAL | None]:
record_provider: Final = self.get_bedrock_invoke_provider(_strip_llm_routing_prefix(record_model))
if record_provider is not None or not target_model:
return record_model, record_provider

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alias fallback skips on provider substrings

Medium Severity

_resolve_batch_record_model_and_provider treats any non-None result from get_bedrock_invoke_provider as proof the record model is a real Bedrock id. That helper also matches provider names as substrings, so an unmapped alias like my-openai-batch or team-meta-proxy gets a false provider hit, skips the target_model fallback, and is left on the passthrough path without the Anthropic (or other) batch schema—reproducing the original anthropic_version validation failures for those alias names.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e8c1fe8. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Substring inference predates this PR, so those alias names fail identically on base. This change only shrinks the failing set; model_alias_map covers the rest.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mateo-berri
mateo-berri merged commit 1a183ef into BerriAI:litellm_internal_staging Aug 15, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bedrock batch records all fail with anthropic_version: Field required when the JSONL names the proxy model alias

3 participants