Anthropic Claude 3.5 Sonnet (Oct '24)

October 2024 update of the Claude 3.5 Sonnet model, focusing on poetic and creative responses

Creator: AnthropicLicense: Proprietary

Summary

Artificial Analysis Quality
Index
80
Output Speed (Tokens per
Second)
56
Model Pricing (USD per 1M Tokens)
$6.000
Latency (to receive the first
token)
14.21s
Context Window (tokens)
200k

Comparison with other models

Quality

Artificial Analysis Quality Index; Higher is better

+ Add model

Speed

Output Tokens per Second; Higher is better

+ Add model

Pricing

USD per 1M Tokens; Lower is better

+ Add model

Latency

Seconds to First Tokens Chunk Received; Lower is better

+ Add model

Authentication

API keys

The Anthropic API requires an API key for authentication. You can generate API keys through the Anthropic Console in your Account Settings. Every API request must include a valid API key to access Claude and other Anthropic services.

  1. Console access - Create an Anthropic Console account to get started
  2. Environment variables - The SDKs are designed to automatically use the ANTHROPIC_API_KEY environment variable
  3. Manual configuration - You can also provide the API key directly when initializing the client
1 2 3 # Set your API key as an environment variable export ANTHROPIC_API_KEY='your-api-key-here' # Linux/macOS set ANTHROPIC_API_KEY=your-api-key-here # Windows

Prerequisites

To use the Anthropic API, you'll need:

  • An Anthropic Console account
  • A valid API key
  • Python 3.7+ or TypeScript 4.5+ for SDK usage

While you can make direct HTTP requests to the API, Anthropic provides official SDKs for Python and TypeScript that handle authentication and provide a more convenient developer experience.

Example curl command:

1 2 3 4 curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json"

Example with Python SDK:

1 2 3 4 5 6 7 from anthropic import Anthropic # The SDK will automatically use the ANTHROPIC_API_KEY environment variable client = Anthropic() # Or set the key explicitly client = Anthropic(api_key="your-api-key-here")

Example with Node.js SDK:

1 2 3 4 5 6 7 8 9 import Anthropic from '@anthropic-ai/sdk'; // The SDK will automatically use the ANTHROPIC_API_KEY environment variable const anthropic = new Anthropic(); // Or set the key explicitly const anthropic = new Anthropic({ apiKey: 'your-api-key-here' });

We recommend starting development in the Workbench, a web-based interface to Claude, before integrating the API into your application. The Workbench allows you to experiment with different prompts and see Claude's responses in real-time.

Create Message

POSThttps://api.anthropic.com/v1/messages

Generate AI responses using text and image inputs. The Messages API can be used for both single queries and multi-turn conversations.

Request body

messages array *Required

Input messages representing conversation history. Each message must have a role and content.

model string *Required

The model that will complete your prompt. See models documentation for available options.

max_tokens integer *Required

The maximum number of tokens to generate before stopping. Models may stop before reaching this maximum.

temperature number *Optional

Amount of randomness injected into the response. Defaults to 1.0. Use lower values for analytical tasks and higher for creative ones.

system string *Optional

System prompt to provide context and instructions to Claude.

metadata object *Optional

An object describing metadata about the request.

stream boolean *Optional

Whether to incrementally stream the response using server-sent events.

curl https://api.anthropic.com/v1/messages \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2024-02-20" \ -H "content-type: application/json" \ -d '{ "model": "claude-3-opus-20240229", "max_tokens": 1024, "messages": [ { "role": "user", "content": "Hello!" } ] }'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 { "id": "msg_013MMxgFxMLC9oKk6J6RGmkc", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "Hello! How can I help you today?" } ], "model": "claude-3-opus-20240229", "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 5, "output_tokens": 9 } }