litellm/tests/test_litellm/llms/anthropic
Mateo Wang 9076c33347
fix(batches): price anthropic passthrough message batches correctly in batch cost job (#32307)
* fix(batches): price anthropic passthrough message batches correctly in batch cost job

Anthropic message batches created via the /anthropic passthrough were never
cost tracked. The CheckBatchCost job fetched batch results from the Files API
(POST /v1/files/msgbatch_.../content), which Anthropic rejects with "File id
must have file_ prefix"; the error response was silently wrapped as file
content, parsed as zero successful rows, logged as a $0 aretrieve_batch spend
row, and the job was marked batch_processed=true so the $0 was permanent.

Route msgbatch_ file ids to GET /v1/messages/batches/{id}/results in the
anthropic files transformation, raise on HTTP error status in
retrieve_file_content instead of returning the error body as content, parse
Anthropic's results JSONL shape (result.type == "succeeded",
result.message.usage with cache creation/read tokens) in batch_utils, price
cache creation tokens at cache_creation_input_token_cost in the batch cost
fallback (50% batch discount preserved for base input, cache reads, cache
writes, and output), and leave the managed object row unprocessed when cost
tracking fails so a later poll retries instead of permanently recording $0.

* fix(batches): carry cache token details into aggregated anthropic batch usage
2026-07-06 20:33:57 -07:00
..
batches test(batches): add 1:1 test file scaffold for batches component paths (#30529) 2026-06-29 09:22:58 +05:30
chat feat: declarative fallback generalizations for unknown models (#29718) 2026-06-27 21:01:19 -07:00
experimental_pass_through fix(bedrock): emit SSE error event when invoke Messages stream ends without message_stop (#32159) 2026-07-04 17:49:40 -07:00
files fix(batches): price anthropic passthrough message batches correctly in batch cost job (#32307) 2026-07-06 20:33:57 -07:00
messages fix(anthropic): require caller api_key and SSRF-validate api_base in advisor tool (#32093) 2026-07-04 12:06:09 -07:00
__init__.py test(batches): add 1:1 test file scaffold for batches component paths (#30529) 2026-06-29 09:22:58 +05:30
test_anthropic_common_utils.py feat: declarative fallback generalizations for unknown models (#29718) 2026-06-27 21:01:19 -07:00
test_anthropic_count_tokens_transformation.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_anthropic_files_and_batches.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_anthropic_structured_output.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_azure_ai_cache_pricing.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_cost_calculation_dict_safety.py fix: completion_cost AttributeError on streaming Anthropic web_search responses (#26153) (#27346) 2026-06-10 21:20:11 -07:00
test_count_tokens_oauth.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_message_sanitization.py fix(anthropic, mcp): sanitize tool names to match Anthropic's [a-zA-Z0-9_-]{1,128} pattern (#26788) 2026-05-06 00:00:36 +00:00