Home / File/ _client.py — anthropic-sdk-python Source File

_client.py — anthropic-sdk-python Source File

Architecture documentation for _client.py, a python file in the anthropic-sdk-python codebase. 24 imports, 2 dependents.

File python AnthropicClient SyncAPI 24 imports 2 dependents 2 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157["_client.py"]
  572af293_51f2_fb95_d24e_acc5aa707af1["572af293:51f2:fb95:d24e:acc5aa707af1"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> 572af293_51f2_fb95_d24e_acc5aa707af1
  fcb8b576_e5db_1acf_9312_20be91e2e300["_beta.py"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> fcb8b576_e5db_1acf_9312_20be91e2e300
  b803cef5_e7f2_93b7_3565_b4b0dad7daef["Beta"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> b803cef5_e7f2_93b7_3565_b4b0dad7daef
  89b7a5c3_e0ee_08cb_29c0_c570ef6cc7a6["AsyncBeta"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> 89b7a5c3_e0ee_08cb_29c0_c570ef6cc7a6
  d8d7efa2_bafb_5415_37ac_4e40a6912a12["_types"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> d8d7efa2_bafb_5415_37ac_4e40a6912a12
  da7ce3bd_4934_ff39_8877_5ba81a168358["_utils"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> da7ce3bd_4934_ff39_8877_5ba81a168358
  dcfeea51_e36b_f1d6_e3e7_7a8f2e20bf59["_compat"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> dcfeea51_e36b_f1d6_e3e7_7a8f2e20bf59
  b3f1122f_559d_b234_c271_aa7f8ec4416c["_version"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> b3f1122f_559d_b234_c271_aa7f8ec4416c
  597ca033_023a_d6d2_0dc5_e7dacc60a056["_streaming"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> 597ca033_023a_d6d2_0dc5_e7dacc60a056
  3c0c5ff4_32ba_8657_2f3f_8c62133d805c["_exceptions"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> 3c0c5ff4_32ba_8657_2f3f_8c62133d805c
  9bba80dc_a498_2f88_8043_9cbe818e360e["_base_client"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> 9bba80dc_a498_2f88_8043_9cbe818e360e
  91a12d3e_6b2a_90bd_28df_074cc1d1ad53["_stream_decoder.py"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> 91a12d3e_6b2a_90bd_28df_074cc1d1ad53
  582aef90_700e_ea04_755a_159b23a192d2["AWSEventStreamDecoder"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> 582aef90_700e_ea04_755a_159b23a192d2
  f76889f6_9b58_6c75_ce69_ae423d228ec5["resources.messages"]
  cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 --> f76889f6_9b58_6c75_ce69_ae423d228ec5
  style cbdd42fd_75f9_7cc6_3f3b_b8d939e4c157 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import os
import logging
import urllib.parse
from typing import Any, Union, Mapping, TypeVar
from typing_extensions import Self, override

import httpx

from ... import _exceptions
from ._beta import Beta, AsyncBeta
from ..._types import NOT_GIVEN, Timeout, NotGiven
from ..._utils import is_dict, is_given
from ..._compat import model_copy
from ..._version import __version__
from ..._streaming import Stream, AsyncStream
from ..._exceptions import AnthropicError, APIStatusError
from ..._base_client import (
    DEFAULT_MAX_RETRIES,
    BaseClient,
    SyncAPIClient,
    AsyncAPIClient,
    FinalRequestOptions,
)
from ._stream_decoder import AWSEventStreamDecoder
from ...resources.messages import Messages, AsyncMessages
from ...resources.completions import Completions, AsyncCompletions

log: logging.Logger = logging.getLogger(__name__)

DEFAULT_VERSION = "bedrock-2023-05-31"

_HttpxClientT = TypeVar("_HttpxClientT", bound=Union[httpx.Client, httpx.AsyncClient])
_DefaultStreamT = TypeVar("_DefaultStreamT", bound=Union[Stream[Any], AsyncStream[Any]])


def _prepare_options(input_options: FinalRequestOptions) -> FinalRequestOptions:
    options = model_copy(input_options, deep=True)

    if is_dict(options.json_data):
        options.json_data.setdefault("anthropic_version", DEFAULT_VERSION)

        if is_given(options.headers):
            betas = options.headers.get("anthropic-beta")
            if betas:
                options.json_data.setdefault("anthropic_beta", betas.split(","))

    if options.url in {"/v1/complete", "/v1/messages", "/v1/messages?beta=true"} and options.method == "post":
        if not is_dict(options.json_data):
            raise RuntimeError("Expected dictionary json_data for post /completions endpoint")

        model = options.json_data.pop("model", None)
        model = urllib.parse.quote(str(model), safe=":")
        stream = options.json_data.pop("stream", False)
        if stream:
            options.url = f"/model/{model}/invoke-with-response-stream"
        else:
            options.url = f"/model/{model}/invoke"

// ... (353 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does _client.py do?
_client.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, SyncAPI subdomain.
What functions are defined in _client.py?
_client.py defines 2 function(s): _infer_region, _prepare_options.
What does _client.py depend on?
_client.py imports 24 module(s): 572af293:51f2:fb95:d24e:acc5aa707af1, AWSEventStreamDecoder, AsyncBeta, Beta, _auth.py, _base_client, _beta.py, _compat, and 16 more.
What files import _client.py?
_client.py is imported by 2 file(s): __init__.py, _stream.py.
Where is _client.py in the architecture?
_client.py is located at src/anthropic/lib/bedrock/_client.py (domain: AnthropicClient, subdomain: SyncAPI, directory: src/anthropic/lib/bedrock).

Analyze Your Own Codebase

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

Try Supermodel Free