Anthropic SDK for Python 1.2
Last reviewed Oct 28, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- Anthropic SDK for Python 1.264 lines · 2K tokens
Total219 lines · 5.8K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 78
- 79
- 89
- 95
- 117
- 201
- 208
- 209
- 214
- 250
- 294
- 295
- 319
- 328
- 338
- 347
- 367
- 379
- 409
- 416
- 426
- 427
- 459
- 470
- 502
- 532
- 611
- 639
- 674
- 732
- 770
- 772
- 776
- 829
- 862
- 916
- 918
- 922
- 1104
- 1333
- 1395
- 1426
- 1427
Prompt Preview
Apply the Python 3 baseline first. These rules cover Anthropic SDK for Python 1.2 credentials, Messages API construction, tool use, streaming, files, retries, errors, and production controls.
Client and credentials
- Construct
Anthropicclients from server-side secrets or a workload secret provider and never expose API keys to browsers or mobile clients. - Keep
base_url, proxy, custom transport, credential profiles, middleware, and default-header settings fixed in trusted configuration; restrictextra_body,extra_query,extra_headers, andwith_options()so request overrides cannot bypass these controls or replaceHostand authentication headers. - For
AnthropicandAsyncAnthropicmodel, Files, batch, and other SDK API requests, allow only reviewed HTTPS scheme/host/port destinations forbase_urland only explicitly approved proxy endpoints, including any intentionally used internal proxy. ReviewANTHROPIC_BASE_URL, credential-profile URLs,HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY,httpx2mounts,with_options(), and caller-suppliedhttp_clientagainst the same policy. - Enforce the SDK request policy in the sync and async transport, egress proxy, and network controls: for each direct connection, resolve the destination and connect only to an approved address while retaining TLS hostname verification; reject loopback, private, link-local, multicast, and metadata addresses. Check an approved internal proxy's exact endpoint, require it to enforce the upstream destination and resolved-address policy, and block routes that bypass it.