Skip to content

Deduplicate pricing lookup warnings for custom/unknown models #2504

Description

@pgjh

Problem

When using Headroom proxy with a custom or unknown model (e.g. glm-5.2 routed through an OpenAI-compatible provider), LiteLLM cannot resolve pricing for that model. This triggers a WARNING log on every single request:

WARNING - headroom.proxy - Failed to get pricing for model glm-5.2: litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=glm-5.2

In an active session this floods proxy.log with hundreds of identical warnings — one per API call. While proxy.log has rotation, the log still grows rapidly and makes it harder to spot genuinely useful warnings.

Location

headroom/proxy/cost.py, line ~731:

except Exception as e:
    logger.warning(f"Failed to get pricing for model {model}: {e}")
    return None

Suggested Fix

Deduplicate the warning per model so it only fires once per unique model name per process lifetime:

except Exception as e:
    if not getattr(logger, "_warned_models", set()):
        logger._warned_models = set()
    if model not in logger._warned_models:
        logger._warned_models.add(model)
        logger.warning(f"Failed to get pricing for model {model}: {e}")
    return None

This is a minimal, non-invasive change — no new dependencies, no config flags, just a set on the logger object to track which models have already been warned about.

Environment

  • Headroom version: 0.32.1
  • Model: glm-5.2 via OpenAI-compatible backend (--backend anyllm --anyllm-provider openai)
  • LiteLLM: installed (cannot resolve custom model names, as expected)

Impact

Low severity — does not affect functionality (pricing returns None, requests succeed). But the log spam is a real operational annoyance, especially for long-running proxy sessions.

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