Claude Opus 4.8
Text Generation • Anthropic
anthropic/claude-opus-4.8
- Third-party
- Zero data retention
Claude Opus 4.8 is Anthropic's most capable generally available model, with a step-change improvement in agentic coding over Claude Opus 4.7. It uses adaptive thinking to calibrate reasoning per task and supports a one million token context window at standard pricing.
| Model Info | |
|---|---|
| Context Window ↗ | 1,000,000 tokens |
| Terms and License | link ↗ |
| More information | link ↗ |
| Zero data retention | Yes |
| Request formats | Anthropic Messages |
| Pricing | <ul><li>Input (per 1M tokens)$5.00</li><li>Output (per 1M tokens)$25.00</li><li>Cached input (per 1M tokens)$0.50</li><li>Cache creation (per 1M tokens)$6.25</li></ul> |
Usage
const response = await env.AI.run(
'anthropic/claude-opus-4.8',
{
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-opus-4.8",
"max_tokens": 1024,
"messages": [
{
"content": "What are the three laws of thermodynamics?",
"role": "user"
}
]
}'
# The Three Laws of Thermodynamics
## First Law (Conservation of Energy)
Energy cannot be created or destroyed, only transferred or converted from one form to another. The total energy of an isolated system remains constant.
**Common expression:** ΔU = Q − W
- ΔU = change in internal energy
- Q = heat added to the system
- W = work done by the system
## Second Law (Entropy)
The total entropy (disorder) of an isolated system always increases over time, or remains constant in ideal reversible processes. Heat naturally flows from hot to cold, never spontaneously the reverse.
**Key implications:**
- No process is 100% efficient
- Perpetual motion machines are impossible
- The universe tends toward greater disorder
## Third Law (Absolute Zero)
As a system approaches absolute zero (0 Kelvin, −273.15°C), its entropy approaches a minimum constant value. It's impossible to reach absolute zero in a finite number of steps.
---
**A popular informal summary:**
1. You can't win (you can't get more energy out than you put in)
2. You can't break even (you'll always lose some energy to entropy)
3. You can't quit the game (you can't reach absolute zero)
*Note:* There's also a **Zeroth Law**, which states that if two systems are each in thermal equilibrium with a third system, they are in equilibrium with each other—this establishes the concept of temperature.
Would you like a deeper explanation of any particular law?
{
"id": "msg_01UPuL7ZtkoyKHmCsNtxyamj",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "# The Three Laws of Thermodynamics\n\n## First Law (Conservation of Energy)\nEnergy cannot be created or destroyed, only transferred or converted from one form to another. The total energy of an isolated system remains constant.\n\n**Common expression:** ΔU = Q − W\n- ΔU = change in internal energy\n- Q = heat added to the system\n- W = work done by the system\n\n## Second Law (Entropy)\nThe total entropy (disorder) of an isolated system always increases over time, or remains constant in ideal reversible processes. Heat naturally flows from hot to cold, never spontaneously the reverse.\n\n**Key implications:**\n- No process is 100% efficient\n- Perpetual motion machines are impossible\n- The universe tends toward greater disorder\n\n## Third Law (Absolute Zero)\nAs a system approaches absolute zero (0 Kelvin, −273.15°C), its entropy approaches a minimum constant value. It's impossible to reach absolute zero in a finite number of steps.\n\n---\n\n**A popular informal summary:**\n1. You can't win (you can't get more energy out than you put in)\n2. You can't break even (you'll always lose some energy to entropy)\n3. You can't quit the game (you can't reach absolute zero)\n\n*Note:* There's also a **Zeroth Law**, which states that if two systems are each in thermal equilibrium with a third system, they are in equilibrium with each other—this establishes the concept of temperature.\n\nWould you like a deeper explanation of any particular law?"
}
],
"model": "claude-opus-4-8",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 20,
"output_tokens": 493
},
"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-opus-4.8',
{
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.',
},
)
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-opus-4.8",
"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."
}'
````
Reading a JSON File in Python
Python's built-in json module makes this straightforward.
Basic Method
import json
with open('data.json', 'r') as file:
data = json.load(file)
print(data)
json.load()reads from a file object- The
withstatement automatically closes the file
Reading from a JSON String
If you have JSON as a string (not a file), use json.loads() (note the "s" for "string"):
import json
json_string = '{"name": "Alice", "age": 30}'
data = json.loads(json_string)
print(data['name']) # Alice
Example with Error Handling
import json
try:
with open('data.json', 'r', encoding='utf-8') as file:
data = json.load(file)
print(data)
except FileNotFoundError:
print("The file was not found.")
except json.JSONDecodeError:
print("The file contains invalid JSON.")
How JSON Maps to Python
| JSON | Python |
|---|---|
| object | dict |
| array | list |
| string | str |
| number (int) | int |
| number (real) | float |
| true / false | True / False |
| null | None |
Accessing the Data
```python
