Repository navigation
fix(anthropic): route msgbatch_* IDs to batch results endpoint - #27998
Rana-Hassan7272 wants to merge 9 commits into
Conversation
Greptile SummaryFixes a routing bug where
Confidence Score: 4/5The change is narrowly scoped and only affects IDs that previously caused 404 errors, so it introduces no regression risk for normal file IDs. The routing logic is correct, the URL is constructed consistently with the rest of the file, and the new test exercises the changed branch without real network calls. The only finding is a minor single-quote vs double-quote inconsistency in the new line. No files require special attention; transformation.py is the only changed production file and the fix is a one-line guard.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/files/transformation.py | Adds a prefix guard in transform_file_content_request to route msgbatch_* IDs to the batch results endpoint instead of the files endpoint; logic is correct, minor quote-style inconsistency. |
| tests/test_litellm/llms/anthropic/files/test_anthropic_files_transformation.py | Adds a unit test for the new msgbatch_* routing branch; uses mocks only, covers the happy path for the new code. |
Reviews (1): Last reviewed commit: "fix(anthropic): route msgbatch_* IDs to ..." | Re-trigger Greptile
| # record 0 tokens and $0 cost for completed batches. | ||
| # Correct endpoint: /v1/messages/batches/{id}/results | ||
| # Ref: https://github.com/BerriAI/litellm/issues/27944 | ||
| if file_id and file_id.startswith('msgbatch_'): |
There was a problem hiding this comment.
Minor style inconsistency: the rest of the file uses double-quoted string literals, but the new
startswith check uses single quotes. Keeping the style uniform with the surrounding code makes diffs easier to read.
| if file_id and file_id.startswith('msgbatch_'): | |
| if file_id and file_id.startswith("msgbatch_"): |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 2 · PR risk: 0/10 |
_get_models_from_db ran find_many() with no ORDER BY, so the model list came back in Postgres' heap-scan order. Toggling a model rewrites its row under MVCC and clear_cache() rebuilds the router from a fresh unordered scan, so the toggled model jumps position and the UI list reshuffles on every reload; worse when a filter shows only a slice. Order by created_at then model_id so the order is stable regardless of updates.
Greptile flagged that ModelRepository.find_all() (and the paginated search fetch) still ran find_many() without an ORDER BY, so the reshuffle could resurface through those paths. The search fetch is worse: it applies take (LIMIT) with no order, so which rows land on a filtered page is itself non-deterministic and changes on every refresh. Centralize the order spec as MODEL_LIST_ORDER (created_at asc, model_id tie-break) and apply it to find_all and the paginated search fetch as well.
Resolves the UP006 strict-rule budget overflow that failed the lint CI check; List[Dict[str, str]] became list[dict[str, str]].
…_list_deterministic_order fix(proxy): load DB models in a deterministic order
|
Lets merge this if possible, we also need this PR |
…fix model_info fallback
Root cause 2: transform_file_content_response returned raw Anthropic JSONL
but calculate_batch_cost_and_usage expected OpenAI format. Added
_translate_anthropic_batch_item_to_openai() to convert Anthropic
{result.message.usage.input_tokens} to OpenAI {response.body.usage.prompt_tokens}.
Root cause 3: deployment_model_info fell back to {} (falsy) instead of None,
causing batch_cost_calculator to skip the global pricing table lookup.
Fixes BerriAI#27944
1415942 to
8d4cb39
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Hi, rebased onto litellm_oss_staging_06_06_2026 and all checks are green except OSV Scan (dependency scan on the lockfile; not introduced by this PR). Ready to merge when you have a moment. Fixes #27944 |
|
Fixed on main by #32307, which routes message batch results to the right endpoint and prices them. Reopen if something is still missing |
Summary
Fixes #27944
Root Causes Fixed
Root cause 1 — Wrong endpoint routing
transform_file_content_request routed msgbatch_* IDs to /v1/files/{id}/content
(Files API) which returns 404. Fixed by detecting msgbatch_* prefix and routing
to /v1/messages/batches/{id}/results.
Root cause 2 — Anthropic JSONL format not translated
Anthropic batch results use {result.message.usage.input_tokens} but cost/usage
helpers expect OpenAI format {response.body.usage.prompt_tokens}. Added
_translate_anthropic_batch_item_to_openai() to normalize before processing.
Root cause 3 — model_info={} short-circuits cost calculation
deployment_model_info fell back to {} instead of None, causing
batch_cost_calculator to skip global pricing table lookup entirely.
Testing