Important for production: Anthropic currently marks Claude Sonnet 4.5 as deprecated: it still works, but is no longer recommended, and is scheduled to retire on November 30, 2026. As of November 9, 2026, that retirement date is 21 days away. For a new production integration, use Anthropic’s recommended replacement, Claude Sonnet 5.5, rather than building on Sonnet 4.5. If you need Sonnet 4.5 for a short-lived test or migration, the direct API setup is below. (platform.claude.com)
Direct Anthropic API details
This example uses Anthropic’s direct Claude API, not Amazon Bedrock, Google Cloud, Microsoft Foundry, or Poe. The direct API base URL is https://api.anthropic.com; the Messages API endpoint is POST /v1/messages. Use the Sonnet 4.5 API model ID claude-sonnet-4-5-20250929. Anthropic also lists claude-sonnet-4-5 as an API alias. These differ from the model IDs used on other platforms, so don’t substitute a Bedrock, Google Cloud, or Poe ID in this direct-API request. (platform.claude.com)
Prerequisites and API key
You’ll need a Claude Console account and an API key. For the Python example, use Python 3.10 or later and install Anthropic’s Python SDK. Keep the key in an environment variable instead of putting it in your source code or committing it to version control. (platform.claude.com)
python -m pip install anthropic
export ANTHROPIC_API_KEY="your-api-key"
Set the environment variable in your shell or secret manager. Replace the placeholder with your key; never publish a real key in code, logs, or a public repository.
Make a first request
Save this as sonnet45_first_request.py and run it in the same environment where ANTHROPIC_API_KEY is set:
from anthropic import Anthropic
client = Anthropic() # Reads ANTHROPIC_API_KEY from the environment
message = client.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=512,
messages=[
{"role": "user", "content": "Reply with a short greeting."}
],
)
for block in message.content:
if block.type == "text":
print(block.text)
The SDK’s default client reads ANTHROPIC_API_KEY, and messages.create sends the request to the Messages API. The model ID above is Anthropic’s direct API ID. max_tokens=512 sets the maximum output for this example; it is not a statement of the model’s maximum output limit. On success, the response contains content blocks; the loop prints the text from each text block. (platform.claude.com)
The equivalent raw HTTP route is POST https://api.anthropic.com/v1/messages. Use Anthropic’s official SDK when you want it to handle the request structure and response object; consult the Messages API reference if you are implementing HTTP directly. (platform.claude.com)
Price and limits
Anthropic lists Sonnet 4.5’s direct API price as $3 per million input tokens and $15 per million output tokens. Its model reference lists a 200,000-token context window and 64,000-token maximum output. These are Anthropic API figures; cloud providers and other gateways can have different billing and limits. (platform.claude.com)
Should you use Sonnet 4.5 for a new integration?
Usually, no. Anthropic’s model reference says Sonnet 4.5 remains functional but is deprecated, is no longer recommended, and retires on November 30, 2026. Anthropic identifies Sonnet 5.5 as the current Sonnet model and recommended replacement. If you’re maintaining an existing integration, plan and test a migration before the retirement date; for new production work, start with the current model instead. (platform.claude.com)
If you intended to use Amazon Bedrock, Google Cloud, Microsoft Foundry, or Poe, follow that provider’s instructions and model ID instead. Their identifiers and authentication setup are not interchangeable with Anthropic’s direct API configuration. (platform.claude.com)
Sources
Claude Sonnet 4.5 — Claude Platform Docs
API overview — Claude Platform Docs
Create a Message — Claude API Reference
