`src/provider/anthropic.rs` — `AnthropicClient` [feature: anthropic]
The Messages API client — shared by the Z.ai profile and Bedrock’s native path. (~3,640 lines with tests.)
Key items
from_env()+ builder includingwith_max_tokens(default 8192, 0 rejected at build); headersx-api-key+anthropic-version: 2023-06-01.RequestBodySpec+build_request_body— system always a top-level field (folded from inline system messages,""when empty); tool_use/tool_result blocks;is_error: truetravels on the wire.- The shared
StreamEmitter(reused by Bedrock): typed SSE events; usage latched atmessage_start, max-merged atmessage_delta; thinking/redacted-thinking lanes;message_stopis the terminal event. - Forced-tool
response_formatsynthesis + the two up-front rejections (strict formats, grammar constraints). pub(super) DEFAULT_MAX_TOKENS— shared with Bedrock.
Behavior notes
- Tool-input deltas carry no index — the emitter remembers the open block from
content_block_start. signature_deltaignored; late events aftermessage_stopswallowed (desync guard); a late error after a clean stop is dropped.- Non-streaming replies skip thinking blocks entirely (reasoning is stream-only); images dropped.
Deep dive: Anthropic.