Repository navigation
fix(proxy): classify /v1/messages pass-through streams as Anthropic on any host - #45602
Conversation
…n any host Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
… provider package Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a975c14. Configure here.
TLDR
Problem this solves:
integrationjobs onmainfail every scheduled CircleCI run/anthropic/v1/messagescalls through a non-Anthropic host log 0 tokens and $0/v1/messagescache hits withoutx-litellm-cache-keyHow it solves it:
/v1/messagesas Anthropic, viais_anthropic_messages_urlin the Anthropic package/v1/messagesincluded, returns a 64-hexx-litellm-cache-keyUser Flow
Before: a team that points
ANTHROPIC_API_BASEat their own gateway sees every streamed call logged at $0ANTHROPIC_API_BASE=https://gateway.internaland restarts the proxy"stream": trueAfter: the same streamed call is logged with real usage, cost and the provider's
msg_...idANTHROPIC_API_BASE=https://gateway.internaland restarts the proxy"stream": truemsg_...idRelevant issues
Related #40117. Overlaps the Anthropic half of #40137 by @Sunny-Soni00 (idle since 2026-10-08, conflicting with
main); credit is carried as a co-author on the squash commitCircleCI failures on main
Red scheduled
integrationworkflow onmain: pipeline 91062, also red in pipeline 91070 (workflow)integration-providersjob 2252899:tests/integration/messages_endpoint/providers/anthropic/test_passthrough_migration_wire.py::test_native_passthrough_spend_rows_record_usage_tags_and_spendget_endpoint_typehas matched only theapi.anthropic.comhost since c107bae ((feat) add usage / cost tracking for Anthropic passthrough routes #6835, 2024). The test added by 0e26edf (test: move 81 legacy live tests in pass-through, spend, batches, audio, search, guardrails, image and ocr dirs offline #45288) is the first to stream through a non-Anthropic host, and it fails at its own merge and baseGENERIC, skips the Anthropic chunk logger,response_obj.idstays empty and the spend row falls back tolitellm_call_idwith 0 tokensintegration-extensionsjob 2252896:tests/integration/observability/test_arize_otel_v2_openinference_spans.py::test_arize_otel_v2_a_cache[messages]refactor: expose public hidden_params accessors), whose "keep hidden params writes on duck-typed responses" change lets the cache-hitcache_keyland on dict/v1/messagesresponses. Bisected: bce020f passes, d364d5e failsDeferred to a later run (covered by #45530 or not yet root-caused), all red on
maintoo:llm_translation_testingxAI reasoning effort,integration-accounting(red onmainin each of the last 13 scheduled runs; Vertex image regional uplift chaos),integration-providersBedrock Mantle and OpenAI dialect prompt-cache breakpoint tests,test_decisions_wire, worker-kill chaos tests, Redis usage-based routing reads. Worker-kill teststest_daily_activity_key_owner_faults,test_daily_activity_key_metadata_query_timeoutandtest_responses_websocket_session_limitfailed once on this pipeline and passed twice each locally at the tip; they never touch pass-through routingPre-Submission checklist
Screenshots / Proof of Fix
CircleCI on this branch: pipeline 91073 at
a975c14388(supersedes 91072).integration-extensionsjob 2253346 passed with all fourtest_arize_otel_v2_a_cachesurfaces green.integration-providersjob 2253353 no longer failstest_native_passthrough_spend_rows_record_usage_tags_and_spend; the job stays red on the deferred tests below, as onmain. Everybuild_and_testjob passedLive proxy against the real Anthropic API.
ANTHROPIC_API_BASEpoints at a local relay on127.0.0.1that forwards every byte tohttps://api.anthropic.com, standing in for a corporate gateway. Spend rows read fromLiteLLM_SpendLogsBefore (63a4f3f)
Streamed /anthropic/v1/messages
"stream": truereturns 200, stream idmsg_011Cfrt69zdLqgRc3jxwYG4v93515cee-158e-46f3-8fb2-de8b480527cf, 0 prompt / 0 completion tokens, spend 0, provider emptyNon-streamed /anthropic/v1/messages
streamreturns 200, idmsg_011Cfrt7SNQKm2MZSfefd2J7msg_011Cfrt7SNQKm2MZSfefd2J7, 12 / 4 tokens, spend 3.2e-05Streamed custom pass-through endpoint targeting /v1/messages
"stream": truereturns 200, stream idmsg_011CfrtAkYdRKusAPB55NcvU09b8d854-8edc-424f-9f3c-1edd1329a719, 0 / 0 tokens, spend 0After (a975c14)
Streamed /anthropic/v1/messages
"stream": truereturns 200, stream idmsg_011CfruEVk7iZTBcWjddMRwbmsg_011CfruEVk7iZTBcWjddMRwb, 12 prompt / 4 completion tokens, spend 3.2e-05, provideranthropicNon-streamed /anthropic/v1/messages
streamreturns 200, idmsg_011CfruF9cBhK4XZUzh4xHESmsg_011CfruF9cBhK4XZUzh4xHES, 12 / 4 tokens, spend 3.2e-05 (unchanged)Streamed custom pass-through endpoint targeting /v1/messages
"stream": truereturns 200, stream idmsg_011CfruFbRChdst7Zrn3wqTwmsg_011CfruFbRChdst7Zrn3wqTw, 12 / 4 tokens, spend 3.2e-05/anthropic/v1/messages/count_tokensreturned 200{"input_tokens":12}on both revisions. The Arize change is test-only; its proof isintegration-extensionspassing in the pipeline aboveType
Bug Fix
Test
Caveats (if any)
Low
/v1/messagesnow use the Anthropic stream loggerFinal Attestation
The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
a975c14 passes /live-pr-risk