diff --git a/tests/entrypoints/openai/test_openai_schema.py b/tests/entrypoints/openai/test_openai_schema.py index 1baab9934..2b26ebd04 100644 --- a/tests/entrypoints/openai/test_openai_schema.py +++ b/tests/entrypoints/openai/test_openai_schema.py @@ -151,6 +151,7 @@ def test_openapi_stateless(case: schemathesis.Case): # requires a longer timeout ("POST", "/v1/chat/completions"): LONG_TIMEOUT_SECONDS, ("POST", "/v1/completions"): LONG_TIMEOUT_SECONDS, + ("POST", "/v1/messages"): LONG_TIMEOUT_SECONDS, }.get(key, DEFAULT_TIMEOUT_SECONDS) # No need to verify SSL certificate for localhost diff --git a/vllm/entrypoints/anthropic/protocol.py b/vllm/entrypoints/anthropic/protocol.py index 5ced67d4c..bbf1ffc27 100644 --- a/vllm/entrypoints/anthropic/protocol.py +++ b/vllm/entrypoints/anthropic/protocol.py @@ -5,7 +5,7 @@ import time from typing import Any, Literal -from pydantic import BaseModel, field_validator +from pydantic import BaseModel, field_validator, model_validator class AnthropicError(BaseModel): @@ -76,6 +76,12 @@ class AnthropicToolChoice(BaseModel): type: Literal["auto", "any", "tool"] name: str | None = None + @model_validator(mode="after") + def validate_name_required_for_tool(self) -> "AnthropicToolChoice": + if self.type == "tool" and not self.name: + raise ValueError("tool_choice.name is required when type is 'tool'") + return self + class AnthropicMessagesRequest(BaseModel): """Anthropic Messages API request"""