Skip to content

fix(ai): do not classify gateway endpoint as local serving backend #5867

Closed

Description

@dan-petty

Problem Description

Calls to hosted models like deepseek-v4.1-flash-1017 through PydanticAI (factory.py) are classified as local savings with backend="llm-gateway" and $0 spend. This causes Grafana projected local savings to become excessively high.

In factory.py, _record() passes served_by = getattr(m, "served_by", None) to track_request_spend. Because pydantic_ai_bridge.py sets model_obj.served_by = base_url (the gateway endpoint http://llm-gateway.llm.svc.cluster.local:4000/v1), factory.py passes the gateway proxy URL as the backend. In is_local(), _is_local_api_base(served_by) evaluates llm-gateway.llm.svc.cluster.local as a *.local address and returns True, bypassing model-based checks.

Reproduction Steps

  1. Run python -c 'from devops_cli.ai.spend.pricing import is_local; print(is_local(server="llm-gateway.llm.svc.cluster.local:4000", provider="gateway", served_by="http://llm-gateway.llm.svc.cluster.local:4000/v1", model="deepseek-v4.1-flash-1017"))'
  2. Output prints True instead of False.
  3. Calls in roadmap-service emit devops_cli_ai_tokens_total with local="true" and backend="llm-gateway".

Expected vs Actual Behavior

Expected: The gateway proxy endpoint is not treated as a local serving backend. Hosted models called through the gateway via PydanticAI are classified as spend, not local savings.
Actual: The gateway endpoint matches *.local and is treated as a local serving backend, causing hosted model calls to be marked local="true" with backend="llm-gateway".

Environment Diagnostics

  • DevOps CLI Version: 0.157.0
  • Python Version: 3.14.10
  • OS & Architecture: Linux x86_64
  • Execution Environment: DevContainer

Logs, Traces, or Terminal Output

python -c 'from devops_cli.ai.spend.pricing import is_local; print(is_local(server="llm-gateway.llm.svc.cluster.local:4000", provider="gateway", served_by="http://llm-gateway.llm.svc.cluster.local:4000/v1", model="deepseek-v4.1-flash-1017"))'
True

Activity

  1. added
    source/agent
    type/bug
    scope/ai
    status/new
    value/medium
    effort/low
    on Nov 15, 2026
  2. dan-petty commented on Nov 15, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    status/in-progress
    and removed
    status/new
    on Nov 15, 2026
  4. added
    status/in-review
    and removed
    status/in-progress
    on Nov 15, 2026
  5. removed
    status/in-review
    on Nov 15, 2026
  6. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-15 23:51 UTC

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

    effort/lowpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions