litellm/tests/test_litellm/llms/bedrock
Tim Elfrink c5eb22381d fix(bedrock): include cacheWriteInputTokens in prompt_tokens calculation
Fixes #15263

This PR fixes the cost calculation for Bedrock Anthropic models with prompt caching.

**Root Cause:**
PR #9838 incorrectly removed adding `cacheWriteInputTokens` to `prompt_tokens`
for Bedrock, based on the assumption that it would cause double counting (similar
to an Anthropic API issue). However, Bedrock's token structure is different:

- **Bedrock API**: `inputTokens`, `cacheReadInputTokens`, and `cacheWriteInputTokens`
  are ALL separate values that should be summed for total input tokens
- **Anthropic API**: Same structure - all three token types are separate

The fix in #9838 was later reverted for Anthropic (correctly re-adding
`cache_creation_input_tokens` to `prompt_tokens`), but Bedrock was never fixed.

**Changes:**
1. Re-add `cacheWriteInputTokens` to `input_tokens` in Bedrock transformation
2. Update test assertions to reflect correct behavior
3. Add regression test for prompt caching cost calculation
4. Fix typo in Anthropic transformation where `cache_creation_tokens` was
   incorrectly set to `cache_read_input_tokens`

**Testing:**
- All existing Bedrock transformation tests pass
- New test validates correct cost calculation with prompt caching
- Verified costs are non-negative and accurate
2025-10-07 20:28:46 +02:00
..
chat fix(bedrock): include cacheWriteInputTokens in prompt_tokens calculation 2025-10-07 20:28:46 +02:00
count_tokens Apply code formatting and linting fixes 2025-09-18 08:28:17 +02:00
embed test_twelvelabs_missing_input_type_error 2025-10-04 12:28:09 -07:00
files [Feat] Bedrock Batches - Ensure correct transformation applied to incoming requests (#14522) 2025-09-12 18:32:57 -07:00
image [Feat] Add inpainting support and corresponding tests for Amazon Nova Canvas (#12949) 2025-07-24 21:46:06 -07:00
invoke_agent fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00
messages/invoke_transformations Update Test for Anthropic Messages Configuration 2025-08-13 11:53:11 -07:00
passthrough fix: Support AWS_BEDROCK_RUNTIME_ENDPOINT on bedrock passthrough, make work for URLs with a base path 2025-09-01 17:47:26 -06:00
rerank Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
vector_stores [Feat] UI Vector Stores - Allow adding Vertex RAG Engine, OpenAI, Azure (#12752) 2025-07-18 18:25:26 -07:00
test_anthropic_beta_support.py Refactor Anthropic Configurations and Add Support for anthropic_beta Headers 2025-08-13 11:47:59 -07:00
test_base_aws_llm.py Add comprehensive tests for AWS external ID support 2025-09-15 19:56:31 +02:00
test_bedrock_common_utils.py Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
test_cross_region_inference_profile_mapping.py Fix: Bedrock cross-region inference profile cost calculation (#14566) 2025-09-15 07:10:20 -07:00