Skip to content
Anthropic logo

Claude Fable 5.2

Text Generation • Anthropic

Model ID

Use with the Workers AI binding, the AI Gateway REST API, or the Unified API.

Calling the provider directly? Use the provider's model name instead, including with provider-native endpoints or the provider's own SDK. For example, Anthropic's name for anthropic/claude-opus-4.8 is claude-opus-4-8.

  • Third-party

Claude Fable 5.2 is built for demanding reasoning and long-horizon agentic work, with adaptive thinking, a 1M token context window, and up to 128K output tokens.

Model Info
Context Window ↗1,000,000 tokens
Terms and Licenselink ↗
More informationlink ↗
Request formatsAnthropic Messages
Pricing
  • Input (per 1M tokens)$8.00
  • Cached input (per 1M tokens)$0.20
  • Cache creation (per 1M tokens)$10.00
  • Output (per 1M tokens)$40.00

Usage

const response = await env.AI.run(
  'anthropic/claude-fable-5.2',
  {
    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-fable-5.2",
  "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."
}'
Use the built-in `json` module:

```python
import json

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

print(data)
```

`json.load()` parses the file into Python objects: JSON objects become `dict`s, arrays become `list`s, and strings, numbers, booleans, and `null` become `str`, `int`/`float`, `bool`, and `None`.

**Accessing the data**

```python
# Given: {"name": "Alice", "skills": ["Python", "SQL"]}
print(data["name"])        # Alice
print(data["skills"][0])   # Python
```

**Handling common errors**

```python
import json

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

**Tips**

- Use `json.load(f)` for a file object and `json.loads(s)` for a string.
- To write JSON back to a file, use `json.dump(data, f, indent=2)`.
- If your file has one JSON object per line (JSON Lines, `.jsonl`), parse it line by line:

  ```python
  with open("data.jsonl", encoding="utf-8") as f:
      records = [json.loads(line) for line in f]
  ```
{
  "model": "claude-fable-5-2",
  "id": "msg_011CgsuBy7YD3SdLFBeFswvH",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "CAQSrwUKEAgTGAI4AUIIdGhpbmtpbmcSDKSIJLl+xWkT9SHrMxoMG4TBjLreVuPOFLKpIjCmvEYg45oRWbtnwo7Cl4w2BAnhnuajXGMmXrEtS0oZqlgNyoiMoDdPeNnC0XlLKyQqzARe2l67RwLuKchg1RsCy5Src7C+V+Tz52I2UkHz3vbKNDxC5KgEkj7V7X7golGAUf6Tcx0gUBLbyQiqJBuyWLqcKieM/QfcWaMoNbJ4VtS5sXZiD3pAl2EPkJh4e/E4Yppq4O/MjMlKlTg5lxwWJ4bpDP1qyMFbmAQM7EfDByWKaRZap+1lPYm7f7JKLtTZM+5Q+b/LNWAF1d5UkaQPbX485JjiQNX2GNqxGoAg/IAypOjp3U5FQP9OIj+HGXtQOIArV/eBqrQUgQu6En0ecOFxAv6kIHM0MSaLb3V3cLmBqAPCzf4+PEYqYUrO9wZ75nxvl6QZConTpPW+llA8v2181t7mpkMT6Z5Gspj6r50jNMDqwj0IASz/38cpBcvao5ao7C2QoK3aDuJBXsilfIeZzhmj0NTstS4Y2B3VhkzVuWrbJIosJ7dnfCCuAQUbha3VS2DZ43Hmv4tvMZ2Sx/1vGLZ1Wou7QhmWXsOWj9ncLfir3FGT0NuQy+AqLLW/lZzzjvoOcj29LpRSUwg8rmFNak2ljC66IbmD8fBmuk58BVzDiYJU/uj9796ApVZ8Azk2JXd0uSEMyFJXpUxuetqkV8+gm6Hn0oVvuml+YYCpSci7GxTpf8hY5d22vgepSx2Nhx+icIbdXzOPjdLpgoai1i/vMRZ9iXwjed//0ExsQlpV/6e4h+OtiT7XZTBo3IaRfDOYQnIHB1q4VUtSBk0YJPtqiI3h8D62dJ/1Qw7D8RFBfQjgyp1JaSVMTlH+Jf98Zki8LA4oiSEnO+cYAQ=="
    },
    {
      "type": "text",
      "text": "Use the built-in `json` module:\n\n```python\nimport json\n\nwith open(\"data.json\", \"r\", encoding=\"utf-8\") as f:\n    data = json.load(f)\n\nprint(data)\n```\n\n`json.load()` parses the file into Python objects: JSON objects become `dict`s, arrays become `list`s, and strings, numbers, booleans, and `null` become `str`, `int`/`float`, `bool`, and `None`.\n\n**Accessing the data**\n\n```python\n# Given: {\"name\": \"Alice\", \"skills\": [\"Python\", \"SQL\"]}\nprint(data[\"name\"])        # Alice\nprint(data[\"skills\"][0])   # Python\n```\n\n**Handling common errors**\n\n```python\nimport json\n\ntry:\n    with open(\"data.json\", \"r\", encoding=\"utf-8\") as f:\n        data = json.load(f)\nexcept FileNotFoundError:\n    print(\"File not found.\")\nexcept json.JSONDecodeError as e:\n    print(f\"Invalid JSON: {e}\")\n```\n\n**Tips**\n\n- Use `json.load(f)` for a file object and `json.loads(s)` for a string.\n- To write JSON back to a file, use `json.dump(data, f, indent=2)`.\n- If your file has one JSON object per line (JSON Lines, `.jsonl`), parse it line by line:\n\n  ```python\n  with open(\"data.jsonl\", encoding=\"utf-8\") as f:\n      records = [json.loads(line) for line in f]\n  ```"
    }
  ],
  "container": null,
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "stop_details": null,
  "usage": {
    "input_tokens": 40,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 0
    },
    "output_tokens": 491,
    "output_tokens_details": {
      "thinking_tokens": 24
    },
    "service_tier": "standard",
    "inference_geo": "global",
    "speed": "standard"
  },
  "diagnostics": null
}

