1. Home
  2. Insights
  3. AI & Chatbots

Claude Fable 5.2 API Tutorial: Python, TypeScript and Cost Math

How to call Claude Fable 5.2 from Python and TypeScript: model ID, effort, streaming, tools, migrating from Fable 5.1, and worked cost examples with caching and batch.

Abstract illustration for our Claude Fable 5.2 API tutorial, showing the title Claude Fable 5.2 API Tutorial: Python, TypeScript and Cost Math.
Illustration: Apex Logic
On this page
  1. Fable 5.2 API quick reference
  2. Before you start
  3. Your first Claude Fable 5.2 request in Python
  4. Your first request in TypeScript
  5. Parameters that matter on Fable 5.2
  6. Migrating from Claude Fable 5.1
  7. Cost math: four worked examples
  8. Prompt caching and batch discounts
  9. Rate limits and errors
  10. Claude Fable 5.2 API FAQ

Quick answer

Call Claude Fable 5.2 with the model ID claude-fable-5-2 on the Messages API (anthropic.claude-fable-5-2 on Bedrock), leave thinking on and set output_config.effort, which defaults to high. Leave out temperature and forced tool choice, stream long outputs, and budget $8 per million input and $40 per million output tokens, with cache reads at $0.20 and the Batch API at half price. Migrating from Fable 5.1 is a model ID change plus checks for edited history, computer use and advisor settings.

  • Model ID claude-fable-5-2, thinking always on
  • Control depth with output_config.effort
  • Four breaking changes from Fable 5.1
  • Cache reads cost $0.20 per million tokens

Updated 10 November 2026. Claude Fable 5.2 reached the Claude API on 9 November as claude-fable-5-2, so this tutorial covers a first request, the settings that matter, migration from Fable 5.1 and what calls cost.

To call Claude Fable 5.2, send a Messages API request with model set to claude-fable-5-2 (on Amazon Bedrock the ID is anthropic.claude-fable-5-2). Thinking is always on, so you leave out any thinking budget and steer depth with output_config.effort, which defaults to high. Leave out temperature, top_p and top_k, keep tool_choice on auto, and stream anything long. As of 10 November 2026 it costs $8 per million input tokens and $40 per million output tokens.

Moving from Fable 5.1 is mostly a one-line change, but four things can break: edited conversation history now fails on every account, Fable 5.1 cannot read Fable 5.2 thinking blocks, the older computer_20251124 tool returns a 400 outside Bedrock, and an advisor tool must use Fable 5.2 or Mythos 5.2.

Fable 5.2 API quick reference

SettingFable 5.2 value
Model IDclaude-fable-5-2; Bedrock anthropic.claude-fable-5-2
Context and output1M tokens in, up to 128K tokens out
ThinkingAdaptive, always on; disabled and budget_tokens return 400
Effortlow, medium, high (default), xhigh, max
Sampling parametersOmit temperature, top_p and top_k
Tool choiceauto or none; any and tool return 400
Assistant prefillNot supported
Price per million tokens$8 in, $40 out; cache read $0.20; batch $4 and $20
Fast modespeed: "fast" at $16 in, $80 out
Data retention30-day retention required on the workspace

Before you start

  • Retention: Fable 5.2 is a Covered Model. A request from an organization or workspace without 30-day data retention returns a 400 invalid_request_error, so set 30-day retention on a workspace first if you run under zero data retention.
  • Access: no approval is needed. Only Mythos 5.2 needs verification; see our Mythos 5.2 access guide. Plans and clouds are in our Claude Fable 5.2 guide.
  • Credentials: export a Claude Console key as ANTHROPIC_API_KEY, or sign in with ant auth login.
  • Install: pip install anthropic or npm install @anthropic-ai/sdk.

Your first Claude Fable 5.2 request in Python

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-fable-5-2",
    max_tokens=16000,
    output_config={"effort": "high"},
    messages=[
        {
            "role": "user",
            "content": "Review this function for race conditions and suggest a fix: ...",
        }
    ],
)

if message.stop_reason == "refusal":
    print("Declined:", message.stop_details.category)
else:
    for block in message.content:
        if block.type == "text":
            print(block.text)

print(message.usage.input_tokens, message.usage.output_tokens)

The response usually starts with a thinking block whose text is empty, because display defaults to "omitted", but you still pay for that thinking as output. Check stop_reason first: a classifier decline is a normal response, not an exception.

