Skip to content

Add bedrock passthrough logging handler for cost tracking etc #11569

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 10 commits into from

Conversation

wreed4
Copy link

@wreed4 wreed4 commented Jun 10, 2025

Title

Relevant issues

Pre-Submission checklist

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

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • 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

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

Copy link

vercel bot commented Jun 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 6:19pm

@CLAassistant
Copy link

CLAassistant commented Jun 10, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for logging and cost tracking of Amazon Bedrock passthrough requests, integrates a new Bedrock handler, and updates routing and request plumbing.

  • Introduce BedrockPassthroughLoggingHandler to transform and log Bedrock responses
  • Extend pass-through routing (pass_through_request, llm_passthrough_endpoints, success_handler) to carry model info and invoke the Bedrock handler
  • Add comprehensive unit tests for Anthropic and Titan response formats under Bedrock

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/pass_through_unit_tests/test_bedrock_passthrough_logging.py New tests covering Anthropic, Titan, generic, cost, error and metadata behaviors
litellm/proxy/pass_through_endpoints/success_handler.py Import and wire up Bedrock handler and route detection logic
litellm/proxy/pass_through_endpoints/pass_through_endpoints.py Add model param to pass-through request signature and propagate to handlers
litellm/proxy/pass_through_endpoints/llm_provider_handlers/bedrock_passthrough_logging_handler.py Implement Bedrock response transformation & logging payload builder
litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py Extract model from Bedrock request body and pass into the pass-through plumbing
Comments suppressed due to low confidence (3)

litellm/proxy/pass_through_endpoints/pass_through_endpoints.py:487

  • The model parameter was added to pass_through_request but the function docstring and parameter description were not updated. Please document the new parameter to keep the signature and docs in sync.
model: Optional[str] = None,

tests/pass_through_unit_tests/test_bedrock_passthrough_logging.py:236

  • [nitpick] The generic Bedrock response test does not assert the finish_reason or usage fields; adding those assertions would ensure consistent behavior across all formats.
assert model_response.choices[0].message.content == "This is a generic response from Titan."

litellm/proxy/pass_through_endpoints/success_handler.py:47

  • The is_bedrock_route logic checks for substrings 'bedrock-runtime' in url_route, but url_route passed in is the path (e.g., '/model/.../invoke') so it never matches. Update the tracked patterns or matching logic to use the correct path segment.
self.TRACKED_BEDROCK_ROUTES = [

return metadata.get("user")

@staticmethod
def _should_log_request(kwargs: dict) -> bool:
Copy link
Preview

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

The helper _should_log_request is defined but never referenced. Consider removing it or integrating it into the handler flow to avoid dead code.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this @wreed4 ^

Copy link
Author

Choose a reason for hiding this comment

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

done

model = kwargs.get("model", "unknown")

# Get the appropriate Bedrock configuration
bedrock_config = ProviderConfigManager.get_provider_chat_config(
Copy link
Contributor

Choose a reason for hiding this comment

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

how will we know if it's a converse or invoke transformation?

Copy link
Contributor

Choose a reason for hiding this comment

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

i assume you need to check the url route and set this on the model - invoke/<model> or converse/<model>

Copy link
Author

Choose a reason for hiding this comment

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

good catch!

@@ -40,6 +43,12 @@ def __init__(self):
# Anthropic
self.TRACKED_ANTHROPIC_ROUTES = ["/messages"]

# Bedrock
self.TRACKED_BEDROCK_ROUTES = [
"bedrock-runtime",
Copy link
Contributor

Choose a reason for hiding this comment

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

we should be more precise here and say invoke and converse are supported - as the transformation in the bedrock_passthrough_logging_handler is configured for that.

@krrishdholakia
Copy link
Contributor

Closing as cost tracking via passthrough for bedrock is supported

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.

4 participants