Skip to content

[Bug] Unauthenticated model-info lookup still emits GET /v1/model/info when key is None #5454

Open

Description

@daviskay75

[Bug] Unauthenticated model-info lookup still emits GET /v1/model/info when key is None

Follow-up to #4098 (closed by stale-bot, still present on main @ cc97bf23).

Current behavior

LLM._post_init() → _init_model_info_and_caps() → get_litellm_model_info() →
_get_model_info_from_litellm_proxy() (openhands-sdk/openhands/sdk/llm/utils/model_info.py):

headers = {}
if isinstance(secret_api_key, SecretStr):
    secret_api_key = secret_api_key.get_secret_value()
if secret_api_key:
    headers["Authorization"] = f"Bearer {secret_api_key}"

response = httpx.get(f"{base_url}/v1/model/info", headers=headers)

When no key is available, headers stays empty but the request is still sent. The
managed proxy answers 401, the SDK silently falls back to static LiteLLM
metadata — and every LLM construction / profile load / validation /
deserialization without credentials emits another unauthenticated request
(hourly lru_cache key per process, so fan-out still multiplies it).

Scope (per #4098)

Skip the request only when no key is available and the target is the managed
OpenHands proxy
(is_openhands_proxy_base_url, i.e. recognized
llm-proxy.app.all-hands.dev base URLs). Generic/custom proxies are unchanged:
an open proxy may legitimately serve model info without credentials, so those
lookups must still be attempted. None, empty, and blank keys all count as
keyless (none of them can authenticate).

Repro

from unittest.mock import patch, MagicMock
from openhands.sdk.llm.utils.model_info import _get_model_info_from_litellm_proxy

with patch("openhands.sdk.llm.utils.model_info.httpx.get") as m:
    m.return_value.json.return_value = {"data": []}
    _get_model_info_from_litellm_proxy(
        secret_api_key=None, base_url="https://llm-proxy.app.all-hands.dev",
        model="litellm_proxy/some-model", cache_key=1,
    )
    assert m.call_count == 0  # FAILS: called once with headers={}

Proposed fix

Skip the request under the scope above and fall through to the existing local
fallbacks (get_model_info variants in get_litellm_model_info). Keyed
requests — including invalid keys, whose real 401 stays visible — unchanged.

PR incoming, referencing this issue.

Activity

  1. all-hands-bot commented on Oct 2, 2026

    @all-hands-bot
    Collaborator

    The following comments were added by the OpenHands AI agent.

    Decision needed

    _get_model_info_from_litellm_proxy sends GET /v1/model/info even when no key is present, as reported. The proposed fix — skip the request whenever no key is available — is broader than the scope defined in the linked predecessor #4098, which requires that unauthenticated discovery keep working for generic litellm_proxy/* configurations and arbitrary custom proxy URLs, and would skip only for the managed OpenHands proxy (default/recognized llm-proxy.app.all-hands.dev). The repro here uses a custom proxy URL and expects zero calls, which contradicts that requirement, so the intended scope needs to be confirmed before acceptance criteria can be written.

    1. Should the skip apply to all litellm_proxy/* lookups with no key (blanket), or only when the target is the managed OpenHands proxy with no key, leaving generic/custom proxies unchanged?
    2. Should the skip trigger only when the key is None, or also when it is an empty/blank string?
  2. daviskay75 commented on Oct 2, 2026

    @daviskay75
    ContributorAuthor

    Decision on the two scope questions — agreed with #4098's defined scope:

    1. Managed-proxy-only, not blanket. You are right: a blanket skip would change behavior for open generic proxies that legitimately serve model info without credentials. The skip now applies only when no key is available and the target is the managed proxy (via the existing is_openhands_proxy_base_url helper, which covers both recognized base-URL forms). Generic/custom URLs keep the exact previous behavior (request still attempted). Issue body and repro updated accordingly.
    2. None, empty, and blank all count as keyless. None of them can authenticate, and the current code already treats "" as absent for header purposes (if secret_api_key:), so treating blank the same way for the skip is consistent.

    PR #5456 updated to match (6 tests: managed None/empty/blank/v1-suffixed skipped, managed keyed sends Authorization, generic keyless still attempted).

  3. aivong-openhands commented on Oct 2, 2026

    @aivong-openhands
    Contributor

    Confirming this is still reproducible on a current build that already includes the refresh-on-401 work (#5218 / #5222), with one additional variant that's worth folding into the fix scope.

    Variant: present-but-invalid key, not just key is None

    This issue is scoped to "when key is None," but the same GET /v1/model/info → 401 → silent fallback also happens when a key is sent but the managed proxy rejects it (type: token_not_found_in_db, "Unable to find token in cache or LiteLLM_VerificationTokenTable"). In that case headers["Authorization"] is populated, so a guard that only checks key is None won't skip the request. The meaningful distinction is "proxy can't authenticate this key," which covers both the absent-key and the stale/invalid-key cases.

    Observed behavior (matches the described mechanism)

    • A steady, continuous rate of GET /v1/model/info returning 401, with no functional impact — chat/completions was 100% 200 over the same window. This corroborates the "SDK silently falls back to static LiteLLM metadata" path.
    • The 401s fan out across every process that constructs an LLM without a proxy-valid key (app server, runtime sandboxes, and a periodic cleanup job), consistent with the per-process hourly lru_cache multiplying the request.

    Adjacent symptom (possibly a separate issue)

    The same stale/absent token also surfaces as delete_key / delete_verification_tokens → 404 {'error': 'No keys found'} from cleanup paths trying to delete a token that is no longer in LiteLLM_VerificationTokenTable. Same root (a token referenced after it's gone from the table), different call path.

    Suggested scope

    Skip the /v1/model/info probe — and/or treat a 401 as a cache-miss without re-emitting the request — whenever the proxy cannot authenticate the key, i.e. when the key is None or present-but-not-in-db, rather than only when the key is absent.


    Filed via an AI agent (OpenHands) on behalf of a maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions