| 1183 | @mock.patch(class="st">"openai._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
| 1184 | @pytest.mark.respx(base_url=base_url) |
| 1185 | def test_omit_retry_count_header( |
| 1186 | self, client: OpenAI, failures_before_success: int, respx_mock: MockRouter |
| 1187 | ) -> None: |
| 1188 | client = client.with_options(max_retries=4) |
| 1189 | |
| 1190 | nb_retries = 0 |
| 1191 | |
| 1192 | def retry_handler(_request: httpx.Request) -> httpx.Response: |
| 1193 | nonlocal nb_retries |
| 1194 | if nb_retries < failures_before_success: |
| 1195 | nb_retries += 1 |
| 1196 | return httpx.Response(500) |
| 1197 | return httpx.Response(200) |
| 1198 | |
| 1199 | respx_mock.post(class="st">"/chat/completions").mock(side_effect=retry_handler) |
| 1200 | |
| 1201 | response = client.chat.completions.with_raw_response.create( |
| 1202 | messages=[ |
| 1203 | { |
| 1204 | class="st">"content": class="st">"string", |
| 1205 | class="st">"role": class="st">"developer", |
| 1206 | } |
| 1207 | ], |
| 1208 | model=class="st">"gpt-5.4", |
| 1209 | extra_headers={class="st">"x-stainless-retry-count": Omit()}, |
| 1210 | ) |
| 1211 | |
| 1212 | assert len(response.http_request.headers.get_list(class="st">"x-stainless-retry-count")) == 0 |
| 1213 | |
| 1214 | @pytest.mark.parametrize(class="st">"failures_before_success", [0, 2, 4]) |
| 1215 | @mock.patch(class="st">"openai._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |