Anthropic SDK for Python 1.2

Last reviewed Oct 28, 2026

Export as PDF

Prompt Details

Prompt Composition

2prompts
  1. Python 3155 lines · 3.8K tokens
  2. 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 Anthropic clients 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; restrict extra_body, extra_query, extra_headers, and with_options() so request overrides cannot bypass these controls or replace Host and authentication headers.
  • For Anthropic and AsyncAnthropic model, Files, batch, and other SDK API requests, allow only reviewed HTTPS scheme/host/port destinations for base_url and only explicitly approved proxy endpoints, including any intentionally used internal proxy. Review ANTHROPIC_BASE_URL, credential-profile URLs, HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY, httpx2 mounts, with_options(), and caller-supplied http_client against 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.