Skip to content

fix(bedrock): preserve provider upload_url in sync create_file path#21628

Closed
Chesars wants to merge 1 commit intoBerriAI:mainfrom
Chesars:fix/bedrock-create-file-double-uuid
Closed

fix(bedrock): preserve provider upload_url in sync create_file path#21628
Chesars wants to merge 1 commit intoBerriAI:mainfrom
Chesars:fix/bedrock-create-file-double-uuid

Conversation

@Chesars
Copy link
Collaborator

@Chesars Chesars commented Feb 20, 2026

Relevant issues

Fixes #21546

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

Changes

The sync create_file path in llm_http_handler.py unconditionally overwrites litellm_params["upload_url"] with api_base (line 3018). For Bedrock, get_complete_file_url generates a new uuid.uuid4() on each call, so api_base (from the first call) and the URL used for the actual S3 upload (from the second call inside transform_create_file_request) contain different UUIDs. The file is uploaded to the correct key (UUID-2) but the returned file_id points to the stale key (UUID-1).

The fix adds a guard so api_base is only used as a fallback when the provider has not already set upload_url in litellm_params. This preserves the correct URL that Bedrock writes at bedrock/files/transformation.py:370.

The sync create_file path unconditionally overwrote
litellm_params["upload_url"] with api_base, discarding the correct URL
set by Bedrock's transform_create_file_request. This caused the returned
file_id to point to a different S3 key than the one the file was
actually uploaded to, because get_complete_file_url generates a new UUID
on each call.

Add a guard so api_base is only used as fallback when the provider has
not already set upload_url.

Fixes BerriAI#21546
@vercel
Copy link

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 20, 2026 0:33am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 20, 2026

Greptile Summary

Fixed a UUID mismatch bug in Bedrock's sync create_file path where api_base (containing UUID-1 from initial get_complete_file_url call) unconditionally overwrote the provider's correctly-set upload_url (containing UUID-2 from transform_create_file_request). This caused files to upload to the correct S3 key but return a file_id pointing to a stale, non-existent key.

Key Changes:

  • Modified llm_http_handler.py:3018 to conditionally set upload_url only when not already present in litellm_params
  • Added comprehensive regression test with mocked Bedrock flow verifying the fix
  • Preserves Bedrock's pattern where transform_create_file_request generates fresh UUIDs and sets litellm_params["upload_url"] at bedrock/files/transformation.py:370

Note: The async path (async_create_file) was not affected by this bug as it correctly passes litellm_params directly without modification.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix is minimal (2-line guard condition), surgically targeted to the specific bug, and includes a comprehensive regression test that validates the exact issue described in [Bug]: litellm.create_file for Bedrock returns a file_id pointing to the wrong S3 key (double UUID generation) #21546. The change only affects the sync path which had the bug, while the async path correctly handled this scenario already. The test uses proper mocking to verify the provider's upload_url is preserved through the entire flow.
  • No files require special attention

Important Files Changed

Filename Overview
litellm/llms/custom_httpx/llm_http_handler.py Added conditional check to preserve provider-set upload_url instead of unconditionally overwriting with api_base
tests/test_litellm/llms/bedrock/files/test_bedrock_files_integration.py Added regression test verifying sync create_file preserves provider's upload_url from litellm_params

Sequence Diagram

sequenceDiagram
    participant Client
    participant HTTPHandler
    participant BedrockTransform
    participant S3

    Note over Client,S3: Before Fix: UUID Mismatch Bug
    Client->>HTTPHandler: create_file(sync)
    HTTPHandler->>BedrockTransform: get_complete_file_url()
    BedrockTransform-->>HTTPHandler: api_base (UUID-1)
    HTTPHandler->>BedrockTransform: transform_create_file_request()
    BedrockTransform->>BedrockTransform: generate new UUID-2
    BedrockTransform->>BedrockTransform: set litellm_params["upload_url"] = UUID-2
    BedrockTransform-->>HTTPHandler: presigned request (UUID-2)
    HTTPHandler->>S3: PUT to UUID-2 ✓
    HTTPHandler->>HTTPHandler: OVERWRITES upload_url = api_base (UUID-1) ✗
    HTTPHandler->>BedrockTransform: transform_create_file_response(UUID-1)
    BedrockTransform-->>Client: file_id points to UUID-1 (wrong!)

    Note over Client,S3: After Fix: UUID Preserved
    Client->>HTTPHandler: create_file(sync)
    HTTPHandler->>BedrockTransform: get_complete_file_url()
    BedrockTransform-->>HTTPHandler: api_base (UUID-1)
    HTTPHandler->>BedrockTransform: transform_create_file_request()
    BedrockTransform->>BedrockTransform: generate new UUID-2
    BedrockTransform->>BedrockTransform: set litellm_params["upload_url"] = UUID-2
    BedrockTransform-->>HTTPHandler: presigned request (UUID-2)
    HTTPHandler->>S3: PUT to UUID-2 ✓
    HTTPHandler->>HTTPHandler: preserves upload_url = UUID-2 ✓
    HTTPHandler->>BedrockTransform: transform_create_file_response(UUID-2)
    BedrockTransform-->>Client: file_id points to UUID-2 (correct!)
Loading

Last reviewed commit: abe7eb6

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@Chesars
Copy link
Collaborator Author

Chesars commented Feb 26, 2026

Closing as superseded by #21650.

@Chesars Chesars closed this Feb 26, 2026
@Chesars Chesars deleted the fix/bedrock-create-file-double-uuid branch February 26, 2026 19:36
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]: litellm.create_file for Bedrock returns a file_id pointing to the wrong S3 key (double UUID generation)

1 participant