| 2439 | @mock.patch(class="st">"openai._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
| 2440 | @pytest.mark.respx(base_url=base_url) |
| 2441 | async def test_omit_retry_count_header( |
| 2442 | self, async_client: AsyncOpenAI, failures_before_success: int, respx_mock: MockRouter |
| 2443 | ) -> None: |
| 2444 | client = async_client.with_options(max_retries=4) |
| 2445 | |
| 2446 | nb_retries = 0 |
| 2447 | |
| 2448 | def retry_handler(_request: httpx.Request) -> httpx.Response: |
| 2449 | nonlocal nb_retries |
| 2450 | if nb_retries < failures_before_success: |
| 2451 | nb_retries += 1 |
| 2452 | return httpx.Response(500) |
| 2453 | return httpx.Response(200) |
| 2454 | |
| 2455 | respx_mock.post(class="st">"/chat/completions").mock(side_effect=retry_handler) |
| 2456 | |
| 2457 | response = await client.chat.completions.with_raw_response.create( |
| 2458 | messages=[ |
| 2459 | { |
| 2460 | class="st">"content": class="st">"string", |
| 2461 | class="st">"role": class="st">"developer", |
| 2462 | } |
| 2463 | ], |
| 2464 | model=class="st">"gpt-5.4", |
| 2465 | extra_headers={class="st">"x-stainless-retry-count": Omit()}, |
| 2466 | ) |
| 2467 | |
| 2468 | assert len(response.http_request.headers.get_list(class="st">"x-stainless-retry-count")) == 0 |
| 2469 | |
| 2470 | @pytest.mark.parametrize(class="st">"failures_before_success", [0, 2, 4]) |
| 2471 | @mock.patch(class="st">"openai._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |