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

_validate_headers() — anthropic-sdk-python Function Reference

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

Function python AnthropicClient AsyncAPI calls 2 called by 1

Entity Profile

Dependency Diagram

graph TD
  0372babc_e638_749f_3e24_5996dba8d7fa["_validate_headers()"]
  0517492b_78c2_27e9_22ae_aae3b5f0e93e["Anthropic"]
  0372babc_e638_749f_3e24_5996dba8d7fa -->|defined in| 0517492b_78c2_27e9_22ae_aae3b5f0e93e
  5e0238dc_6349_2bf4_d30e_5166a92c3219["_validate_headers()"]
  5e0238dc_6349_2bf4_d30e_5166a92c3219 -->|calls| 0372babc_e638_749f_3e24_5996dba8d7fa
  5e0238dc_6349_2bf4_d30e_5166a92c3219["_validate_headers()"]
  0372babc_e638_749f_3e24_5996dba8d7fa -->|calls| 5e0238dc_6349_2bf4_d30e_5166a92c3219
  afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7["get()"]
  0372babc_e638_749f_3e24_5996dba8d7fa -->|calls| afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7
  style 0372babc_e638_749f_3e24_5996dba8d7fa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_client.py lines 185–198

    def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
        if headers.get("Authorization") or headers.get("X-Api-Key"):
            # valid
            return

        if headers.get("X-Api-Key") or isinstance(custom_headers.get("X-Api-Key"), Omit):
            return

        if headers.get("Authorization") or isinstance(custom_headers.get("Authorization"), Omit):
            return

        raise TypeError(
            '"Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the `X-Api-Key` or `Authorization` headers to be explicitly omitted"'
        )

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free