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]

Merge branch 'main' into feat/github-copilot-thinking-reasoning-support

Krish Dholakiaa913ecf60b04
diff --cc litellm/llms/github_copilot/chat/transformation.py
index 65f83c178a3,4aa6063570d..66227ac21d8
--- a/litellm/llms/github_copilot/chat/transformation.py
+++ b/litellm/llms/github_copilot/chat/transformation.py
@@@ -75,32 -75,12 +75,36 @@@ class GithubCopilotConfig(OpenAIConfig)
initiator = self._determine_initiator(messages)
validated_headers["X-Initiator"] = initiator
+ # Add Copilot-Vision-Request header if request contains images
+ if self._has_vision_content(messages):
+ validated_headers["Copilot-Vision-Request"] = "true"
+
return validated_headers
+ def get_supported_openai_params(self, model: str) -> list:
+ """
+ Get supported OpenAI parameters for GitHub Copilot.
+
+ For Claude models that support extended thinking (Claude 4 family and Claude 3-7), includes thinking and reasoning_effort parameters.
+ For other models, returns standard OpenAI parameters (which may include reasoning_effort for o-series models).
+ """
+ from litellm.utils import supports_reasoning
+
+ # Get base OpenAI parameters
+ base_params = super().get_supported_openai_params(model)
+
+ # Add Claude-specific parameters for models that support extended thinking
+ if "claude" in model.lower() and supports_reasoning(
+ model=model.lower(),
+ ):
+ if "thinking" not in base_params:
+ base_params.append("thinking")
+ # reasoning_effort is not included by parent for Claude models, so add it
+ if "reasoning_effort" not in base_params:
+ base_params.append("reasoning_effort")
+
+ return base_params
+
def _determine_initiator(self, messages: List[AllMessageValues]) -> str:
"""
Determine if request is user or agent initiated based on message roles.
diff --cc tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py
index 96da5fb9423,1c99b4f9f59..d92025bf6af
--- a/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py
+++ b/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py
@@@ -364,53 -364,97 +364,148 @@@ def test_x_initiator_header_system_only
assert headers["X-Initiator"] == "user"
+def test_get_supported_openai_params_claude_model():
+ """Test that Claude models with extended thinking support have thinking and reasoning parameters."""
+ config = GithubCopilotConfig()
+
+ # Test Claude 4 model supports thinking and reasoning_effort parameters
+ supported_params = config.get_supported_openai_params("claude-sonnet-4-20250514")
+ assert "thinking" in supported_params
+ assert "reasoning_effort" in supported_params
+
+ # Test Claude 3-7 model supports thinking and reasoning_effort parameters
+ supported_params_claude37 = config.get_supported_openai_params("claude-3-7-sonnet-20250219")
+ assert "thinking" in supported_params_claude37
+ assert "reasoning_effort" in supported_params_claude37
+
+ # Test Claude 3.5 model does NOT support thinking parameters (no extended thinking)
+ supported_params_claude35 = config.get_supported_openai_params("claude-3.5-sonnet")
+ assert "thinking" not in supported_params_claude35
+ assert "reasoning_effort" not in supported_params_claude35
+
+ # Test non-Claude model doesn't include thinking parameters but may include reasoning_effort
+ supported_params_gpt = config.get_supported_openai_params("gpt-4o")
+ assert "thinking" not in supported_params_gpt
+ # gpt-4o should NOT have reasoning_effort (not a reasoning model)
+ assert "reasoning_effort" not in supported_params_gpt
+
+ # Test O-series reasoning models include reasoning_effort but not thinking
+ supported_params_o3 = config.get_supported_openai_params("o3-mini")
+ assert "thinking" not in supported_params_o3
+ # o3-mini should have reasoning_effort (it's an O-series reasoning model)
+ assert "reasoning_effort" in supported_params_o3
+
+
+def test_get_supported_openai_params_case_insensitive():
+ """Test that Claude model detection is case-insensitive for models with extended thinking."""
+ config = GithubCopilotConfig()
+
+ # Test uppercase Claude 4 model with full model name
+ supported_params_upper = config.get_supported_openai_params("CLAUDE-SONNET-4-20250514")
+ assert "thinking" in supported_params_upper
+ assert "reasoning_effort" in supported_params_upper
+
+ # Test mixed case Claude 3-7 model (has extended thinking) with full model name
+ supported_params_mixed = config.get_supported_openai_params("Claude-3-7-Sonnet-20250219")
+ assert "thinking" in supported_params_mixed
+ assert "reasoning_effort" in supported_params_mixed
+
+ # Test that Claude 3.5 models don't have thinking support (case insensitive)
+ supported_params_35 = config.get_supported_openai_params("CLAUDE-3.5-SONNET")
+ assert "thinking" not in supported_params_35
+ assert "reasoning_effort" not in supported_params_35
++
+ def test_copilot_vision_request_header_with_image():
+ """Test that Copilot-Vision-Request header is added when messages contain images"""
+ config = GithubCopilotConfig()
+
+ # Mock the authenticator
+ config.authenticator = MagicMock()
+ config.authenticator.get_api_key.return_value = "gh.test-key-123"
+ config.authenticator.get_api_base.return_value = None
+
+ messages = [
+ {
+ "role": "user",
+ "content": [
+ {"type": "text", "text": "What's in this image?"},
+ {
+ "type": "image_url",
+ "image_url": {"url": "data:image/jpeg;base64,abc123"}
+ }
+ ]
+ }
+ ]
+
+ headers = config.validate_environment(
+ headers={},
+ model="github_copilot/gpt-4-vision-preview",
+ messages=messages,
+ optional_params={},
+ litellm_params={},
+ api_key=None,
+ api_base=None,
+ )
+
+ assert headers["Copilot-Vision-Request"] == "true"
+ assert headers["X-Initiator"] == "user"
+
+
+ def test_copilot_vision_request_header_text_only():
+ """Test that Copilot-Vision-Request header is not added for text-only messages"""
+ config = GithubCopilotConfig()
+
+ # Mock the authenticator
+ config.authenticator = MagicMock()
+ config.authenticator.get_api_key.return_value = "gh.test-key-123"
+ config.authenticator.get_api_base.return_value = None
+
+ messages = [
+ {"role": "user", "content": "Just a text message"},
+ ]
+
+ headers = config.validate_environment(
+ headers={},
+ model="github_copilot/gpt-4",
+ messages=messages,
+ optional_params={},
+ litellm_params={},
+ api_key=None,
+ api_base=None,
+ )
+
+ assert "Copilot-Vision-Request" not in headers
+ assert headers["X-Initiator"] == "user"
+
+
+ def test_copilot_vision_request_header_with_type_image_url():
+ """Test that Copilot-Vision-Request header is added for content with type: image_url"""
+ config = GithubCopilotConfig()
+
+ # Mock the authenticator
+ config.authenticator = MagicMock()
+ config.authenticator.get_api_key.return_value = "gh.test-key-123"
+ config.authenticator.get_api_base.return_value = None
+
+ messages = [
+ {
+ "role": "user",
+ "content": [
+ {"type": "text", "text": "Analyze this image"},
+ {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
+ ]
+ }
+ ]
+
+ headers = config.validate_environment(
+ headers={},
+ model="github_copilot/gpt-4-vision-preview",
+ messages=messages,
+ optional_params={},
+ litellm_params={},
+ api_key=None,
+ api_base=None,
+ )
+
+ assert headers["Copilot-Vision-Request"] == "true"
+ assert headers["X-Initiator"] == "user"