Skip to content

fix(model-metadata): fall back to LITELLM_KEY for endpoint metadata#4914

Open
malaiwah wants to merge 1 commit into
NousResearch:mainfrom
malaiwah:codex/litellm-key-model-metadata
Open

fix(model-metadata): fall back to LITELLM_KEY for endpoint metadata#4914
malaiwah wants to merge 1 commit into
NousResearch:mainfrom
malaiwah:codex/litellm-key-model-metadata

Conversation

@malaiwah

@malaiwah malaiwah commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Falls back to LITELLM_KEY in fetch_endpoint_model_metadata() when no explicit api_key is passed. This fixes custom endpoint metadata and pricing lookups that currently send unauthenticated /models requests and fail with 401s.

Related Issue

Fixes #4913

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • use LITELLM_KEY as a fallback in agent/model_metadata.py when api_key is empty
  • add a regression test in tests/agent/test_model_metadata.py that verifies the Authorization header is sent

How to Test

  1. source venv/bin/activate
  2. python -m pytest tests/agent/test_model_metadata.py tests/test_model_metadata_local_ctx.py -q
  3. Verify fetch_endpoint_model_metadata(..., api_key="") sends Authorization: Bearer <LITELLM_KEY> when LITELLM_KEY is set

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 26.3.1, Python 3.12.11

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

@malaiwah

malaiwah commented Apr 4, 2026

Copy link
Copy Markdown
Contributor Author

Ran the full test suite locally as a follow-up. Current result on this branch/base state is 7880 passed, 172 skipped, 1 xfailed, 7 failed. The failing tests are outside the files touched by this PR, so they do not appear to be caused by this change. Targeted metadata tests for this patch are green: python -m pytest tests/agent/test_model_metadata.py tests/test_model_metadata_local_ctx.py -q -> 95 passed.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: custom endpoint metadata lookup can hit /models without auth

2 participants