Skip to content
Anthropic logo

Claude Fable 5

Text GenerationAnthropic

Claude Fable 5 is Anthropic's most capable widely released model, built for the most demanding reasoning and long-horizon agentic work. Adaptive thinking is always on, and the model supports a 1M token context window with up to 128k output tokens per request.

Model Info
Context Window1,000,000 tokens
Terms and Licenselink
More informationlink
Request formatsAnthropic Messages
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
const response = await env.AI.run(
'anthropic/claude-fable-5',
{
max_tokens: 1024,
messages: [{ content: 'What are the three laws of thermodynamics?', role: 'user' }],
},
)
console.log(response)
# The Three Laws of Thermodynamics

## First Law: Conservation of Energy
Energy cannot be created or destroyed—only converted from one form to another. The total energy of an isolated system remains constant.

**Formula:** ΔU = Q − W (change in internal energy = heat added − work done by the system)

**Example:** When you burn fuel in an engine, chemical energy converts to heat and mechanical work, but the total energy is conserved.

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

**Key implications:**
- No heat engine can be 100% efficient
- Natural processes are irreversible
- It explains why time seems to have a direction ("arrow of time")

**Example:** An ice cube melts in warm water, but you'll never see warm water spontaneously form an ice cube.

## Third Law: Absolute Zero
As a system approaches absolute zero (0 Kelvin, or −273.15°C), its entropy approaches a minimum constant value. It's impossible to reach absolute zero in a finite number of steps.

**Example:** Scientists can get extremely close to absolute zero (billionths of a degree above), but never quite reach it.

---

**Bonus — The Zeroth Law:** Added later but considered more fundamental: if two systems are each in thermal equilibrium with a third system, they're in equilibrium with each other. This is what makes thermometers work!

A popular summary: *"You can't win (1st), you can't break even (2nd), and you can't quit the game (3rd)."*

Examples

