Show answerHide answer
Correct answer: B Use the Claude Python SDK and let it handle authentication, retries, and response parsing through its standard documented patterns for Python integrations.
Explanation
ExplanationThe Claude Python SDK (anthropic) is the purpose-built client for Python applications, and it owns the concerns you'd otherwise reimplement: authentication (defaults to the ANTHROPIC_API_KEY environment variable), typed response parsing, and automatic retries with exponential backoff for transient failures (rate limits, 5xx errors, connection issues), defaulting to two retries and honoring retry-after headers. It also raises typed exceptions (e.g., RateLimitError, AuthenticationError) rather than returning raw error JSON, so your application can handle failures programmatically.
The standard documented pattern is exactly the straightforward one: instantiate Anthropic() (the API key is read from the environment by default), then call client.messages.create(...). Using the SDK means your integration code focuses on the application's logic — prompt construction, handling the response, and business behavior — while the SDK maintains the transport layer, parsing, and retry policy consistently.
Why the other options are incorrect
- A — "Call the REST API directly with raw HTTP": Reimplements everything the SDK already provides (auth, retries, parsing, typed errors) and creates a maintenance burden with no benefit; the SDK is the documented integration path.
- C — "Use another provider's SDK and translate responses": Introduces a translation layer that adds fragility and complexity for no gain — you'd be fighting the wrong API shape and losing Claude-specific error semantics.
- D — "Embed Claude calls in shell commands invoked from Python": Moves the integration outside the Python process, losing typed errors, structured parsing, and retry handling — an ad-hoc approach that's harder to test, debug, and maintain.
The tested distinction: use the purpose-built SDK (managed auth, retries, parsing, typed errors) vs. raw HTTP, cross-provider translation, or shelling out.
References
- Claude Platform, Python SDK — installation, Anthropic() client with ANTHROPIC_API_KEY default, client.messages.create().