MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / Anthropic

Class Anthropic

src/anthropic/_client.py:134–548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132
133
134class Anthropic(SyncAPIClient):
135 # client options
136 api_key: str | None
137 auth_token: str | None
138 webhook_key: str | None
139 credentials: AccessTokenProvider | None
140 _token_cache: TokenCache | None
141 _custom_auth: AccessTokenAuth | None
142
143 # constants
144 HUMAN_PROMPT = _constants.HUMAN_PROMPT
145 AI_PROMPT = _constants.AI_PROMPT
146
147 def __init__(
148 self,
149 *,
150 api_key: str | None = None,
151 auth_token: str | None = None,
152 credentials: AccessTokenProvider | None = None,
153 config: Mapping[str, Any] | None = None,
154 profile: str | None = None,
155 webhook_key: str | None = None,
156 base_url: str | httpx.URL | None = None,
157 timeout: float | Timeout | None | NotGiven = not_given,
158 max_retries: int = DEFAULT_MAX_RETRIES,
159 default_headers: Mapping[str, str] | None = None,
160 default_query: Mapping[str, object] | None = None,
161 # Configure a custom httpx client.
162 # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
163 # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
164 http_client: httpx.Client | None = None,
165 middleware: Sequence[MiddlewareInput] | None = None,
166 # Enable or disable schema validation for data returned by the API.
167 # When enabled an error APIResponseValidationError is raised
168 # if the API responds with invalid data for the expected schema.
169 #
170 # This parameter may be removed or changed in the future.
171 # If you rely on this feature, please open a GitHub issue
172 # outlining your use-case to help us decide if it should be
173 # part of our public interface in the future.
174 _strict_response_validation: bool = False,
175 _token_cache: TokenCache | None | NotGiven = not_given,
176 ) -> None:
177 """Construct a new synchronous Anthropic client instance.
178
179 Credentials are resolved in the following order (first match wins):
180
181 1. Explicit constructor arguments — ``api_key=``, ``auth_token=``,
182 ``credentials=``, ``config=``, or ``profile=``. When any of these
183 is passed, environment variables are not consulted for credentials.
184 2. ``ANTHROPIC_API_KEY`` / ``ANTHROPIC_AUTH_TOKEN`` environment
185 variables.
186 3. ``ANTHROPIC_PROFILE`` environment variable — loads the named
187 profile from ``<config_dir>/configs/<profile>.json``.
188 4. Workload identity federation environment variables —
189 ``ANTHROPIC_IDENTITY_TOKEN[_FILE]`` +
190 ``ANTHROPIC_FEDERATION_RULE_ID`` + ``ANTHROPIC_ORGANIZATION_ID``.
191 5. The active profile on disk — the profile named by

Calls

no outgoing calls