Your first request in TypeScript

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

const message = await client.messages.create({
  model: "claude-fable-5-2",
  max_tokens: 16000,
  output_config: { effort: "high" },
  messages: [
    { role: "user", content: "Review this function for race conditions and suggest a fix: ..." }
  ]
});

for (const block of message.content) {
  if (block.type === "text") {
    console.log(block.text);
  }
}
console.log(message.stop_reason, message.usage.output_tokens);

Run it as an ES module with npx tsx first.ts, as Anthropic's quickstart does.

Parameters that matter on Fable 5.2

Effort, not a thinking budget

Fable 5.2 decides how much to think, and output_config.effort steers it. Anthropic's advice: start at high, where most of the capability already is; use xhigh for your hardest long-running coding and agent work once you have measured a gain; drop to medium or low where your evals hold; and keep max for measuring the ceiling. A disabled thinking setting or a budget_tokens value returns a 400. For a readable summary of the reasoning, pass thinking={"type": "adaptive", "display": "summarized"}. Per-message effort changes, which keep the prompt cache, are in beta under the mid-conversation-output-config-2026-07-01 header.

max_tokens

max_tokens is a hard cap on thinking plus answer, up to 128K, so set it large at high effort and above. A small value can stop with stop_reason: "max_tokens" after the thinking block and before any text. The SDKs check that a non-streaming request is not expected to run past 10 minutes, so stream big outputs.

Streaming