With System Message — Using a system message to set context
TypeScript
const response = await env.AI.run(
'anthropic/claude-fable-5',
{
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

Use the built-in `json` module with the `json.load()` function:

```python
import json

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

print(data)
```

## Key Points

- **`json.load(file)`** — reads JSON from a *file object*
- **`json.loads(string)`** — parses JSON from a *string* (note the "s")
- The `with` statement automatically closes the file when done

## Accessing the Data

JSON objects become Python dictionaries, and JSON arrays become lists:

```python
# Given data.json:
# {
#   "name": "Alice",
#   "age": 30,
#   "hobbies": ["reading", "coding"]
# }

print(data["name"])        # Alice
print(data["age"])         # 30
print(data["hobbies"][0])  # reading
```

## Handling Errors

```python
import json

try:
    with open("data.json", "r", encoding="utf-8") as file:
        data = json.load(file)
except FileNotFoundError:
    print("File not found.")
except json.JSONDecodeError as e:
    print(f"Invalid JSON: {e}")
```

## Type Conversions

| JSON | Python |
|------|--------|
| object | `dict` |
| array | `list` |
| string | `str` |
| number | `int` / `float` |
| `true` / `false` | `True` / `False` |
| `null` | `None` |

That's all you need for most use cases. For very large files, consider streaming libraries like `ijson`.
Multi-turn Conversation — Continuing a conversation with context
TypeScript
const response = await env.AI.run(
'anthropic/claude-fable-5',
{
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)
Great question! Your stops depend a lot on which route you take, so let me break it down:

## Highway 1 / Pacific Coast Highway (Scenic Route)
This adds significant time (10+ hours of driving) but is one of the most beautiful drives in the world:

- **Half Moon Bay** – Charming coastal town, great for breakfast
- **Santa Cruz** – Beach boardwalk and surf culture
- **Monterey & Carmel** – World-class aquarium, scenic 17-Mile Drive
- **Big Sur** – Stunning cliffs, Bixby Bridge, McWay Falls, redwood hikes
- **San Simeon** – Hearst Castle and elephant seal viewing at Piedras Blancas
- **Morro Bay** – Iconic Morro Rock
- **Pismo Beach** – Classic beach town vibes
- **Santa Barbara** – Beautiful Spanish architecture, wine country nearby
- **Malibu** – Beaches and a great way to roll into LA

## Highway 101 (Balanced Option, ~7-8 hours)
- **San Jose** – Winchester Mystery House
- **Gilroy** – Garlic capital (and outlet shopping)
- **Paso Robles** – Excellent wine region
- **San Luis Obispo** – Cute college town, Bubblegum Alley
- **Solvang** – Quirky Danish village with bakeries and windmills
- **Santa Barbara** – Same as above

## I-5 (Fastest, ~5-6 hours)
Honestly, not much to see—mostly farmland. Best stop is **Harris Ranch** in Coalinga for a famous steak lunch.

**My suggestion:** If you have 2+ days, take Highway 1 and stay overnight in Monterey, Big Sur, or San Luis Obispo. If you only have one day, 101 gives you a nice mix of speed and scenery.

How much time do you have for the trip? That'll help narrow down the best plan!
Creative Writing with Adaptive Thinking — Use adaptive thinking with high effort to steer creative output. Adaptive thinking is always on for Claude Fable 5; use the `effort` parameter to control depth.
TypeScript
const response = await env.AI.run(
'anthropic/claude-fable-5',
{
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)
# The Paper Bird

Detective Mara Voss had worked homicide for eleven years, and in that time she'd catalogued every variety of crime scene debris: shell casings, cigarette butts, the sad confetti of torn receipts. But she had never found an origami crane perched in a dead man's open palm.

The victim—Gerald Fitch, fifty-three, accountant—lay sprawled across his kitchen floor as though he'd simply decided to stop standing. No wounds. No struggle. Just the crane, folded from heavy cream paper, balanced on his hand like it had landed there of its own accord.

"Don't touch it," she said, though the rookie behind her hadn't moved. She crouched, knees popping, and angled her flashlight at the paper bird. There—faint lines beneath the folds. Writing.

She photographed it from six angles before lifting it with gloved fingers, and unfolded it wing by wing with the care of someone defusing a bomb. The creases gave up their secret slowly: a single sentence, written in tight, slanted script.

*He counted everything except his sins.*

Mara read it three times. Then she looked back at Gerald Fitch's face—peaceful, almost smug, even in death—and felt the familiar cold prickle at the base of her skull. The one that told her this wasn't an ending.

It was an invitation.
Streaming Response — Enable streaming for real-time output
TypeScript
const response = await env.AI.run(
'anthropic/claude-fable-5',
{
max_tokens: 1024,
messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
stream: true,
},
)
console.log(response)
# Recursion

**Recursion** is a programming concept where a function calls itself to solve a problem by breaking it down into smaller, similar subproblems.

## Key Components

Every recursive function needs two parts:

1. **Base case** — a condition that stops the recursion (prevents infinite loops)
2. **Recursive case** — where the function calls itself with a smaller/simpler input

## Simple Example: Factorial

The factorial of a number `n` (written `n!`) is the product of all positive integers up to `n`:

- `5! = 5 × 4 × 3 × 2 × 1 = 120`

Notice the pattern: `5! = 5 × 4!` — the problem contains a smaller version of itself. Perfect for recursion!

```python
def factorial(n):
    if n <= 1:          # Base case
        return 1
    else:               # Recursive case
        return n * factorial(n - 1)

print(factorial(5))  # Output: 120
```

## How It Unfolds

```
factorial(5)
= 5 × factorial(4)
= 5 × 4 × factorial(3)
= 5 × 4 × 3 × factorial(2)
= 5 × 4 × 3 × 2 × factorial(1)
= 5 × 4 × 3 × 2 × 1      ← base case reached
= 120
```

The calls "stack up" until hitting the base case, then results are multiplied back up the chain.

## An Intuitive Analogy

Imagine you're in a movie theater line and want to know your position. Instead of counting everyone yourself, you ask the person in front of you, "What's your position?" They ask the person in front of them... until someone at the front says "I'm first!" (base case). Then each person adds 1 and passes the answer back.

## When to Use Recursion

Recursion shines for naturally recursive structures like:
- Tree traversal
- Directory/file systems
- Divide-and-conquer algorithms (e.g., merge sort)

⚠️ **Caution:** Without a proper base case, recursion runs forever and causes a *stack overflow*.

Parameters

max_tokens
numberrequiredexclusiveMinimum: 0
system
string
stream
boolean

API Schemas (Raw)

Input
Output