Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/gateway/api/routes/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@
"Top up the provider account, or route this model to a provider that has credit."
)
PROVIDER_RATE_LIMITED_DETAIL = "The provider rate-limited this request"
PROVIDER_NONSTREAMING_MAX_TOKENS_DETAIL = (
"max_tokens is too large for a non-streaming request to this provider; lower max_tokens "
"or set stream: true"
)
ALL_PROVIDERS_FAILED_DETAIL = "All upstream providers failed"
ALL_PROVIDERS_TIMED_OUT_DETAIL = "All upstream providers timed out"
SANDBOX_NOT_CONFIGURED_DETAIL = (
Expand Down Expand Up @@ -343,6 +347,20 @@ def _unsupported_feature_detail(exc: BaseException) -> str:
return _caller_fault_detail(exc, PROVIDER_BAD_REQUEST_DETAIL)


# The anthropic SDK's non-streaming pre-flight guard message (otari#533); status-less,
# so this classifier has to name it explicitly or it falls through to a generic 502.
# Matched as a substring: the SDK message also links a docs anchor that has moved.
_ANTHROPIC_NONSTREAMING_TIMEOUT_GUARD_MESSAGE = "Streaming is required for operations that may take longer"


def _is_anthropic_nonstreaming_timeout_guard(exc: BaseException) -> bool:
"""True when a status-less ``ValueError`` is the anthropic SDK's own pre-flight guard."""
return any(
isinstance(candidate, ValueError) and _ANTHROPIC_NONSTREAMING_TIMEOUT_GUARD_MESSAGE in str(candidate)
for candidate in upstream_exception_chain(exc)
)


def _redacted_caller_fault_detail(message: str, fallback: str) -> str:
"""Return redacted explanatory text, or a fixed detail when none remains."""
redacted = redact_upstream_message(message)
Expand Down Expand Up @@ -403,6 +421,10 @@ def classify_provider_error(exc: BaseException) -> ProviderErrorMapping | None:
# whole signal here, and its message names the unsupported feature.
if _is_unsupported_feature_error(exc):
return ProviderErrorMapping(status.HTTP_400_BAD_REQUEST, _unsupported_feature_detail(exc))
# Defense in depth for otari#533: an operator-supplied timeout equal to the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scenario named here cannot occur. A YAML client_args: {timeout: 600} becomes httpx.Timeout(600.0), which is not equal to DEFAULT_TIMEOUT (connect=5.0), so an operator-supplied timeout equal to the SDK's default is not expressible from config and never re-arms the guard.

Keep the branch: it still catches any-llm's InvalidRequestError translation and any future Anthropic client built without with_anthropic_default_timeout. Reword the justification, or the next reader will trust it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right about the mechanism, and I rewrote the comment rather than the branch. An operator's client_args.timeout can only ever arrive as a flat number from config, and a flat number sets every httpx.Timeout dimension including connect, so it can equal DEFAULT_TIMEOUT only by also setting connect to 5.0, at which point read/write/pool are 5.0 too, not 600. Config alone can't reproduce the real default, so the old comment's stated scenario doesn't happen.

The branch itself stays, and the comment now says what it actually catches: a client built without with_anthropic_default_timeout, i.e. some future call path that skips get_provider_kwargs and build_attempt_client_args. That client is left at the SDK's real default and can still trip the guard for a large max_tokens.

Pushed at 4bdef8c.

# SDK's own default re-arms this same status-less guard.
if _is_anthropic_nonstreaming_timeout_guard(exc):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch is unreachable through either client-construction path once the timeout is injected, and it couples the classifier to an English sentence in a vendored SDK. Meanwhile any-llm 1.25's _translating_nonstreaming_guard already converts the guard into an InvalidRequestError whose message names the actual max_tokens value, which this replaces with a fixed string.

Classifying a status-less any_llm.exceptions.InvalidRequestError as a 400 through _redacted_caller_fault_detail is reachable today, generalizes to every other status-less InvalidRequestError, keeps the more specific message, and sits on the same rung as the existing _is_unsupported_feature_error branch.

return ProviderErrorMapping(status.HTTP_400_BAD_REQUEST, PROVIDER_NONSTREAMING_MAX_TOKENS_DETAIL)
if status_code is None:
return None
# Account billing exhaustion, which several providers report as a 400/422
Expand Down
16 changes: 10 additions & 6 deletions src/gateway/api/routes/_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from gateway.models.mcp import McpServerConfig
from gateway.services.bedrock_gateway_auth import build_bedrock_client_args
from gateway.services.mcp_loop import MaxToolIterationsExceeded
from gateway.services.provider_kwargs import with_anthropic_default_timeout
from gateway.services.sandbox_backend import SandboxNotReachableError
from gateway.services.web_search_backend import WebSearchNotReachableError

Expand Down Expand Up @@ -173,7 +174,8 @@ class _AttemptFailure(NamedTuple):

def build_attempt_client_args(attempt: ResolvedAttempt) -> dict[str, Any] | None:
"""Build the ``client_args`` any-llm needs to construct this attempt's
provider client, or ``None`` when the attempt carries no ``extra_params``.
provider client, or ``None`` when the attempt carries no ``extra_params``
and needs none injected (see ``with_anthropic_default_timeout``).

This *must* be a separate ``client_args`` dict, not merged flat into the
completion kwargs: any-llm's ``acompletion()`` only forwards a
Expand All @@ -189,14 +191,16 @@ def build_attempt_client_args(attempt: ResolvedAttempt) -> dict[str, Any] | None
Bedrock gets dedicated handling (see :mod:`gateway.services.bedrock_gateway_auth`)
because it also needs its secret aliased to a different boto3 kwarg name
and, for the bearer-token ("Bedrock API key") credential shape, a custom
pre-built client. Every other provider's ``extra_params`` is forwarded
as-is.
pre-built client. Anthropic gets a default ``timeout`` filled in when the
attempt carries none (see :func:`gateway.services.provider_kwargs.with_anthropic_default_timeout`,
otari#533). Every other provider's ``extra_params`` is forwarded as-is.
"""
provider = LLMProvider(attempt.provider)
if not attempt.extra_params:
return None
if LLMProvider(attempt.provider) == LLMProvider.BEDROCK:
return with_anthropic_default_timeout(provider, None)
if provider == LLMProvider.BEDROCK:
return build_bedrock_client_args(attempt.api_key, attempt.extra_params)
return dict(attempt.extra_params)
return with_anthropic_default_timeout(provider, dict(attempt.extra_params))


def default_attempt_kwargs(
Expand Down
25 changes: 25 additions & 0 deletions src/gateway/services/provider_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@
# and no key takes the keyless placeholder, so it never reaches a caller alone.
_NON_CREDENTIAL_KWARGS = frozenset({"client_args"})

# The anthropic SDK's non-streaming pre-flight guard fires for a large max_tokens
# only while the client's timeout is untouched (otari#533); this is also the
# guard's own fallback value, so setting it explicitly disables the guard alone.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing ties 600.0 to anthropic.DEFAULT_TIMEOUT, so if the SDK bumps its default the constant diverges silently and this comment's "also the guard's own fallback value" goes stale. Add the drift assertion this repo already uses for the same class of coupling (test_the_uncredentialed_provider_roster_has_not_drifted):

assert anthropic.DEFAULT_TIMEOUT.read == ANTHROPIC_DEFAULT_TIMEOUT_SECONDS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the drift risk, though the exact assertion changed shape along with the fix. Since with_anthropic_default_timeout now injects httpx.Timeout(601.0, connect=5.0) instead of a flat 600.0 (see the reply on the finding above), the constant that has to track the SDK is the connect value, not the read value. tests/unit/test_provider_instances.py now has test_anthropic_default_timeout_constants_track_the_sdks_own_default, asserting anthropic.DEFAULT_TIMEOUT.connect == ANTHROPIC_DEFAULT_CONNECT_TIMEOUT_SECONDS and that the httpx.Timeout we build stays unequal to anthropic.DEFAULT_TIMEOUT. Either one drifting fails the test.

Pushed at 4bdef8c.

ANTHROPIC_DEFAULT_TIMEOUT_SECONDS = 600.0


def with_anthropic_default_timeout(
provider: LLMProvider, client_args: dict[str, Any] | None
) -> dict[str, Any] | None:
"""Ensure an Anthropic ``client_args`` carries an explicit ``timeout``.

A no-op for every other provider. An operator's own ``timeout`` (set via
``client_args`` on the provider config or a platform attempt's
``extra_params``) is left untouched; this only fills the gap when nothing
was configured.
"""
if provider != LLMProvider.ANTHROPIC:
return client_args
merged = dict(client_args) if client_args else {}
merged.setdefault("timeout", ANTHROPIC_DEFAULT_TIMEOUT_SECONDS)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A flat float raises the Anthropic client's connect timeout from 5s to 600s on every request, including the streaming ones the guard never touched. Verified against the installed SDK:

anthropic._constants.DEFAULT_TIMEOUT   -> Timeout(connect=5.0, read=600, write=600, pool=600)
_calculate_nonstreaming_timeout(...)   -> Timeout(connect=5.0, read=600, write=600, pool=600)
AsyncAnthropic(timeout=600.0).timeout  -> Timeout(timeout=600.0)   # connect=600.0

The guard's trigger is self._client.timeout == DEFAULT_TIMEOUT (anthropic/resources/messages/messages.py:1061), so 600.0 disarms it only because it is unequal to the default, and the inequality is exactly the connect dimension. There is no client-level value that both disarms the guard and keeps connect=5.0: httpx.Timeout(600.0, connect=5.0) compares equal to DEFAULT_TIMEOUT and re-arms it. This also reaches alist_models, where the surrounding code already treats a 600s hang as a hazard (model_discovery_service.py:317, "so a black-holed endpoint cannot hang the test button for the SDK's ~600s default").

A per-request timeout disarms the guard and leaves the client at DEFAULT_TIMEOUT. Against the real any-llm/Anthropic stack with httpx.AsyncClient.send patched:

client_args {"timeout": 600.0}                 -> APIConnectionError   (guard skipped, connect=600)
client_args httpx.Timeout(600.0, connect=5.0)  -> InvalidRequestError  (guard re-armed)
acompletion(..., timeout=600.0)                -> APIConnectionError   (guard skipped, connect=5)

Fix: inject timeout as a completion kwarg instead of into client_args. That moves the injection to where request kwargs are assembled (default_attempt_kwargs, responses.py:381, and the standalone path) rather than get_provider_kwargs, so it is a wider change than this one. If it has to stay client-level, httpx.Timeout(601.0, connect=5.0) keeps the 5s connect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right on every part of this, and I reproduced it before changing anything. In a Docker container with anthropic 0.88.0 installed, AsyncAnthropic(timeout=600.0)._client.timeout is Timeout(timeout=600.0), and its connect attribute reads 600.0, not 5.0. anthropic._constants.DEFAULT_TIMEOUT is Timeout(connect=5.0, read=600, write=600, pool=600), and the guard in messages.py checks self._client.timeout == DEFAULT_TIMEOUT exactly as you quoted. I also patched httpx.AsyncClient.send and ran your three cases through the real SDK: a flat 600.0 skips the guard and reaches the transport layer with connect=600, httpx.Timeout(600.0, connect=5.0) compares equal to DEFAULT_TIMEOUT and puts the guard back, and httpx.Timeout(601.0, connect=5.0) skips the guard and reaches the transport with connect still at 5.0.

I went with your client-level alternative rather than moving this to a completion kwarg. with_anthropic_default_timeout now injects httpx.Timeout(601.0, connect=5.0) instead of a flat float. That function already backs both call sites, get_provider_kwargs and build_attempt_client_args, so the platform-attempt path gets the fix too without touching responses.py or the completion-kwarg assembly. A new test in test_hybrid_client_args_routing.py drives an attempt through the real any-llm/anthropic stack and captures the constructed httpx.AsyncClient's own timeout to confirm connect lands at 5.0 end to end, not just in our own dict construction.

Pushed at 4bdef8c.

return merged


def _kwargs_carry_a_credential(kwargs: dict[str, Any]) -> bool:
"""Whether anything in a resolved provider's kwargs could authenticate a call.
Expand Down Expand Up @@ -227,6 +249,9 @@ def get_provider_kwargs(
if placeholder is not None:
kwargs["api_key"] = placeholder

if provider == LLMProvider.ANTHROPIC:
kwargs["client_args"] = with_anthropic_default_timeout(provider, kwargs.get("client_args"))

return kwargs


Expand Down
71 changes: 71 additions & 0 deletions tests/unit/test_hybrid_client_args_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from unittest.mock import patch

import pytest
from anthropic import APIConnectionError
from any_llm import acompletion

from gateway.api.routes._platform import ResolvedAttempt, default_attempt_kwargs
Expand Down Expand Up @@ -98,3 +99,73 @@ def fake_converse(**_call_kwargs: Any) -> Any:
# client and skips constructing its own; Session.client() is
# untouched for the runtime client in this shape.
fake_boto3_client.assert_not_called()


@pytest.mark.asyncio
async def test_anthropic_default_timeout_reaches_the_real_sdk_client() -> None:
"""otari#533: with no extra_params, the anthropic client used to be built
with the SDK's own default timeout, which makes AsyncAnthropic's
non-streaming pre-flight guard raise a bare ValueError for a large
max_tokens before any request is even attempted. default_attempt_kwargs now
carries an explicit timeout through client_args, which the real SDK's guard
treats identically to an operator-supplied one and skips."""
attempt = ResolvedAttempt(
attempt_id="a0",
position=0,
provider="anthropic",
model="claude-opus-5",
api_key="sk-test",
managed=False,
extra_params=None,
)
kwargs = default_attempt_kwargs(
attempt,
{"messages": [{"role": "user", "content": "hi"}], "max_tokens": 65536, "stream": False},
)

class _Sentinel(Exception):
pass

async def fake_send(*_args: Any, **_kwargs: Any) -> Any:
raise _Sentinel

# any-llm/anthropic wraps a non-HTTP send failure in APIConnectionError after
# retries; reaching that (rather than the pre-flight ValueError) is what
# proves the guard was skipped and the request reached the transport layer.
with patch("httpx.AsyncClient.send", side_effect=fake_send):
with pytest.raises(APIConnectionError):
await acompletion(**kwargs)


@pytest.mark.asyncio
async def test_anthropic_default_timeout_reaches_the_real_sdk_client_in_hybrid_mode() -> None:
"""otari#533 point 1: an attempt with its own extra_params (the hybrid-mode
shape) took a different branch of build_attempt_client_args than the bare
no-extra_params case above, and that branch never filled in a default
timeout, so a platform-routed Anthropic attempt with any extra_params at
all (e.g. a base_url override) still hit the pre-flight guard."""
attempt = ResolvedAttempt(
attempt_id="a0",
position=0,
provider="anthropic",
model="claude-opus-5",
api_key="sk-test",
managed=False,
extra_params={"auth_token": "operator-supplied-bearer-token"},
)
kwargs = default_attempt_kwargs(
attempt,
{"messages": [{"role": "user", "content": "hi"}], "max_tokens": 65536, "stream": False},
)
assert kwargs["client_args"]["timeout"] == 600.0
assert kwargs["client_args"]["auth_token"] == "operator-supplied-bearer-token"

class _Sentinel(Exception):
pass

async def fake_send(*_args: Any, **_kwargs: Any) -> Any:
raise _Sentinel

with patch("httpx.AsyncClient.send", side_effect=fake_send):
with pytest.raises(APIConnectionError):
await acompletion(**kwargs)
60 changes: 59 additions & 1 deletion tests/unit/test_provider_error_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
import httpx
import pytest
from anthropic import APITimeoutError as AnthropicAPITimeoutError
from any_llm.exceptions import UnsupportedParameterError
from any_llm.exceptions import InvalidRequestError, UnsupportedParameterError
from openai import APITimeoutError as OpenAIAPITimeoutError

from gateway.api.routes._pipeline import (
PROVIDER_BAD_REQUEST_DETAIL,
PROVIDER_BILLING_DETAIL,
PROVIDER_CREDENTIALS_DETAIL,
PROVIDER_MODEL_NOT_FOUND_DETAIL,
PROVIDER_NONSTREAMING_MAX_TOKENS_DETAIL,
PROVIDER_RATE_LIMITED_DETAIL,
PROVIDER_TIMEOUT_DETAIL,
classify_provider_error,
Expand Down Expand Up @@ -348,6 +349,63 @@ def test_unsupported_feature_is_recorded_as_400_on_the_usage_log() -> None:
assert failure_status_code(NotImplementedError(_CONTEXT_MANAGEMENT_MSG)) == 400


_ANTHROPIC_NONSTREAMING_TIMEOUT_MSG = (
"Streaming is required for operations that may take longer than 10 minutes. See "
"https://github.com/anthropics/anthropic-sdk-python#long-requests for more details"
)


def test_anthropic_nonstreaming_timeout_guard_maps_to_400() -> None:
"""otari#533: the anthropic SDK's own pre-flight guard for a non-streaming
request whose max_tokens implies over 10 minutes raises a bare, status-less
ValueError, which used to fall through to a generic 502 telling the caller
nothing about the client-side limit it hit."""
mapping = classify_provider_error(ValueError(_ANTHROPIC_NONSTREAMING_TIMEOUT_MSG))
assert mapping is not None
assert mapping.status_code == 400
assert mapping.detail == PROVIDER_NONSTREAMING_MAX_TOKENS_DETAIL


def test_anthropic_nonstreaming_timeout_guard_survives_the_unified_exception_wrapper() -> None:
"""The message match still fires once ANY_LLM_UNIFIED_EXCEPTIONS=1 wraps the
raw error, because the wrapper keeps it on ``original_exception``."""
mapping = classify_provider_error(_WrappedError(500, ValueError(_ANTHROPIC_NONSTREAMING_TIMEOUT_MSG)))
assert mapping is not None
assert mapping.status_code == 400
assert mapping.detail == PROVIDER_NONSTREAMING_MAX_TOKENS_DETAIL


def test_anthropic_nonstreaming_timeout_guard_is_recorded_as_400_on_the_usage_log() -> None:
assert failure_status_code(ValueError(_ANTHROPIC_NONSTREAMING_TIMEOUT_MSG)) == 400


def test_unrelated_value_error_is_not_mistaken_for_the_timeout_guard() -> None:
"""The match is a specific substring of the SDK's own wording, not any
ValueError: an unrelated caller-code or config ValueError must still return
None so it stays on the generic 502 rather than a wrong client-facing 400."""
assert classify_provider_error(ValueError("invalid literal for int() with base 10")) is None


def test_anthropic_nonstreaming_timeout_guard_via_the_real_any_llm_wrapper() -> None:
"""any-llm-sdk 1.25 already translates the raw ValueError into its own
InvalidRequestError (any_llm/providers/anthropic/base.py's
_translating_nonstreaming_guard), which is what actually reaches this
classifier through acompletion(); it is not a bare ValueError, but it does
carry the original one on .original_exception, which
upstream_exception_chain walks."""
original = ValueError(_ANTHROPIC_NONSTREAMING_TIMEOUT_MSG)
exc = InvalidRequestError(
"A non-streaming request with max_tokens=65536 can exceed the default per-request time "
"limit, so it needs an explicit timeout. Pass a `timeout` (in seconds) or use `stream=True`.",
original_exception=original,
provider_name="anthropic",
)
mapping = classify_provider_error(exc)
assert mapping is not None
assert mapping.status_code == 400
assert mapping.detail == PROVIDER_NONSTREAMING_MAX_TOKENS_DETAIL


def test_redaction_keeps_the_part_that_explains_the_rejection() -> None:
"""Redaction targets secret shapes, not meaning: the text that tells the
caller what to change has to survive."""
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/test_provider_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
_AMBIENT_CREDENTIAL_PROVIDERS,
_KEYLESS_PLACEHOLDER_API_KEY,
_KEYLESS_SELF_HOSTED_PROVIDERS,
ANTHROPIC_DEFAULT_TIMEOUT_SECONDS,
get_provider_kwargs,
keyless_placeholder_api_key,
normalize_pricing_key,
provider_key,
resolve_provider_selector,
split_selector,
with_anthropic_default_timeout,
)

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -405,6 +407,47 @@ def test_get_provider_kwargs_strips_provider_type_and_models() -> None:
assert kwargs == {"api_base": "http://x/v1", "api_key": "k"}


# ---------------------------------------------------------------------------
# get_provider_kwargs / with_anthropic_default_timeout (otari#533)
# ---------------------------------------------------------------------------


def test_get_provider_kwargs_fills_a_default_anthropic_timeout() -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_provider_kwargs(GatewayConfig(), ANTHROPIC) now returns {"client_args": {"timeout": 600.0}} where it returned {}. It still reports exhausted, because client_args is already in _NON_CREDENTIAL_KWARGS, but that is load-bearing for the organization-key and fallback-rung paths and nothing here holds it. Worth pinning alongside these:

def test_a_default_anthropic_timeout_does_not_look_like_a_credential() -> None:
    kwargs = get_provider_kwargs(GatewayConfig(), LLMProvider.ANTHROPIC)
    assert credential_ladder_exhausted(LLMProvider.ANTHROPIC, kwargs) is True

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, close to what you proposed. tests/unit/test_provider_instances.py now has test_a_default_anthropic_timeout_does_not_look_like_a_credential, asserting that get_provider_kwargs(GatewayConfig(), LLMProvider.ANTHROPIC) still reports credential_ladder_exhausted() as True. It pins exactly the thing you flagged: a default-filled client_args stays in _NON_CREDENTIAL_KWARGS and never gets read as a credential by itself.

Pushed at 4bdef8c.

config = GatewayConfig(providers={"anthropic": {"api_key": "sk-test"}})
kwargs = get_provider_kwargs(config, LLMProvider.ANTHROPIC, instance="anthropic")
assert kwargs["client_args"] == {"timeout": ANTHROPIC_DEFAULT_TIMEOUT_SECONDS}


def test_get_provider_kwargs_preserves_an_operator_configured_anthropic_timeout() -> None:
config = GatewayConfig(providers={"anthropic": {"api_key": "sk-test", "client_args": {"timeout": 900}}})
kwargs = get_provider_kwargs(config, LLMProvider.ANTHROPIC, instance="anthropic")
assert kwargs["client_args"] == {"timeout": 900}


def test_get_provider_kwargs_leaves_other_providers_client_args_untouched() -> None:
config = GatewayConfig(providers={"openai": {"api_key": "sk-test"}})
kwargs = get_provider_kwargs(config, LLMProvider.OPENAI, instance="openai")
assert "client_args" not in kwargs


def test_with_anthropic_default_timeout_is_a_no_op_for_other_providers() -> None:
assert with_anthropic_default_timeout(LLMProvider.OPENAI, None) is None
assert with_anthropic_default_timeout(LLMProvider.OPENAI, {"timeout": 5}) == {"timeout": 5}


def test_with_anthropic_default_timeout_fills_a_missing_default() -> None:
assert with_anthropic_default_timeout(LLMProvider.ANTHROPIC, None) == {
"timeout": ANTHROPIC_DEFAULT_TIMEOUT_SECONDS
}
assert with_anthropic_default_timeout(LLMProvider.ANTHROPIC, {}) == {
"timeout": ANTHROPIC_DEFAULT_TIMEOUT_SECONDS
}


def test_with_anthropic_default_timeout_never_overrides_an_explicit_value() -> None:
assert with_anthropic_default_timeout(LLMProvider.ANTHROPIC, {"timeout": 42}) == {"timeout": 42}


# ---------------------------------------------------------------------------
# get_provider_kwargs: keyless custom-endpoint placeholder (mozilla-ai/otari#421)
# ---------------------------------------------------------------------------
Expand Down
Loading