Examples

Multi-turn Conversation — Continue a conversation with prior assistant context
const response = await env.AI.run(
  'anthropic/claude-fable-5.2',
  {
    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)
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-fable-5.2",
  "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"
    }
  ]
}'
The best stops depend on which route you take.

**Highway 1 along the coast (9-10 hours of driving, best split over two days)**

This is the scenic route. From north to south:

- **Santa Cruz**: a classic beach boardwalk and a good first coffee stop.
- **Monterey and Carmel**: the Monterey Bay Aquarium, Cannery Row, and Carmel's walkable village and beach.
- **Big Sur**: the highlight of the drive, with Bixby Bridge, McWay Falls, and Pfeiffer Beach.
- **San Simeon**: Hearst Castle tours (book ahead) and the elephant seal rookery, which is free and right off the highway.
- **Morro Bay and San Luis Obispo**: good places to stay overnight, with solid food in downtown SLO.
- **Santa Barbara**: the Spanish mission, State Street, and the waterfront.
- **Malibu**: a last beach stop before LA, such as El Matador or Zuma.

Check Caltrans road conditions before you go, because the Big Sur stretch of Highway 1 sometimes closes for landslides.

**US-101 (about 7 hours)**

This is a middle ground. It skips Big Sur but still passes through San Luis
{
  "model": "claude-fable-5-2",
  "id": "msg_011CgsuCQmtMxj7JPEhCLZZq",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "sign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V+C5y/luIueDHqLkJ52JV063UjyTI+xtCJvGAPWDZmAuX21USbR0ItauhYXs1soACs6obtlDtAfMfVCz1CFTKdHKqYfEfvvQTOWyr6202r34JGxccdBQe90IPY/NjPL6X/P9jo1JPYLOVDwt/0fgvOhsM8nAaogMj4H+XNMmTJZkmva9g5r2bdTBc0oiXSorAXB57jgSJT60YZ4SzzNm/iP+QakMdJbFyvHvjaIhG+r8bvXbebBQnwdbyZfxXcZonLW5YwvM/oNssKsZndPSY9E2e3Fg97zs9w2mEzqZN1AxrK7u1VioK0GuDtrAHlvElHyOgyThy77rIsn21ZajU89fjzd2ENML560DTbiFKemCSbiS2IK8FHpmIR28Gi/5a0mgh7GxUUjbpmoPtJjo2NPiuNxaWdVt4PN7WKT8KW/Ts1iD6pR3b4HIruWOE+36EChU/6CvV/tHYDJfarCNwYrWmpRqmufuHCvqm1McYZbU8PaSvg8cilWLYZCKNQ/muNSDzGAE="
    },
    {
      "type": "text",
      "text": "The best stops depend on which route you take.\n\n**Highway 1 along the coast (9-10 hours of driving, best split over two days)**\n\nThis is the scenic route. From north to south:\n\n- **Santa Cruz**: a classic beach boardwalk and a good first coffee stop.\n- **Monterey and Carmel**: the Monterey Bay Aquarium, Cannery Row, and Carmel's walkable village and beach.\n- **Big Sur**: the highlight of the drive, with Bixby Bridge, McWay Falls, and Pfeiffer Beach.\n- **San Simeon**: Hearst Castle tours (book ahead) and the elephant seal rookery, which is free and right off the highway.\n- **Morro Bay and San Luis Obispo**: good places to stay overnight, with solid food in downtown SLO.\n- **Santa Barbara**: the Spanish mission, State Street, and the waterfront.\n- **Malibu**: a last beach stop before LA, such as El Matador or Zuma.\n\nCheck Caltrans road conditions before you go, because the Big Sur stretch of Highway 1 sometimes closes for landslides.\n\n**US-101 (about 7 hours)**\n\nThis is a middle ground. It skips Big Sur but still passes through San Luis"
    }
  ],
  "container": null,
  "stop_reason": "max_tokens",
  "stop_sequence": null,
  "stop_details": null,
  "usage": {
    "input_tokens": 105,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 0
    },
    "output_tokens": 1024,
    "output_tokens_details": {
      "thinking_tokens": 604
    },
    "service_tier": "standard",
    "inference_geo": "global",
    "speed": "standard"
  },
  "diagnostics": null
}
Streaming Response — Stream a response for real-time output
const response = await env.AI.run(
  'anthropic/claude-fable-5.2',
  {
    max_tokens: 1024,
    messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
    stream: true,
  },
)
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-fable-5.2",
  "max_tokens": 1024,
  "messages": [
    {
      "content": "Explain the concept of recursion with a simple example.",
      "role": "user"
    }
  ],
  "stream": true
}'
Recursion is when a function solves a problem by calling itself on a smaller version of the same problem, until the problem is small enough to answer directly.

