|
11 | 11 | """ |
12 | 12 |
|
13 | 13 | import json |
| 14 | +from typing import Literal |
14 | 15 |
|
15 | 16 | import httpx2 |
16 | 17 | import pytest |
@@ -123,6 +124,57 @@ async def test_sampling_fields_reach_the_api_when_streaming() -> None: |
123 | 124 | assert captured["body"] == IsPartialDict({"temperature": 0.2, "stream": True}) |
124 | 125 |
|
125 | 126 |
|
| 127 | +@pytest.mark.asyncio |
| 128 | +@pytest.mark.parametrize("streaming", [False, True]) |
| 129 | +@pytest.mark.parametrize("speed", ["standard", "fast", None]) |
| 130 | +async def test_speed_reaches_the_api_when_set(speed: Literal["standard", "fast"] | None, streaming: bool) -> None: |
| 131 | + captured: dict[str, object] = {} |
| 132 | + config = AnthropicConfig( |
| 133 | + model="claude-opus-5-5", |
| 134 | + api_key="test", |
| 135 | + speed=speed, |
| 136 | + streaming=streaming, |
| 137 | + http_client=_capturing_client(captured, stream=streaming), |
| 138 | + ) |
| 139 | + |
| 140 | + await _ask(config) |
| 141 | + |
| 142 | + body = captured["body"] |
| 143 | + assert isinstance(body, dict) |
| 144 | + if speed is None: |
| 145 | + assert "speed" not in body |
| 146 | + else: |
| 147 | + assert body == IsPartialDict({"speed": speed}) |
| 148 | + headers = captured["headers"] |
| 149 | + assert isinstance(headers, httpx2.Headers) |
| 150 | + assert "anthropic-beta" not in headers |
| 151 | + |
| 152 | + |
| 153 | +@pytest.mark.asyncio |
| 154 | +@pytest.mark.parametrize("streaming", [False, True]) |
| 155 | +@pytest.mark.parametrize("speed", ["standard", "fast"]) |
| 156 | +async def test_speed_preserves_the_users_beta_header_with_mcp( |
| 157 | + context: Context, speed: Literal["standard", "fast"], streaming: bool |
| 158 | +) -> None: |
| 159 | + captured: dict[str, object] = {} |
| 160 | + config = AnthropicConfig( |
| 161 | + model="claude-opus-5", |
| 162 | + api_key="test", |
| 163 | + speed=speed, |
| 164 | + streaming=streaming, |
| 165 | + default_headers={"Anthropic-Beta": "fast-mode-2026-02-01"}, |
| 166 | + http_client=_capturing_client(captured, stream=streaming), |
| 167 | + ) |
| 168 | + schemas = await MCPServerTool(server_url="https://mcp.example.com/x", server_label="x").schemas(context) |
| 169 | + |
| 170 | + await _ask(config, tools=schemas) |
| 171 | + |
| 172 | + assert captured["body"] == IsPartialDict({"speed": speed}) |
| 173 | + headers = captured["headers"] |
| 174 | + assert isinstance(headers, httpx2.Headers) |
| 175 | + assert headers.get_list("anthropic-beta") == ["fast-mode-2026-02-01,mcp-client-2025-11-20"] |
| 176 | + |
| 177 | + |
126 | 178 | @pytest.mark.asyncio |
127 | 179 | async def test_user_extra_body_wins_over_a_sampling_field() -> None: |
128 | 180 | captured: dict[str, object] = {} |
|
0 commit comments