Skip to content

fix(bedrock): read s3_bucket_name passed to the SDK for Bedrock file content - #47459

Closed
ryan-crabbe-berri wants to merge 1 commit into
mainfrom
litellm_lit_9501_sdk_s3_bucket_name_kwarg
Closed

ryan-crabbe-berri wants to merge 1 commit into
mainfrom
litellm_lit_9501_sdk_s3_bucket_name_kwarg

Conversation

@ryan-crabbe-berri

@ryan-crabbe-berri ryan-crabbe-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

  • If you use the Python SDK directly to read a Bedrock batch file from S3 and tell it which bucket to use, it ignored you and said no bucket was set
  • Uploading worked, only reading the file back broke
  • The only way around it was a global env var for the bucket
  • Now, if you call the SDK directly, the bucket you pass is used
  • If you go through the proxy nothing changes, the bucket still comes only from the proxy config and never from the client

User Flow

Before: a developer using the Python SDK against Bedrock batch can upload a file but cannot read it back

  1. They call litellm.create_file(purpose="batch", custom_llm_provider="bedrock", s3_bucket_name="my-bucket", ...) and get back an s3://my-bucket/litellm-bedrock-files-...jsonl id
  2. They call litellm.file_content(file_id=<that id>, custom_llm_provider="bedrock", s3_bucket_name="my-bucket", ...)
  3. It raises ValueError: S3 bucket_name is required. Set 's3_bucket_name' in proxy config or AWS_S3_BUCKET_NAME even though they passed the bucket

After: the same two calls work with nothing but the kwargs they already pass

  1. They call litellm.create_file(...) exactly as before and get the same kind of s3://my-bucket/... id
  2. They call litellm.file_content(...) exactly as before
  3. The file body comes back from my-bucket

A proxy user is unaffected either way. The bucket on GET /v1/files/{id}/content still comes from the deployment's s3_bucket_name in the proxy config, and a bucket a client tries to send is ignored

Relevant issues

Fixes #45061

Linear ticket

Resolves LIT-9501

Pre-Submission checklist

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

Shared setup. Real AWS account, real S3 bucket litellm-lit4162-batch-439158074652 in us-west-2, AWS_S3_BUCKET_NAME unset everywhere. The SDK script is the exact two calls a user makes

AWS_PROFILE=litellm-dev python - <<'PY'
import os, litellm
assert "AWS_S3_BUCKET_NAME" not in os.environ
bucket = "litellm-lit4162-batch-439158074652"
body = b'{"custom_id":"r1","method":"POST","url":"/v1/chat/completions","body":{"model":"anthropic.claude-3-haiku-20240307-v1:0","messages":[{"role":"user","content":"hi"}]}}\n'
f = litellm.create_file(file=("lit9501.jsonl", body), purpose="batch", custom_llm_provider="bedrock",
                        s3_bucket_name=bucket, s3_region_name="us-west-2", aws_region_name="us-west-2")
print("UPLOAD OK:", f.id)
c = litellm.file_content(file_id=f.id, custom_llm_provider="bedrock",
                         s3_bucket_name=bucket, s3_region_name="us-west-2", aws_region_name="us-west-2")
print("CONTENT OK:", c.content[:60])
PY

Proxy config used for the proxy case, started with litellm --config lit9501_proxy.yaml --port 4931

model_list:
  - model_name: bedrock-batch
    litellm_params:
      model: bedrock/anthropic.claude-3-haiku-20240307-v1:0
      aws_region_name: us-west-2
      s3_bucket_name: litellm-lit4162-batch-439158074652
      s3_region_name: us-west-2
    model_info:
      mode: batch
general_settings:
  master_key: sk-lit9501

Before (7b76b2b)

SDK upload then read with the bucket as a kwarg

  1. Ran the script above
  2. Output
UPLOAD OK: s3://litellm-lit4162-batch-439158074652/litellm-bedrock-files-anthropic.claude-3-haiku-20240307-v1-0-c71d50fe-ebc0-46ec-93c6-abdd20d83c8f.jsonl
CONTENT FAILED: ValueError S3 bucket_name is required. Set 's3_bucket_name' in proxy config or AWS_S3_BUCKET_NAME for Bedrock file content retrieval.