Every recursive function needs two parts:

1. **Base case:** a simple input that it answers directly, without calling itself. This stops the recursion.
2. **Recursive case:** the function calls itself with an input that moves closer to the base case.

## Example: factorial

The factorial of a number `n` (written `n!`) is the product of all whole numbers from 1 to `n`. For example, `4! = 4 × 3 × 2 × 1 = 24`.

Notice that `4! = 4 × 3!`, and `3! = 3 × 2!`, and so on. The problem contains a smaller copy of itself, which makes it a natural fit for recursion:

```python
def factorial(n):
    if n <= 1:          # base case
        return 1
    return n * factorial(n - 1)   # recursive case
```

## What happens when you call `factorial(4)`

Each call waits for the one below it to finish:

```
factorial(4)
= 4 * factorial(3)
= 4 * (3 * factorial(2))
= 4 * (3 * (2 * factorial(1)))
= 4 * (3 * (2 * 1))     ← base case reached, now the results multiply back up
= 4 * (3 * 2)
= 4 * 6
= 24
```

Without the base case, the function would call itself forever (in practice, until the program crashes with a stack overflow error).
[
  {
    "type": "message_start",
    "message": {
      "model": "claude-fable-5-2",
      "id": "msg_011CgsuDKd7HCjnpqvQic3mi",
      "type": "message",
      "role": "assistant",
      "content": [],
      "container": null,
      "stop_reason": null,
      "stop_sequence": null,
      "stop_details": null,
      "usage": {
        "input_tokens": 24,
        "cache_creation_input_tokens": 0,
        "cache_read_input_tokens": 0,
        "cache_creation": {
          "ephemeral_5m_input_tokens": 0,
          "ephemeral_1h_input_tokens": 0
        },
        "output_tokens": 6,
        "service_tier": "standard",
        "inference_geo": "global",
        "speed": "standard"
      },
      "diagnostics": null
    }
  },
  {
    "type": "content_block_start",
    "index": 0,
    "content_block": {
      "type": "thinking",
      "thinking": "",
      "signature": ""
    }
  },
  "... 85 more chunks omitted ...",
  {
    "type": "message_stop"
  }
]

Parameters

Schema variant
max_tokens
numberrequiredexclusiveMinimum: 0
temperature
numberminimum: 0maximum: 1
top_p
numberminimum: 0maximum: 1
top_k
numberexclusiveMinimum: 0
stream
boolean
id
string
type
stringconst: message
role
stringconst: assistant
model
string
stop_reason
string

API Schemas (Raw)

Input
Output

Was this helpful?