Address code review feedback: instead of silently dropping data when
server_tool_use is an unsupported type, now:
- Issue a warning when receiving unexpected types
- Attempt graceful conversion for Pydantic models (via model_dump)
- Attempt graceful conversion for Mapping types (via dict())
- Warn again if conversion fails
This prevents silent data loss while maintaining backward compatibility.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fix Pydantic serialization warning when API responses contain
server_tool_use as a dict instead of ServerToolUse object.
Some API providers (e.g., NEXUS, custom Anthropic-compatible endpoints)
return server_tool_use as a plain dict with fields like:
{
"web_search_requests": 0,
"tool_search_requests": null
}
This caused Pydantic serialization warnings:
PydanticSerializationUnexpectedValue(Expected `ServerToolUse` -
serialized value may not be as expected)
Changes:
- Modified Usage.__init__ to accept Union[ServerToolUse, dict] for server_tool_use
- Added conversion logic to transform dict to ServerToolUse object
- Follows same pattern as prompt_tokens_details and completion_tokens_details
This maintains backward compatibility while supporting API responses
that return dict format for server_tool_use field.
first_id and last_id in the video list response were returned as raw
provider IDs while data[].id was properly wrapped with
encode_video_id_with_provider(). This caused pagination to break when
clients passed unencoded cursors back as the `after` parameter.
- Encode first_id/last_id in transform_video_list_response
- Decode the `after` param in transform_video_list_request via
extract_original_video_id()
- Add 6 unit tests covering encoding, decoding, passthrough, and
full round-trip pagination
Fixes#20708
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Vertex AI requires Anthropic beta flags in the request body
(anthropic_beta array), not as HTTP headers. The Bedrock handler
already extracts user-specified beta headers from the headers dict,
but the Vertex handler was missing this, causing extra_headers like
interleaved-thinking-2025-05-14 to be silently dropped.
This extracts anthropic-beta values from optional_params extra_headers
and merges them into the anthropic_beta request body field, and also
removes extra_headers from the request body since the parent's
transform_request spreads optional_params into data.