Repository navigation
fix(decisions): support the litellm_proxy provider (#51611, #53195) [lts/1.108.x] - #53196
Conversation
Backport of BerriAI#51611 to lts/1.108.x. Cherry-picked from 8f651ba (litellm_decisions_litellm_proxy). Adapted to the line: lts/1.108.x registers lazy imports in its tuple-and-map registry and resolves decisions configs with per-provider ifs, and the test file gains main's single-answer predicate fixture.
Pass the per-call use_litellm_proxy flag into provider resolution so a router deployment flagged for the proxy sends Decisions to the proxy with its own key, and pin that litellm_proxy never falls back to OpenAI's base or key. (cherry picked from commit db2afb5)
…uestions to the proxy The proxy's /v1/decisions accepts audio and videos and checks each model's capabilities itself, so the litellm_proxy config forwards them and box questions instead of refusing them in the SDK. A deployment that sets one of these flags to false is still refused locally. Adapted for lts/1.108.x, where the audio and video support hooks take no per-deployment flag, so a litellm_proxy call always forwards them and only box questions can be turned off per deployment. (cherry picked from commit d1fa55b1acfaf8971846560bf5920e9ec6b92e5d)
…ll the proxy's cost A systemone call now goes to the proxy's /v1/systemone unchanged, assets and criteria included, and a decisions call keeps going to /v1/decisions. The call's cost comes from the proxy's x-litellm-response-cost header, and the missing-key error names LITELLM_PROXY_API_KEY. On the proxy, use_litellm_proxy stays a deployment setting that a request body cannot set This line's cost lookup keeps any float a provider reports, so the pick itself drops a negative, NaN or infinite header and the call falls back to the model price, as main's cost lookup already does (cherry picked from commit c6f2379abe53ca80f221aa99abdbb941efd24962)
…calls The proxy's /v1/systemone accepts safety_identifier, so the systemone hop now sends it instead of refusing the call or dropping the field under drop_params (cherry picked from commit 787aa1cc33c2ca3b756bdf24d34b7214734061f3)
…images A proxied call with no usable cost header now has to bill the same model price a direct call bills, a zero cost header has to bill zero, and the systemone call has to forward its images (cherry picked from commit 7c0892dbd2d5b36d814155531e4e76ab54358f0e)
The decisions endpoints already drop use_litellm_proxy and model_info from the top level of a request body, since both are deployment settings. Fallback targets in the body now drop them too, in fallbacks, context_window_fallbacks, content_policy_fallbacks and the same lists under router_settings_override, so only deployment config turns the flag on (cherry picked from commit e84aac682fe0920e54d189d2bf3599372cda8952)
…and allow a keyless proxy Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit abcbd7a)
A proxied decisions or systemone call with drop_params still failed when the proxy's deployment could not take safety_identifier, since the flag stayed on the client. The call now sends drop_params: true to the proxy, which drops what the deployment it picks cannot take (cherry picked from commit ecc0180)
… key message The hop sets api_key_required to False, which gates the only caller of missing_api_key_message, so the override never ran (cherry picked from commit be5486c)
… hop A proxy-wide or SDK-wide drop_params went to the upstream proxy on every hop call, so an upstream that is not a LiteLLM proxy refused the unknown parameter. The hop now gets drop_params only when the caller set it on that call, and the global setting stays on the client the way chat through litellm_proxy keeps it (cherry picked from commit f09d530)
[Medium impact] The reviewed changes appear safe to merge
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
The proxy already checked each answer against its own deployment's provider, so a Parallel AI choice or score answer with no confidence now reaches the caller instead of failing after the proxy billed it This line also gains main's optional-confidence check from BerriAI#49188, which the pick needs. A choice or score answer may now carry no confidence, every provider other than the litellm_proxy hop still answers 500 when it is missing, and the complexity router and the Playground leave the confidence out instead of failing (cherry picked from commit 350afdffcfa4d9a4e1b315a5cc56bb0eb962af9c) (cherry picked from commit 43da8f6)
|
bugbot run |
Bugbot is paused — your team has an unpaid invoiceBugbot is paused because your team has an unpaid invoice. Pay it from the billing page in the Cursor dashboard and Bugbot resumes automatically. (requestId: c0a95eb2-295d-4b0c-be77-25d043a44672) |
|
bugbot run |
Bugbot is paused — your team has an unpaid invoiceBugbot is paused because your team has an unpaid invoice. Pay it from the billing page in the Cursor dashboard and Bugbot resumes automatically. (requestId: 58528733-7e49-4d23-a719-2fa7624e12af) |
|
bugbot run |
Bugbot is paused — your team has an unpaid invoiceBugbot is paused because your team has an unpaid invoice. Pay it from the billing page in the Cursor dashboard and Bugbot resumes automatically. (requestId: 6cc5edb2-cb09-48f2-ba5a-e290daba4088) |
|
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 0f4d1f3. Configure here.
Backport of #51611 and its follow-up #53195 to the 1.108 LTS line. Decision calls from an SDK app that sends its traffic through a LiteLLM proxy failed or went to OpenAI. Now they reach the proxy's
/v1/decisions, alitellm.asystemonecall goes to its/v1/systemone, and each call bills the cost the proxy reportsOriginal
TLDR
Problem this solves:
litellm.use_litellm_proxyis onlitellm_proxy/...modeluse_litellm_proxy: truesends decisions to OpenAIHow it solves it:
litellm_proxydecisions config sends decisions to the proxy's/v1/decisionswith its URL and keyuse_litellm_proxyflag countslitellm.systemonecalls go to the proxy's own/v1/systemoneunchangedx-litellm-response-costuse_litellm_proxy, fallback targets includeddrop_paramsgoes to the proxy tooconfidencereaches the callerUser Flow
Before: an SDK app that sends all its calls through a LiteLLM proxy cannot make decision calls
litellm.use_litellm_proxy = True,LITELLM_PROXY_API_BASEandLITELLM_PROXY_API_KEYlitellm.acompletion(model="openai/gpt-6-luna", ...)reaches the proxy and answerslitellm.adecisions(model="openai/gpt-6-luna", ...)raisesBadRequestError: Unknown Decisions provider 'litellm_proxy', and so does alitellm_proxy/...modeluse_litellm_proxy: truesends its decision call to api.openai.com instead, which answers 401After: the same decision calls go through the proxy
litellm.use_litellm_proxy = True,LITELLM_PROXY_API_BASEandLITELLM_PROXY_API_KEYlitellm.adecisions(model="openai/gpt-6-luna", ...)sends POST<LITELLM_PROXY_API_BASE>/v1/decisionswith the proxy key and returns the proxy's answers, and so does alitellm_proxy/...modellitellm.asystemone(model="litellm_proxy/gemini/gemini-decision-1", ...)sends POST<LITELLM_PROXY_API_BASE>/v1/systemoneand returns the proxy's answers with theirconfidenceresponse._hidden_params["response_cost"]matches thex-litellm-response-costthe proxy billedRelevant issues
Backport of #51611 and #53195, the fixes #51611 merged without, each picked with
git cherry-pick -x. Five trailers name local copies that were never pushed, so the table maps each to its main commit. bbbb829, 20f7864 and 0f67db8 only merge mainHow the picks differ from main
The db2afb5 pick adds and removes the same lines as on main. The 8f651ba pick registers the new config in this line's tuple-and-map lazy import registry and resolves it with the line's per-provider
if, and its test file gains main's single-answer predicate fixture. Main's abcbd7a maps to two commits here. 370e7ca picks d1fa55b1ac, the fix abcbd7a replaced on main, and forwards box questions, audio and videos to the proxy. 4641a68 picks abcbd7a and keeps only its keyless proxy, because this line'ssupports_audio_inputandsupports_video_inputtake no per-deployment flag. So the litellm_proxy config always forwards audio and videos, only box questions can be turned off per deployment, and the refusal test covers box questions only. The 57fb1db pick is adapted because this line has no extra-field passthrough for decisions responses, so it leaves out main's evidence fields, and because this line's cost lookup keeps any float a provider reports. So the pick drops a negative, NaN or infinite cost header itself and the call bills the model price, which main's cost lookup already does. Its audio and video support checks keep this line's signature. The 43da8f6 pick is adapted because this line's answer types requiredconfidence. 0f4d1f3 also brings main's optional-confidence check from #49188, so only thelitellm_proxyconfig passes on a choice or score answer with no confidence, which a newer proxy that routes to Parallel AI sends, and every other decisions provider still answers 500 on one. The complexity router's own TypeSafe classifier takes an answer with no confidence, as on main. The f86f2e2 pick is adapted only because this line's_request_datatakes noapi_nameand its endpoint has no extraction route. The ecc0180 pick is adapted only because this line's decisions call has no prompt cache breakpoint step for the flag to pass through. Main's b828c1b has no pick, because this line has no Gemini decisions config, so there is no Gemini systemone answer to name the model onPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Last updated: 0f4d1f3
SDK cases through a live far proxy at b828c1b. Before, each one fails without reaching the hop
5f1b6e4cca0f4d1f3f5bboxsentsafety_identifiersentdrop_paramssentclient.py,parallel_predicate.pyand the transcripts are in the gist, for GitHub's size capFull SDK table, config, scripts and commands
The rig ran on a local macOS laptop, with one FAR proxy at main PR #53195's head
b828c1b63band a keyless FAR2 from the same tree, each on--num_workers 2 --reloadwith two workers serving (no"workers" flag is ignoredwarning, both worker PIDs on the listener) and one shared Redis with no database, recorders in front of OpenAI, Gemini, TypeSafe and both proxies, and every SDK leg on the AFTER tree's venv withPYTHONPATHset to its own tree5f1b6e4cca0f4d1f3f5bb020078055boxsafety_identifier1.71e-05on both calls0.0171drop_params: truedrop_params, Gemini call 400Every BEFORE case failed before any request reached HOP_WIRE or a provider recorder, and its recorder lines are empty. Every AFTER case reached HOP_WIRE (HOP2_WIRE for the keyless cases) with the body the caller sent, and the hop lines show the audio, video,
box,safety_identifieranddrop_paramsvalues listed above. The fourGET /v1/modelslines with a 401 inside keyless-flag come from the proxies themselves, since the SDK has no OPENAI_WIRE addressThree rows did not match what this run expected. The parallel rows answer with a confidence on both AFTER and PRE-PORT because Parallel's API now returns
confidenceon choice answers, so the no-confidence answer that0f4d1f3f5bhandles never came up and this run does not exercise it live. Called directly, Parallel also returns a confidence on a score answer but none on a predicate (noul) answer (last block). The parallel-predicate row sent that predicate through the hop, and PRE-PORT answered it with no 500. The predicate answer type has no confidence field, and the check0f4d1f3f5badds covers only choice and score answers, so a predicate never reached it on either commit. In global-drop the SDK left the globallitellm.drop_paramsout of the hop body as designed, and the FAR proxy, which sets nodrop_paramsof its own, answered the Gemini systemone call with a 400 because Gemini does not takesafety_identifier. The OpenAI decision call in that case answered. Both results were the same on an earlier full boot, so they are not flakesEverything here comes from the second full boot. On the first, FAR2 still had
LITELLM_MASTER_KEYin its environment and the proxy reads that variable as its master key, so both keyless calls got a 401. Main also refuses to boot with no master key unlessLITELLM_DANGEROUSLY_PERMIT_WEAK_OR_UNSET_MASTER_KEY=trueis set, so FAR2 now runs with that variable and withoutLITELLM_MASTER_KEY. Every other row matched across both boots. The parallel-predicate row ran later on its own fresh boot of the same rig, and PRE-PORT gave the same answer on one more fresh bootdrop_paramsstays local by this PR's designconfig.yaml (FAR) and config-keyless.yaml (FAR2)
config.yamlis the earlier proof's config with thecloudflare/clairicentry dropped.config-keyless.yamlis the same file without thegeneral_settings.master_keylinekeyless.py and recorder.py
keyless.pyisclient.py'sprefixandflagcases with theLITELLM_PROXY_API_KEYread removedRig commands and env var names, as run
The proxies get only the variables named after
clean_exec, which unsets every other exported variable exceptHOMEandPATH.PYTHON_DOTENV_DISABLED=1keeps every process from loading a tree's.env, so the SDK legs see onlyLITELLM_PROXY_API_BASE,LITELLM_PROXY_API_KEYand the fakeOPENAI_API_KEY, and the keyless legs see noLITELLM_PROXY_API_KEYat all. Every port came from a random pick in 20000-32767 checked free withlsof -nP -iTCP:<port> -sTCP:LISTENPRE-PORT transcript, commit b020078
Parallel called directly with choice, score and predicate questions
In the b020078 smoke, a proxy-wide
drop_paramsreached the hop and OpenAI answered 400 before, and 200 afterSmoke table, config and commands
Live smoke on lts/1.108.x for
/v1/decisionsand/v1/systemoneBoth legs ran at the same time on a macOS laptop (18 cores), each with its own Redis, proxy and two forwarding recorders, and each proxy printed
"workers" flag is ignored when reloading is enabled, so each leg served from one uvicorn worker and the two-worker check was dropped.96524beb69b020078055drop_paramsat OpenAItruedrop_paramsat hop, proxy-wide settingtruedrop_paramsat hop, proxy-wide settingtruedrop_paramsat hop, per-call settingtruetruedrop_paramsat hop, per-call settingtruetrueRequests 2 and 3 end in a 400 on both legs because this LTS line has no Gemini decisions provider, so the hop proxy answers
Unknown Decisions provider 'gemini'. Requests 2b and 3b send the same calls through a hop to OpenAIgpt-6-lunaand answer 200 on both legs. The before leg's 2b still answers 200 because the hop is a LiteLLM proxy, which acceptsdrop_params, so only an upstream that is not a LiteLLM proxy (request 1) refuses it. Requests 2b and 3b ran on a second fresh boot of both legs, with thechained-lunaandopenai/gpt-6-lunaentries added to the config.Headline, request 1 (
/v1/decisionsthrough alitellm_proxy/deployment that points at OpenAI)Before, at
96524beb69After, at
b020078055Rig
Each leg ran the proxy from its own tree with the after tree's
.venv/bin/pythonandPYTHONPATHset to that tree, and each leg printedlitellm.__file__from its own tree. Both trees were clean (git status --porcelainempty) and at the stated commit before boot. The after tree has a bootstrap.envthat carries a database URL, so both legs setPYTHON_DOTENV_DISABLED=1and took every value from the shell, and both boot logs showprisma_client: None.96524beb69b020078055The env var names are the same on both legs.
OPENAI_API_KEYandGEMINI_API_KEYcome from the main checkout's.envthroughdotenv-get,LITELLM_MASTER_KEYis a randomsk-value per boot, andOPENAI_WIREandHOP_WIREpoint at the leg's recorders. The rest arePYTHON_DOTENV_DISABLED=1,LITELLM_LOCAL_MODEL_COST_MAP=TrueandPYTHONPATH=<leg tree>, withDATABASE_URL,OPENAI_BASE_URLandTIMEOUT_WORKER_HEALTHCHECKunset.Commands per leg, the proxy run from the leg's tree
Config, the same on both legs apart from the Redis port. The
chained-lunaandopenai/gpt-6-lunaentries were added for the second boot that ran 2b and 3bRequests, sent 8 seconds apart on each leg
Recorder script, which forwards each request unchanged and logs the path, sorted body keys and
drop_params, never headersLeg runner script, exactly as run
Observations
--num_workers 2under--reload, one worker servedThe ba799a9 proxy flag cases still hold, as its proxy file is unchanged
Proxy flag cases
The proxy flag cases boot this line's proxy itself, once per tree, with
--num_workers 2and no database. body-flag sendsuse_litellm_proxy: trueat the top level of a/v1/decisionsbody, and fallback-flag puts it in a request-body fallback target of a deployment with a bad OpenAI key. Both calls reach real OpenAIBefore (5f1b6e4)
body-flag
fallback-flag
After (ba799a9)
body-flag
fallback-flag
At 0f4d1f3, 81 decisions test files (15960 tests), the Playground tests (154) and
make checkpass. Without the picks, the new tests fail/gauntlet-mini came back PARTIAL, and c0a4c2f and 7eaeba7 fix both findings
grype flags dnspython, filelock, pillow, soupsieve, tornado and diskcache in
uv.lock. Main has the first five, and diskcache has no fixed releaseType
🐛 Bug Fix
Caveats (if any)
Copied from #51611 and #53195, re-read against this line
Medium
/v1/decisionsalso needs/v1/systemonefor proxied systemone calls and decisions health checks"confidence": null, as on mainLow
imagesunlessdrop_paramsis setlitellm.adecisionsreturns no extra fields likedecision_idon this linedrop_paramsreaches the next proxydrop_paramslitellm_proxydeployment needs a LiteLLM proxy as itsapi_basedrop_paramswith 400asystemoneuse_litellm_proxylike"true"passes the router's proxy checks, but the call goes to the provider, as on mainDecisions
api_keyorLITELLM_PROXY_API_KEY, so an OpenAI key is never sent to another host, and with neither set the call goes out with no authorization header. Chat's fallback toOPENAI_API_KEYandlitellm.api_keywas the alternative/v1/decisionsand a systemone call to its/v1/systemone, each in the caller's shape. One endpoint for both was the alternative, but/v1/decisionsflattens systemone criteria and refuses assets, and a systemone body has no prompt cache fieldsuse_litellm_proxycounts only when it is the booleanTrue. Lax coercion was the alternative, but it takes"yes"and raises on other strings mid-callsafety_identifiergoes to the proxy even when the client setsdrop_params, and the call also sends the caller'sdrop_params, so the proxy drops it only for a deployment that cannot take it. Dropping it on the client was the alternative, but the client cannot tell which deployment the proxy picksx-litellm-response-costheader, the cost comes from the cost map, rather than logging nonedrop_paramsmeans only the per-call flag. Also sending the globallitellm.drop_paramsor the proxy's own setting was the alternative, but then alitellm_proxydeployment whoseapi_baseis not a LiteLLM proxy failed every call with 400use_litellm_proxyormodel_infoin a decisions request body, at the top level or in a fallback target, is dropped, so the call runs as it did before this PR. Answering 400 was the alternative, but it would fail requests that workedFinal Attestation
Bugbot summary