Skip to content
Anthropic logo

Claude Opus 4.8

Text GenerationAnthropicProxied

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 Window1,000,000 tokens
Terms and Licenselink
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
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)
# The Three Laws of Thermodynamics

There are actually **four** laws when you include the "Zeroth Law," but here are the three classic laws (I'll mention the zeroth too for completeness):

## 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 (Conservation of Energy)
Energy cannot be created or destroyed, only transformed from one form to another. The change in a system's internal energy equals the heat added to it minus the work it does.

**Equation:** ΔU = Q − W

*In simple terms:* You can't get something for nothing—energy is always conserved.

## Second Law (Entropy)
The total entropy (disorder) of an isolated system always increases over time. Heat naturally flows from hot to cold, never spontaneously the reverse.

*In simple terms:* Things naturally tend toward disorder, and you can't build a perfectly efficient engine.

## 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.

*In simple terms:* You can't actually reach absolute zero.

---

**A popular humorous summary:**
1. You can't win (energy is conserved)
2. You can't break even (entropy always increases)
3. You can't quit the game (can't reach absolute zero)

Let me know if you'd like a deeper explanation of any of these!

Examples

With System Message — Using a system message to set context
TypeScript
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)
# Reading a JSON File in Python

Python's built-in `json` module makes this easy. Here's how:

## Basic Method

```python
import json

with open('data.json', 'r') as file:
    data = json.load(file)

print(data)
```

- `json.load()` reads from a **file object** and parses the JSON into a Python object (usually a `dict` or `list`).
- Using `with open(...)` ensures the file is closed automatically.

## Specifying Encoding (Recommended)

It's good practice to specify the encoding explicitly:

```python
import json

with open('data.json', 'r', encoding='utf-8') as file:
    data = json.load(file)
```

## Reading from a JSON String

If you have JSON as a **string** instead of a file, use `json.loads()` (note the `s` for "string"):

```python
import json

json_string = '{"name": "Alice", "age": 30}'
data = json.loads(json_string)

print(data['name'])  # Alice
```

## Handling Errors

It's wise to handle potential issues:

```python
import json

try:
    with open('data.json', 'r', encoding='utf-8') as file:
        data = json.load(file)
except FileNotFoundError:
    print("The file was not found.")
except json.JSONDecodeError:
    print("The file contains invalid JSON.")
```

## Quick Reference

| Function | Use Case |
|----------|----------|
| `json.load(file)` | Read from a file object |
| `json.loads(string)` | Parse from a string |
| `json.dump(obj, file)` | Write to a file |
| `json.dumps(obj)` | Convert to a string |

Let me know if you'd like help **writing** JSON or working with a specific data structure!
Multi-turn Conversation — Continuing a conversation with context
TypeScript
const response = await env.AI.run(
'anthropic/claude-opus-4.8',
{
max_tokens: 1024,
messages: [
{
content: 'I need help planning a road trip from San Francisco to Los Angeles.',
role: 'user',
},
{
content:
"I'd be happy to help! The drive is about 380 miles and takes roughly 5-6 hours. Would you like suggestions for scenic routes or interesting stops along the way?",
role: 'assistant',
},
{ content: 'Yes, what are some good places to stop?', role: 'user' },
],
},
)
console.log(response)
Here are some great stops along the way, depending on which route you take:

## If You Take Highway 1 (Pacific Coast Highway) — Scenic but Slower
This route adds time but offers stunning coastal views.

- **Santa Cruz** – Beach boardwalk, classic seaside vibe
- **Monterey** – World-famous aquarium, Cannery Row
- **Carmel-by-the-Sea** – Charming village, beautiful beaches
- **Big Sur** – Dramatic cliffs, Bixby Bridge, hiking (a must-see!)
- **Hearst Castle** (San Simeon) – Opulent historic estate, tours available
- **Pismo Beach** – Sand dunes, laid-back beach town

## If You Take Highway 101 — Balanced Option
Faster than Highway 1 but still scenic in parts.

- **Gilroy** – The "Garlic Capital," outlet shopping
- **Paso Robles** – Excellent wine country
- **San Luis Obispo** – Cute college town, good food
- **Santa Barbara** – Beautiful "American Riviera," Spanish architecture, wineries

## If You Take Interstate 5 — Fastest Route
The quickest way (about 5-6 hours) but mostly flat farmland with little scenery.

- **Kettleman City** – Main rest/fuel stop
- Not many attractions, but great if you're short on time

---

A few questions to help me refine suggestions:
1. **How much time** do you have for the trip? (One day or multiple?)
2. **What interests you most** — nature, food, beaches, history?
3. Are you traveling **solo, as a couple, or with family/kids**?

Let me know and I can help build an itinerary!
Creative Writing with Adaptive Thinking — Use adaptive thinking with high effort to steer creative output -- the recommended replacement for the deprecated `temperature` parameter.
TypeScript
const response = await env.AI.run(
'anthropic/claude-opus-4.8',
{
max_tokens: 2048,
messages: [
{
content: 'Write a short story opening about a detective finding an unusual clue.',
role: 'user',
},
],
output_config: { effort: 'high' },
thinking: { type: 'adaptive' },
},
)
console.log(response)
Detective Mara Voss had seen blood spatter shaped like everything from constellations to corporate logos, but she'd never seen a crime scene that smelled like oranges.

She paused in the doorway of the dead man's study, notebook half-raised, and breathed in again. Citrus, bright and unmistakable, layered over the expected copper tang. No fruit bowl. No air freshener. No candle that she could see.

"You smell that?" she asked.

Behind her, Officer Reyes shrugged. "Smell what?"

Mara stepped carefully around the chalk-pale shape on the hardwood—Gerald Finch, sixty-three, retired accountant, found by his housekeeper at seven that morning. The scent grew stronger as she approached the desk, and there, beneath the man's outstretched right hand, she found it.

A single dried orange peel, curled into a tight spiral, placed deliberately atop a blank sheet of paper.

Not dropped. Not discarded. *Placed.* The spiral wound clockwise, perfectly even, the way a person might twist a peel if they had all the time in the world and very steady hands.

Mara crouched, knees popping, and studied it without touching. Gerald Finch lived alone. Gerald Finch, according to three separate neighbors, was allergic to citrus.

So the question wasn't who had killed him.

The question was who had sat here, calm as a churchgoer, peeling an orange beside a dying man—and why they'd wanted her to know it.
Streaming Response — Enable streaming for real-time output
TypeScript
const response = await env.AI.run(
'anthropic/claude-opus-4.8',
{
max_tokens: 1024,
messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
stream: true,
},
)
console.log(response)

Parameters

max_tokens
numberrequiredexclusiveMinimum: 0
stream
boolean
system
string

API Schemas (Raw)

Input
Output