mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(anthropic): skip the sign-in lookup for chatgpt and github_copilot model prefixes on bridged /v1/messages calls
This commit is contained in:
parent
ea5f02e8dd
commit
cb77c44025
3 changed files with 33 additions and 10 deletions
|
|
@ -16,6 +16,7 @@ from pydantic import TypeAdapter
|
|||
|
||||
import litellm
|
||||
from litellm.anthropic_beta_headers_manager import aload_beta_headers_config
|
||||
from litellm.constants import PROVIDERS_THAT_AUTHENTICATE_ON_PROVIDER_INFO
|
||||
from litellm.integrations.anthropic_cache_control_hook import AnthropicCacheControlHook
|
||||
from litellm.litellm_core_utils.core_helpers import as_str_mapping
|
||||
from litellm.litellm_core_utils.exception_mapping_utils import exception_type
|
||||
|
|
@ -113,7 +114,11 @@ def _resolve_requested_provider(
|
|||
litellm_params=litellm_params,
|
||||
)
|
||||
requested_provider: Final = model.partition("/")[0]
|
||||
if custom_llm_provider in (None, requested_provider) or requested_provider not in LlmProvidersSet:
|
||||
if (
|
||||
custom_llm_provider in (None, requested_provider)
|
||||
or requested_provider not in LlmProvidersSet
|
||||
or requested_provider in PROVIDERS_THAT_AUTHENTICATE_ON_PROVIDER_INFO
|
||||
):
|
||||
return resolved
|
||||
own: Final = _resolve_by_model_prefix(model, litellm_params)
|
||||
return own if own is not None and own[1] == custom_llm_provider else resolved
|
||||
|
|
|
|||
|
|
@ -1225,6 +1225,30 @@ async def test_bridged_messages_keep_the_callers_explicit_provider_over_the_mode
|
|||
assert {json.loads(call.request.content)["model"] for call in upstream.calls} == {model}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model", ["chatgpt/gpt-5", "github_copilot/gpt-5"])
|
||||
def test_bridged_messages_reach_the_callers_provider_without_signing_in_to_the_prefix_provider(
|
||||
model, monkeypatch, tmp_path
|
||||
):
|
||||
monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "server-openai-key")
|
||||
monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(tmp_path))
|
||||
monkeypatch.setenv("GITHUB_COPILOT_TOKEN_DIR", str(tmp_path))
|
||||
litellm.in_memory_llm_clients_cache.flush_cache()
|
||||
|
||||
with respx.mock(assert_all_called=True) as respx_mock:
|
||||
upstream: Final = respx_mock.route().mock(side_effect=httpx.ConnectError("cut at the wire"))
|
||||
with pytest.raises(openai.APIError):
|
||||
litellm.anthropic.messages.create(
|
||||
max_tokens=100,
|
||||
messages=[{"role": "user", "content": "ping"}],
|
||||
model=model,
|
||||
custom_llm_provider="openai",
|
||||
)
|
||||
|
||||
assert {call.request.url.host for call in upstream.calls} == {"api.openai.com"}
|
||||
assert {call.request.headers["authorization"] for call in upstream.calls} == {"Bearer server-openai-key"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bridged_messages_send_the_deployments_key_for_azure_models_served_as_openai(monkeypatch):
|
||||
monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)
|
||||
|
|
|
|||
|
|
@ -67,25 +67,19 @@ async def test_anthropic_messages_with_mcp_reaches_an_env_only_deployment_with_i
|
|||
monkeypatch.setenv("AZURE_AI_API_KEY", "azure-env-key")
|
||||
litellm.in_memory_llm_clients_cache.flush_cache()
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
import_module("litellm.responses.mcp.litellm_proxy_mcp_handler").LiteLLM_Proxy_MCP_Handler,
|
||||
"process_mcp_tools_without_openai_transform",
|
||||
new=AsyncMock(return_value=([], {})),
|
||||
),
|
||||
respx.mock(assert_all_called=True) as respx_mock,
|
||||
):
|
||||
with respx.mock(assert_all_called=True) as respx_mock:
|
||||
upstream: Final = respx_mock.route().mock(side_effect=httpx.ConnectError("cut at the wire"))
|
||||
with pytest.raises(openai.APIError):
|
||||
await litellm.anthropic.messages.acreate(
|
||||
max_tokens=100,
|
||||
messages=[{"role": "user", "content": "ping"}],
|
||||
model="azure_ai/gpt-6-luna",
|
||||
tools=[MCP_REFERENCE],
|
||||
tools=[{**MCP_REFERENCE, "server_url": "litellm_proxy"}],
|
||||
)
|
||||
|
||||
assert {call.request.url.host for call in upstream.calls} == {"example-resource.cognitiveservices.azure.com"}
|
||||
assert {call.request.headers.get("api-key") for call in upstream.calls} == {"azure-env-key"}
|
||||
assert not any(b"litellm_proxy" in call.request.content for call in upstream.calls)
|
||||
|
||||
|
||||
def test_anthropic_messages_handler_skips_the_gateway_on_recursion():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue