Skip to content

Conversation

timelfrink
Copy link
Contributor

Title

fix(lm_studio): resolve illegal Bearer header value issue

Relevant issues

Fixes #14502

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

Problem

Users couldn't use LMStudio locally due to httpcore.LocalProtocolError: Illegal header value b'Bearer ' when no API key was set. The issue was caused by the default API key being a single space " ", which created an illegal HTTP Authorization header Bearer (Bearer followed by two spaces).

Root Cause

In litellm/llms/lm_studio/chat/transformation.py, the default API key was set to " " (space) to satisfy OpenAI client requirements, but this created malformed HTTP headers.

Solution

  • Changed default API key from " " to "fake-api-key"
  • This follows the pattern used by other similar providers in the codebase (e.g., hosted_vllm)
  • Creates valid HTTP headers: Authorization: Bearer fake-api-key
  • Maintains full backward compatibility for users with explicit API keys

Testing

  • Added comprehensive tests for provider info retrieval
  • Tests cover default behavior, explicit API keys, and environment variables
  • All existing tests continue to pass

Impact

- Change default API key from space ' ' to 'fake-api-key'
- Fixes httpcore.LocalProtocolError: Illegal header value b'Bearer  '
- Maintains compatibility with explicit API keys and environment variables
- Add comprehensive tests for provider info retrieval

Fixes BerriAI#14502
Copy link

vercel bot commented Sep 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Sep 12, 2025 8:43pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot run a LMStudio local model
1 participant