feat: add extra_headers parameter to LLM class

- Add extra_headers parameter to LLM constructor for custom authentication headers
- Update _prepare_completion_params to pass extra_headers to LiteLLM
- Add comprehensive tests for extra_headers functionality
- Ensure backward compatibility with None default value

Fixes #3177

Co-Authored-By: Jo\u00E3o <joao@crewai.com>
This commit is contained in:
Devin AI
2025-07-17 09:07:32 +00:00
parent bf248d5118
commit bb19998fe7
2 changed files with 82 additions and 0 deletions

View File

@@ -311,6 +311,7 @@ class LLM(BaseLLM):
callbacks: List[Any] = [],
reasoning_effort: Optional[Literal["none", "low", "medium", "high"]] = None,
stream: bool = False,
extra_headers: Optional[Dict[str, str]] = None,
**kwargs,
):
self.model = model
@@ -337,6 +338,7 @@ class LLM(BaseLLM):
self.additional_params = kwargs
self.is_anthropic = self._is_anthropic_model(model)
self.stream = stream
self.extra_headers = extra_headers
litellm.drop_params = True
@@ -408,6 +410,7 @@ class LLM(BaseLLM):
"stream": self.stream,
"tools": tools,
"reasoning_effort": self.reasoning_effort,
"extra_headers": self.extra_headers,
**self.additional_params,
}