with client.messages.stream(
    model="claude-fable-5-2",
    max_tokens=64000,
    output_config={"effort": "xhigh"},
    messages=[{"role": "user", "content": "Plan the migration of this service to Postgres: ..."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    final = stream.get_final_message()

print()
print("Output tokens:", final.usage.output_tokens)

In TypeScript, the same call is client.messages.stream({...}), with .on("text", ...) for the deltas and await stream.finalMessage() for the complete message.

Tools

Tools work as on other Claude models, with two Fable rules. Forced tool choice returns a 400, so name the tool in your instruction and leave tool_choice on auto. And send the assistant's full content back unchanged, so its thinking blocks stay valid. Add strict: true when a tool's input must match the schema exactly, except in organizations with customer-managed encryption keys, where Fable 5.2 does not offer strict tool use.

tools = [
    {
        "name": "get_order_status",
        "description": "Look up the shipping status of an order by its ID.",
        "input_schema": {
            "type": "object",
            "properties": {
                "order_id": {"type": "string", "description": "Order ID, for example A-1042"}
            },
            "required": ["order_id"],
        },
    }
]
messages = [{"role": "user", "content": "Where is order A-1042? Use the order tool."}]

response = client.messages.create(
    model="claude-fable-5-2",
    max_tokens=16000,
    tools=tools,
    tool_choice={"type": "auto", "disable_parallel_tool_use": True},
    messages=messages,
)

if response.stop_reason == "tool_use":
    call = next(block for block in response.content if block.type == "tool_use")
    print("Claude called", call.name, call.input)
    result = "Shipped 8 November, due 12 November"  # your lookup goes here
    messages += [
        {"role": "assistant", "content": response.content},
        {
            "role": "user",
            "content": [{"type": "tool_result", "tool_use_id": call.id, "content": result}],
        },
    ]
    followup = client.messages.create(
        model="claude-fable-5-2",
        max_tokens=16000,
        tools=tools,
        tool_choice={"type": "auto", "disable_parallel_tool_use": True},
        messages=messages,
    )
    print(next(block.text for block in followup.content if block.type == "text"))

Computer use on Fable 5.2 goes through the computer_toolset_20260801 toolset. If you are building a full agent loop rather than one tool call, our guide on how to build an AI agent covers the design.

Migrating from Claude Fable 5.1

  1. Change the model ID from claude-fable-5-1 to claude-fable-5-2. The API surface, refusal categories and retention rules stay the same.
  2. Check whether your code edits history. Fable 5.2 validates each thinking block against the system prompt, the tools and every earlier message, on every account. Fable 5.1 did this only for accounts created on or after 31 August 2026, so older accounts can start getting a 400 that says The block is bound to a different conversation. Retrying the same body does not clear it.
  3. Find the edits before you switch. Run a test session with the thinking-binding-controls-2026-08-01 beta header and prefix_mismatch_behavior set to "drop_block", log input_transformations, and fix every prefix_binding_mismatch entry. Treat drop_block as a stopgap, because dropped reasoning can raise output tokens.
  4. Expect lost reasoning on model switches. No model except Mythos 5.2 reads Fable 5.2 thinking blocks, so a router or fallback that moves a conversation to Opus 5.5 or Fable 5.1 drops them, unbilled.
  5. Move computer use to computer_toolset_20260801; outside Amazon Bedrock, computer_20251124 returns a 400.
  6. Update the advisor tool to claude-fable-5-2 or claude-mythos-5-2, in new conversations.
  7. Check rate limits: Fable 5.2 has its own bucket.
  8. Rerun your evals with an effort sweep that starts at high, and delete prompt lines that ask the model to think less.

The test request for step 3 looks like this:

response = client.beta.messages.create(
    model="claude-fable-5-2",
    max_tokens=16000,
    thinking={
        "type": "adaptive",
        "block_binding": {"prefix_mismatch_behavior": "drop_block"},
    },
    messages=history,  # your stored conversation
    betas=["thinking-binding-controls-2026-08-01"],
)
print("Input transformations:", len(response.input_transformations or []))

Cost math: four worked examples

All four are illustrative, use Anthropic's list prices as of 10 November 2026, and count thinking as output, because that is how it is billed.

ExampleAssumptionsFable 5.2 cost
1. One agent step50,000 input and 8,000 output tokens$0.40 + $0.32 = $0.72 (Fable 5.1: $0.90; Opus 5.5: $0.36)
2. Cached codebase, 20 questions200,000-token cached prefix; 2,000 new input and 4,000 output tokens per request, each within 5 minutes of the lastFirst call $2.18, then $0.22 each: about $6.28 (no caching: $35.52)
3. Nightly batch review2,000 pull requests, 20,000 input and 6,000 output tokens each$400 on the Batch API ($800 at standard rates)
4. Example 1 in fast modeSame tokens with speed: "fast"$0.80 + $0.64 = $1.44

US-only inference with inference_geo: "us" multiplies every rate by 1.1, so Example 1 becomes about $0.79. Token counts should match Fable 5.1, which uses the same tokenizer family, so only the price changes when you migrate. Measure real prompts with the token counting endpoint, and see our guide to estimating and cutting an LLM API bill.

Prompt caching and batch discounts

Caching is the biggest cost lever on Fable 5.2: a cache read costs 2.5% of the input price, $0.20 per million. A 5-minute write costs 1.25x ($10) and a 1-hour write 2x ($16). The minimum cacheable prompt is 512 tokens, you get up to four breakpoints, and cached reads do not count toward your input-token rate limit. The simplest setup is one top-level cache_control field:

response = client.messages.create(
    model="claude-fable-5-2",
    max_tokens=16000,
    cache_control={"type": "ephemeral"},
    system=project_notes,  # the same long text on every request
    messages=[{"role": "user", "content": "Which modules touch billing?"}],
)
print(response.usage.cache_creation_input_tokens, response.usage.cache_read_input_tokens)

Add "ttl": "1h" to cache_control for a one-hour cache. A hit needs an identical prefix, and switching speed invalidates the cached system prompt and messages.

The Message Batches API takes 50% off. A batch holds up to 100,000 requests or 256 MB, most finish within an hour, unfinished requests expire after 24 hours, and results stay for 29 days. Batch requests cannot use stream, speed or fallbacks.

from anthropic.types.message_create_params import MessageCreateParamsNonStreaming
from anthropic.types.messages.batch_create_params import Request

batch = client.messages.batches.create(
    requests=[
        Request(
            custom_id="pr-" + str(number),
            params=MessageCreateParamsNonStreaming(
                model="claude-fable-5-2",
                max_tokens=16000,
                messages=[{"role": "user", "content": "Review this diff: " + diff}],
            ),
        )
        for number, diff in enumerate(diffs)  # diffs is your list of diff strings
    ]
)
print(batch.id, batch.processing_status)

Rate limits and errors

Usage tierRequests per minuteInput tokens per minuteOutput tokens per minute
Start4,000500,000100,000
Build10,0001,500,000300,000
Scale13,0004,000,000800,000

Responses carry anthropic-ratelimit-* headers, and a rate limit 429 usually includes retry-after. A 429 from your tier's monthly spend cap has no retry-after and keeps failing until access resumes.

StatusError typeCommon cause on Fable 5.2
400invalid_request_errorThinking disabled or budgeted, forced tool choice, sampling parameters, prefill, edited history, no 30-day retention
401authentication_errorMalformed, revoked or expired API key
429rate_limit_errorRate limit, fast mode limit or spend cap
500api_errorInternal error; retry with backoff
529overloaded_errorThe API is temporarily overloaded

The SDKs retry connection errors, 429s and 5xx errors twice by default with exponential backoff, honoring retry-after. After that, catch the typed exceptions, most specific first:

try:
    message = client.messages.create(
        model="claude-fable-5-2",
        max_tokens=16000,
        messages=[{"role": "user", "content": "Summarize this incident log: ..."}],
    )
except anthropic.BadRequestError as error:
    print("Fix the request:", error.message)
except anthropic.RateLimitError as error:
    print("Rate limited, retry after", error.response.headers.get("retry-after"))
except anthropic.APIStatusError as error:
    print("API error", error.status_code, error.message)
except anthropic.APIConnectionError:
    print("Network problem, try again")

Refusals are not errors. Fable 5.2 can decline with stop_reason: "refusal" and a stop_details.category such as cyber, bio, frontier_llm, reasoning_extraction or general_harms. To retry declined requests automatically, call client.beta.messages.create with fallbacks="default" and betas=["server-side-fallback-2026-07-01"]: the API reruns the request on Anthropic's recommended model for that category, Opus 4.8 or Opus 5 for Fable 5.2. It is in beta on the Claude API and Claude Models on Google Cloud (Anthropic managed), and a reasoning_extraction refusal is never rerouted.

Building a feature on Fable 5.2 and want retention, caching and fallbacks right the first time? Apex Logic builds Claude integrations on fixed quotes, and you own the code. Tell us what you are building or try our AI tools.

Claude Fable 5.2 API FAQ

What is the Claude Fable 5.2 model ID?

The model ID is claude-fable-5-2 on the Claude API, Claude Platform on AWS, both Google Cloud options and Microsoft Foundry. On Amazon Bedrock it is anthropic.claude-fable-5-2, and on Foundry fast mode uses a separate claude-fable-5-2-fast deployment. Anthropic says dateless model IDs like this one are pinned snapshots, so the model behind it will not change.

How do I turn thinking on or off in Claude Fable 5.2?

You cannot turn it off. Adaptive thinking is always on: omit the thinking field or send type adaptive. Type disabled, or a budget_tokens value, returns a 400 error. To use less thinking, lower output_config.effort to medium or low. To read a summary of the reasoning, set display to summarized, because the default is omitted.

Why does my Claude Fable 5.2 request return a 400 error?

Usual causes: a thinking setting other than adaptive, tool_choice set to any or tool, a temperature, top_p or top_k value, an assistant prefill, a workspace without 30-day data retention, or history your code edited after a thinking block was produced. The error message usually says which setting is wrong. History edits keep failing on retry until you fix the code or use drop_block.

How much does a Claude Fable 5.2 API call cost?

As of 10 November 2026, input costs $8 and output $40 per million tokens, with thinking billed as output. A call with 50,000 input and 8,000 output tokens costs $0.72, against $0.90 on Fable 5.1. Cache reads at $0.20 per million and the Batch API at half price cut that further, while fast mode doubles it.

Does Claude Fable 5.2 support prompt caching and the Batch API?

Yes. Prompts of 512 tokens or more can be cached, with reads at $0.20 per million tokens and writes at $10 for five minutes or $16 for one hour. The Message Batches API supports Fable 5.2 at $4 input and $20 output per million tokens, but batch requests cannot use fast mode, streaming or fallbacks.

Sources

Want an AI tool like this built for your business?

We build custom AI tools on Gemini, GPT and Claude, connected to the software you already use. Fixed quote, live in weeks, and you own the code.

Written by Abdul Ghani

Apex Logic is a software studio in Multan, Pakistan that builds custom web apps, AI tools and automation for clients worldwide.

More from Abdul Ghani

Editor's note: Facts checked against official announcements and documentation on 10 November 2026. These topics are moving fast; prices, availability and features may change.

Comments

Loading comments...