Home / Function/ _parse_retry_after_header() — anthropic-sdk-python Function Reference

_parse_retry_after_header() — anthropic-sdk-python Function Reference

Architecture documentation for the _parse_retry_after_header() function in _base_client.py from the anthropic-sdk-python codebase.

Function python AnthropicClient SyncAPI calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  614e9b3b_4fa0_b0b8_c33c_36259a5398eb["_parse_retry_after_header()"]
  842ce0be_ea56_b939_960f_13eb61230daf["BaseClient"]
  614e9b3b_4fa0_b0b8_c33c_36259a5398eb -->|defined in| 842ce0be_ea56_b939_960f_13eb61230daf
  f6d7d851_1218_0312_84fe_55254f0ab693["_calculate_retry_timeout()"]
  f6d7d851_1218_0312_84fe_55254f0ab693 -->|calls| 614e9b3b_4fa0_b0b8_c33c_36259a5398eb
  afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7["get()"]
  614e9b3b_4fa0_b0b8_c33c_36259a5398eb -->|calls| afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7
  style 614e9b3b_4fa0_b0b8_c33c_36259a5398eb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_base_client.py lines 741–773

    def _parse_retry_after_header(self, response_headers: Optional[httpx.Headers] = None) -> float | None:
        """Returns a float of the number of seconds (not milliseconds) to wait after retrying, or None if unspecified.

        About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
        See also  https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#syntax
        """
        if response_headers is None:
            return None

        # First, try the non-standard `retry-after-ms` header for milliseconds,
        # which is more precise than integer-seconds `retry-after`
        try:
            retry_ms_header = response_headers.get("retry-after-ms", None)
            return float(retry_ms_header) / 1000
        except (TypeError, ValueError):
            pass

        # Next, try parsing `retry-after` header as seconds (allowing nonstandard floats).
        retry_header = response_headers.get("retry-after")
        try:
            # note: the spec indicates that this should only ever be an integer
            # but if someone sends a float there's no reason for us to not respect it
            return float(retry_header)
        except (TypeError, ValueError):
            pass

        # Last, try parsing `retry-after` as a date.
        retry_date_tuple = email.utils.parsedate_tz(retry_header)
        if retry_date_tuple is None:
            return None

        retry_date = email.utils.mktime_tz(retry_date_tuple)
        return float(retry_date - time.time())

Subdomains

Calls

Frequently Asked Questions

What does _parse_retry_after_header() do?
_parse_retry_after_header() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_base_client.py.
Where is _parse_retry_after_header() defined?
_parse_retry_after_header() is defined in src/anthropic/_base_client.py at line 741.
What does _parse_retry_after_header() call?
_parse_retry_after_header() calls 1 function(s): get.
What calls _parse_retry_after_header()?
_parse_retry_after_header() is called by 1 function(s): _calculate_retry_timeout.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free