Repository navigation
feat(sdk): consume proxy-advertised request-parameter capabilities - #5502
Conversation
Keep litellm_params.allowed_openai_params from the matching LiteLLM proxy /v1/model/info entries (intersected across deployments) in the returned model_info, and let an advertised param enable exactly the capability that is that request param: reasoning_effort, prompt_cache_key, or prompt_cache_retention. Explicit capability overrides still win; absence from the list is not treated as a denial, so existing fallbacks are unchanged. Fixes #5499 Co-authored-by: openhands <openhands@all-hands.dev>
Temporary PR artifacts under .pr/; removed on approval. Co-authored-by: openhands <openhands@all-hands.dev>
|
🧹 PR Artifact Cleanup Queued The |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: In scope. The change lives entirely in openhands-sdk/openhands/sdk/llm/utils/ (capability resolution for LiteLLM proxy models), which this repository owns. No model or provider names are hard-coded, and discovery stays optional, matching the non-goals in #5499.
Verification on head 88249e4:
- Current-head CI is green (
sdk-tests,tools-tests,agent-server-tests,cross-tests,windows-tests,pre-commit,security, and all build/publish checks). uv run pytest tests/sdk/llm/test_model_info_proxy_lookup.py tests/sdk/llm/test_model_features.py -q-> 238 passed, 3 failed. The 3 failures (test_reasoning_effort_supportforopenrouter/moonshotai/kimi-k2.5,openrouter/moonshotai/kimi-k2-thinking,openrouter/deepseek/deepseek-r1) also fail on the PR's merge-base7999acfain this environment; they are pre-existing route-dependent expectations, not a regression from this PR. Currentmainhas already rewritten those cases to follow LiteLLM's livesupported_openai_params(#4877 follow-up), so merging an updated branch picks up the corrected test.- Traced the full path:
litellm_params.allowed_openai_params-> intersection across matching deployments ->model_info->get_featuresvia_resolved_bool->select_chat_options. Overrides still win; the advertised-param check only affects the three request-param capabilities, so vision/prompt-cache/thinking cannot be enabled through it (negative tests assert this). - Compatibility: the new
allowed_openai_paramskey lands inLLM._model_info, a private attribute that is not serialized or persisted;_register_proxy_alias_pricingcopies only_PRICING_FIELDS, so nothing leaks intomodel_cost. Malformedlitellm_params/param values degrade to absent, and the existing try/except fallback path is unchanged.
Acceptance criteria (#5499): all addressed - authoritative metadata without hardcoding, safe degradation on 401/500/invalid-JSON/malformed payloads (tested against a real local HTTP server through the actual LLM -> features -> chat-options path), no unrelated capability enablement, and documentation of the field's contract status. The issue now carries ready-for-dev.
Non-blocking notes for the maintainer:
- Upstream LiteLLM issue not yet filed: the drafted issue exists at
.pr/proxy-request-params/litellm-upstream-issue.md, but filing againstBerriAI/litellmreturned 403 for the bot token. A maintainer needs to open it and link it, completing the final acceptance criterion. - Live authenticated proxy run not performed: evidence uses a faithful fixture proxy (real HTTP, Bearer auth, the exact redacted entry from #5499) plus the unauthenticated live 401 run; the limitation is disclosed with the exact command (
LLM_API_KEY=... uv run python .pr/proxy-request-params/repro.py --base-url https://llm-proxy.app.all-hands.dev). Worth a lightweight confirmation against the managed proxy before or shortly after merge. - Branch age: the PR is based on
7999acfa;mainhas since touchedmodel_features.py(no conflicts per GitHub,mergeable: true). Updating the branch before merge will also inherit main's rewritten route-following reasoning-effort tests.
No material correctness, security, or compatibility findings on the current head.
✅ APPROVED
Resolve llm capability conflicts additively: keep this PR's consolidated capability resolver and provenance, graft main's proxy-advertised request-param support (#5502, allowed_openai_params) on top, and union-merge the proxy lookup / model features tests. Advertised params enable exactly their capability; generic supports_reasoning alone still does not authorize reasoning_effort under this PR's resolver. Co-authored-by: openhands <openhands@all-hands.dev>
HUMAN:
I read the code and am satisfied by the agent's testing. Merging in.
AGENT:
Why
_get_model_info_from_litellm_proxy()returned onlycurrent["model_info"]. That droppedlitellm_params.allowed_openai_params, which is how a LiteLLM proxy deployment declares which extra request params it forwards upstream. Because of this, the SDK could not learn from proxy metadata that an alias acceptsreasoning_effort. It had to rely on the genericsupports_reasoningflag, the static LiteLLM registry, or model-name lists.Summary
model_info.py): when a/v1/model/infoentry matches, copyallowed_openai_paramsinto the returnedmodel_info. If several deployments match the alias, keep only the params that all of them allow, since the proxy can route to any of them. Non-list values and non-string items are ignored. Nothing else fromlitellm_paramsis kept.model_features.py): an advertised param can enable only the capability that is that request param:reasoning_effort→supports_reasoning_effortprompt_cache_key→supports_prompt_cache_keyprompt_cache_retention→supports_prompt_cache_retentioncapability_overrideswin, then an advertised param, then existing metadata, then fallbacks. A param missing from the list is not treated as a denial, because LiteLLM uses the list only to extend the provider's native params. Vision, prompt caching (cache_control), thinking mode, and other capabilities are never derived from the list.Issue Number
Fixes #5499
How to Test
Base:
7999acfadc0a163186f5a8025ffda0de8e351c34(main).Head:
45259c484a9b37d79c73a10cb457b076a9395fb3(code and tests) +88249e4(.pr/evidence only).Reproducer
.pr/proxy-request-params/repro.pycalls/v1/model/infowith a Bearer key and buildsLLM(model="litellm_proxy/deepseek-v4.1-flash", reasoning_effort="low"). It then prints only:allowed_openai_params/supports_reasoningmodel_infoModelFeaturesfields that the advertised params changereasoning_effortappears in the chat requestIt never prints the credential or any other catalog entry.
--fixtureserves the redacted entry quoted in #5499 from an in-process proxy that returns 401 without the right Bearer key.Before (base source; full log:
before.txt):After (head
45259c4; full log:after.txt):Reading the output:
supports_reasoning_effortis true only because of the genericsupports_reasoningflag (the concern in SDK sends unsupported reasoning_effort to MiniMax M3 #4934).supports_reasoning_efforton its own. It changes no otherModelFeaturesfield.supports_prompt_cache_key: trueappears both before and after, and does not come from this change. The [Bug]: Native LLM spans recordgen_ai.usage.cost = 0.0for customlitellm_proxy/*model names #4816 alias-pricing registration maps the alias to the underlyingopenrouter/…entry, and LiteLLM's OpenRouter param set includesprompt_cache_key. The "features changed" line shows the advertised params do not affect it.--fixture --no-key(401), output is identical before and after: nomodel_info, every capability false, and noreasoning_effortsent.Tests
New tests in
tests/sdk/llm/test_model_info_proxy_lookup.pyrun against a real local HTTP/v1/model/infoserver and go through the actualLLM→get_litellm_model_info→get_features→select_chat_optionspath. New tests intests/sdk/llm/test_model_features.pycoverget_featuresdirectly. They use an alias the LiteLLM registry does not know (acme-reasoner-7), so the proxy is the only source of the capability. Coverage:data, all falling back to existing behaviorsupports_reasoningreasoning_effortenables no otherModelFeaturesfield (prompt_cache_key,prompt_cache,vision, …), and unmapped names such assupports_vision/image_url, a bare string, or non-strings change nothingVideo/Screenshots
Not applicable. This is SDK capability resolution with no UI change. Evidence is the reproducer output above.
Design Doc
Not applicable. The change is two small functions plus one precedence rule.
Type
Notes
allowed_openai_paramsa stable LiteLLM contract? Only partly.allowed_openai_paramson config.yaml), and LiteLLM 1.93 applies it assupported_params + allowed_openai_params./v1/model/infois not a declared response field._get_proxy_model_info()echoeslitellm_paramsminus credentials.model_info.supported_openai_paramsis LiteLLM's canonical field, but it is computed from the static registry for the underlying model and omits the deployment's allowed params. Using it broadly would also bring back the passthrough over-reporting fixed in [Bug]: openhands/claude-* conversations fail with 400 UnsupportedParamsError on prompt_cache_key when litellm>=1.99 #5325, so this PR does not consume it..pr/proxy-request-params/litellm-upstream-issue.md. I could not file it: the available token gets403 Resource not accessible by integrationonBerriAI/litellm. A maintainer needs to open it and link it here.reasoning_effortenablessupports_reasoning_effort, the existing chat-options rule also drops sampling params for that model unlesssupports_sampling_paramssays otherwise. This is the same rule that already applies to every reasoning-effort model.LLM_API_KEYwas not present in this sandbox. The unauthenticated live call returns401and falls back exactly as on base (included inbefore.txt/after.txt). RunLLM_API_KEY=... uv run python .pr/proxy-request-params/repro.py --base-url https://llm-proxy.app.all-hands.devto confirm against the managed proxy. The fixture serves the exact redacted entry from Define and consume proxy-advertised request-parameter capabilities #5499.tests/sdkfailures (hooks async, FIFO fairness, import timing) pass when rerun serially on this branch (75 passed). They are timing-sensitive under-n 8.tests/crossfailures came from the sandbox's runtime env vars leaking into the in-process agent-server. With a clean env,tests/cross/test_hello_world.pyandtest_remote_conversation_live_server.pygive 26 passed, 1 skipped.ready-for-devlabel, so that check will fail once this leaves draft until a maintainer triages the issue.This PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:88249e4-pythonRun
All tags pushed for this build
About Multi-Architecture Support
88249e4-python) is a multi-arch manifest supporting both amd64 and arm6488249e4-python-amd64) are also available if needed