Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(lm_studio): resolve illegal Bearer header value issue

Tim Elfrinkb84785b5b751
diff --git a/litellm/llms/lm_studio/chat/transformation.py b/litellm/llms/lm_studio/chat/transformation.py
index f7a2cc0f28a..7b188ff33f8 100644
--- a/litellm/llms/lm_studio/chat/transformation.py
+++ b/litellm/llms/lm_studio/chat/transformation.py
@@ -15,8 +15,8 @@ class LMStudioChatConfig(OpenAIGPTConfig):
) -> Tuple[Optional[str], Optional[str]]:
api_base = api_base or get_secret_str("LM_STUDIO_API_BASE") # type: ignore
dynamic_api_key = (
- api_key or get_secret_str("LM_STUDIO_API_KEY") or " "
- ) # vllm does not require an api key
+ api_key or get_secret_str("LM_STUDIO_API_KEY") or "fake-api-key"
+ ) # LM Studio does not require an api key, but OpenAI client requires non-None value
return api_base, dynamic_api_key
def map_openai_params(
diff --git a/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py b/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py
index 1f09b1e5406..964c85da3db 100644
--- a/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py
+++ b/tests/test_litellm/llms/lm_studio/test_lm_studio_chat_transformation.py
@@ -1,5 +1,6 @@
import os
import sys
+from unittest.mock import patch
from pydantic import BaseModel
@@ -53,3 +54,32 @@ class TestLMStudioChatConfigResponseFormat:
assert mapped_schema["properties"] == schema["properties"]
opt_schema = optional_params["response_format"]["json_schema"]["schema"]
assert opt_schema["properties"] == schema["properties"]
+
+
+def test_lm_studio_get_openai_compatible_provider_info():
+ """Test provider info retrieval"""
+ config = LMStudioChatConfig()
+
+ # Test default behavior (no API key provided)
+ _, api_key = config._get_openai_compatible_provider_info(None, None)
+ assert api_key == "fake-api-key"
+
+ # Test explicit API key
+ _, api_key = config._get_openai_compatible_provider_info(None, "test-key")
+ assert api_key == "test-key"
+
+
+def test_lm_studio_get_openai_compatible_provider_info_with_env():
+ """Test provider info retrieval with environment variables."""
+ config = LMStudioChatConfig()
+
+ with patch.dict(
+ "os.environ",
+ {
+ "LM_STUDIO_API_BASE": "http://localhost:1234/v1",
+ "LM_STUDIO_API_KEY": "env_api_key",
+ },
+ ):
+ api_base, api_key = config._get_openai_compatible_provider_info(None, None)
+ assert api_base == "http://localhost:1234/v1"
+ assert api_key == "env_api_key"