Claude Sonnet 4.6

Text Generation • Anthropic

anthropic/claude-sonnet-4.6

  • Third-party
  • Zero data retention

Claude Sonnet 4.6 is Anthropic's latest balanced model offering strong coding, reasoning, and agentic capabilities with improved instruction following.

Model Info
Context Window ↗ 200,000 tokens
Terms and License link ↗
More information link ↗
Zero data retention Yes
Request formats Anthropic Messages
Pricing <ul><li>Input (per 1M tokens)$3.00</li><li>Output (per 1M tokens)$15.00</li><li>Cached input (per 1M tokens)$0.30</li><li>Cache creation (per 1M tokens)$3.75</li></ul>

Usage

const response = await env.AI.run(
  'anthropic/claude-sonnet-4.6',
  {
    max_tokens: 1024,
    messages: [{ content: 'What are the three laws of thermodynamics?', role: 'user' }],
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/messages \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "anthropic/claude-sonnet-4.6",
  "max_tokens": 1024,
  "messages": [
    {
      "content": "What are the three laws of thermodynamics?",
      "role": "user"
    }
  ]
}'
There are actually **four** laws of thermodynamics (including the Zeroth Law):

## The Laws of Thermodynamics

**Zeroth Law**
If two systems are each in thermal equilibrium with a third system, they are in thermal equilibrium with each other. (This establishes the concept of temperature.)

**First Law**
Energy cannot be created or destroyed, only converted from one form to another. (Conservation of energy)

**Second Law**
Entropy of an isolated system tends to increase over time. Heat naturally flows from hot to cold, not the reverse. (No perfectly efficient engine is possible.)

**Third Law**
As temperature approaches absolute zero, the entropy of a perfect crystal approaches zero. It is impossible to reach absolute zero in a finite number of steps.

---

The laws are often summarized humorously as:
- **You can't win** (can't get more energy out than you put in)
- **You can't break even** (you always lose some energy to entropy)
- **You can't quit the game** (you can never reach absolute zero)

Would you like more detail on any of these?
{
  "id": "msg_015bDPjJ5vm4gY4EH7pALCsh",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "There are actually **four** laws of thermodynamics (including the Zeroth Law):\n\n## The Laws of Thermodynamics\n\n**Zeroth Law**\nIf two systems are each in thermal equilibrium with a third system, they are in thermal equilibrium with each other. (This establishes the concept of temperature.)\n\n**First Law**\nEnergy cannot be created or destroyed, only converted from one form to another. (Conservation of energy)\n\n**Second Law**\nEntropy of an isolated system tends to increase over time. Heat naturally flows from hot to cold, not the reverse. (No perfectly efficient engine is possible.)\n\n**Third Law**\nAs temperature approaches absolute zero, the entropy of a perfect crystal approaches zero. It is impossible to reach absolute zero in a finite number of steps.\n\n---\n\nThe laws are often summarized humorously as:\n- **You can't win** (can't get more energy out than you put in)\n- **You can't break even** (you always lose some energy to entropy)\n- **You can't quit the game** (you can never reach absolute zero)\n\nWould you like more detail on any of these?"
    }
  ],
  "model": "claude-sonnet-4-6",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 17,
    "output_tokens": 252
  },
  "stop_sequence": null,
  "stop_details": null,
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

Examples

<details>

<summary>With System Message — Using a system message to set context</summary>

const response = await env.AI.run(
  'anthropic/claude-sonnet-4.6',
  {
    max_tokens: 1024,
    messages: [{ content: 'How do I read a JSON file in Python?', role: 'user' }],
    system: 'You are a helpful coding assistant specializing in Python.',
    temperature: 0.3,
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/messages \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "anthropic/claude-sonnet-4.6",
  "max_tokens": 1024,
  "messages": [
    {
      "content": "How do I read a JSON file in Python?",
      "role": "user"
    }
  ],
  "system": "You are a helpful coding assistant specializing in Python.",
  "temperature": 0.3
}'

````

Reading a JSON File in Python

Basic Method using json module

```python import json