Proxy upload then read with the bucket in deployment config

  1. Not re-run at the merge base. This path reads the bucket from the deployment snapshot and already worked, which is what the After run below confirms is unchanged

After (7565016)

SDK upload then read with the bucket as a kwarg

  1. Ran the same script
  2. Output
UPLOAD OK: s3://litellm-lit4162-batch-439158074652/litellm-bedrock-files-anthropic.claude-3-haiku-20240307-v1-0-aeae4c01-d913-46c7-809e-1a249d8573d2.jsonl
CONTENT OK: b'{"recordId": "r1", "modelInput": {"messages": [{"role": "use'
  1. The object is really in S3
$ AWS_PROFILE=litellm-dev aws s3 ls s3://litellm-lit4162-batch-439158074652/ | grep -c aeae4c01
1

Proxy upload then read with the bucket in deployment config

  1. Upload
$ curl -s http://localhost:4931/v1/files -H "Authorization: Bearer sk-lit9501" -F purpose=batch -F model=bedrock-batch -F "file=@lit9501.jsonl"
{"id":"file-bGl0ZWxsbTpzMzovL2xpdGVsbG0tbGl0NDE2Mi1iYXRjaC00MzkxNTgwNzQ2NTIvbGl0ZWxsbS1iZWRyb2NrLWZpbGVzLWFudGhyb3BpYy5jbGF1ZGUtMy1oYWlrdS0yMDI0MDMwNy12MS0wLTMzNDNhZTdkLThkZDUtNGU5OS05NjNhLWVmOTMzOTQxYWViMC5qc29ubDttb2RlbCxiZWRyb2NrLWJhdGNo","bytes":174,"created_at":1792457473,"filename":"litellm-bedrock-files-anthropic.claude-3-haiku-20240307-v1-0-3343ae7d-8dd5-4e99-963a-ef933941aeb0.jsonl","object":"file","purpose":"batch","status":"uploaded","expires_at":null,"status_details":null}
  1. Read it back
$ curl -s -w "\nHTTP %{http_code}\n" http://localhost:4931/v1/files/$FID/content -H "Authorization: Bearer sk-lit9501"
{"recordId": "r1", "modelInput": {"messages": [{"role": "user", "content": [{"type": "text", "text": "hi"}]}], "max_tokens": 4096, "anthropic_version": "bedrock-2023-05-31"}}
HTTP 200
  1. A client trying to pick its own bucket is ignored and still gets the configured bucket's content
$ curl -s -w "\nHTTP %{http_code}\n" "http://localhost:4931/v1/files/$FID/content?s3_bucket_name=attacker-bucket" -H "Authorization: Bearer sk-lit9501"
{"recordId": "r1", "modelInput": {"messages": [{"role": "user", "content": [{"type": "text", "text": "hi"}]}], "max_toke
HTTP 200

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Proxy trust now hinges on the proxy_server_request stamp, which the proxy already strips from client bodies
  • s3_output_bucket_name gets the same SDK kwarg fallback for symmetry, not exercised live here
  • Pre-existing and separate: an SDK upload to the wrong region printed a success id while S3 answered with a redirect and stored nothing. Not touched by this PR

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

…content

A direct SDK call that passed s3_bucket_name as a kwarg lost it twice: the kwargs
allowlist dropped the key, and the Bedrock bucket lookup refused to read anything but
the proxy's deployment snapshot or AWS_S3_BUCKET_NAME. The lookup now also accepts the
caller's kwarg when the call did not enter through the proxy, decided by one shared
is_proxy_request helper keyed on the server-set proxy_server_request stamp. Proxy
requests keep resolving the bucket from deployment config or the environment only
@codspeed

codspeed Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing litellm_lit_9501_sdk_s3_bucket_name_kwarg (7565016) with main (b2eda10)

Open in CodSpeed

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ryan-crabbe-berri

Copy link
Copy Markdown
Contributor Author

Closing in favor of #47601, which fixes the same SDK bucket bug on top of the request-body bucket allowlist in #47496

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 file routing drops configured S3 endpoint and bucket parameters

1 participant