Best Claude Model for Coding in 2026: Opus vs Sonnet vs Haiku vs Fable, Priced on Real Twitter (X) Data

By TwitterAPI.io Team•17 min read
Diagram of the four current Claude models for coding, Haiku 5.5, Sonnet 5.5, Opus 5.5 and Fable 5.1, with model IDs, per-million-token prices and Anthropic's use-case guidance
The current Claude lineup on the Claude API, list prices per million tokens (input / output) from Anthropic's pricing page. X data in the footer collected in 2026.

This page answers one question: which Claude model should you write code with. Our sibling guide on Claude API pricing is the per-token rate reference (cache writes, Batch, data residency, every legacy model); this one is the decision guide, model by model, for coding work in Claude Code or through the API, with the cost of a real data-handling coding task worked out for each model.

Most of the results that rank for this question still describe the previous generation (Opus 5, Sonnet 5, Haiku 4.5). The lineup changed: Anthropic's models overview now lists Claude Fable 5.1, Claude Opus 5.5, Claude Sonnet 5.5 and Claude Haiku 5.5 as current, and Claude Code's default model moved to Opus 5.5. Every model ID, price, context window and default below was read from platform.claude.com and code.claude.com docs this year; none of it comes from memory or from a benchmark we ran. We did not benchmark the models.

What we did measure is the input side of a coding task that touches real data. Developers who build on X (Twitter) data paste API responses into prompts as fixtures, ask Claude to write parsers, and run classifiers over thousands of posts. We pulled 955 real posts through the TwitterAPI.io API, measured their size, and priced the same task on each model, so you can see where the model choice actually moves your bill.

01 — Section

The short answer: which Claude model is best for coding

Anthropic publishes its own recommendation, and it is unusually direct. The models overview opens with: start with Claude Opus 5.5 for most workloads, and use Claude Fable 5.1 for demanding reasoning and long-horizon agentic work, or when your evals on Opus 5.5 at higher effort still fall short. The choosing-a-model guide repeats it: most workloads start with Claude Opus 5.5.

Pick Claude Opus 5.5 when the task is real engineering: multi-file changes, a refactor across a codebase, debugging something you do not understand yet, or an agent that runs for a long time without you. Anthropic's selection matrix lists "multihour autonomous coding agents, large-scale refactoring, complex systems engineering" as its use cases.

Pick Claude Sonnet 5.5 when you want fast, capable everyday coding: writing a function, adding an endpoint, generating tests, explaining code. The selection matrix assigns it "code generation, data analysis, content creation, visual understanding, agentic tool use," and the overview calls it "the best combination of speed and intelligence." It costs half of Opus 5.5 per token.

Pick Claude Haiku 5.5 when the job is high-volume and narrow: a subagent that greps and summarizes, a classifier over thousands of records, a router that decides which tool to call. Anthropic lists "real-time applications, high-volume intelligent processing, cost-sensitive deployments needing strong reasoning, subagent tasks." It is 40x cheaper per input token than Opus 5.5 for prompts up to 100,000 tokens.

Pick Claude Fable 5.1 when a task is larger than a single sitting. Anthropic describes it as its most capable model open to all customers, for "agent sessions that run for hours, multistep deep research, analysis carried through to a finished document." Claude Code's docs add that neither Fable model is the default on any plan, and that on some plans Fable usage bills to usage credits instead of your plan's included limits.

If you only remember one rule from Anthropic's docs, make it this one from the choosing-a-model guide: tuning the effort parameter "is often a better lever than switching models." Opus 5.5 at a lower effort is often a better trade than dropping to a smaller model.

02 — Section

Claude models comparison: IDs, prices, context and defaults

Every value in this table comes from the comparison table on Anthropic's models overview (platform.claude.com/docs/en/models/overview) and the model pricing table (platform.claude.com/docs/en/about-claude/pricing). Prices are USD per million tokens (MTok) on the Claude API.

ModelAPI IDInput / output per MTokLatencyDefault effort (API)
Claude Fable 5.1claude-fable-5-1$10 / $50Slowerhigh
Claude Opus 5.5claude-opus-5-5$4 / $20Moderatemedium
Claude Sonnet 5.5claude-sonnet-5-5$2 / $10Fasthigh
Claude Haiku 5.5claude-haiku-5-5$0.10 / $0.50 (prompts up to 100K tokens)Fastestmedium

What is the same across all four. Each has a 1M-token context window, 128K max output on the synchronous Messages API, text and image input, tool use, and a reliable knowledge cutoff of June 2026. Thinking is adaptive on all four; on Fable 5.1 and Opus 5.5 it is always on. So the context window is not a reason to pick one model over another for coding any more.

Haiku 5.5 has a second price tier. A Haiku 5.5 request whose prompt is over 100,000 tokens pays $0.50 / $2.50 per MTok instead of $0.10 / $0.50, and the whole request is billed at the higher rate. The other three current models bill the full 1M window at their standard rate.

Discounts that stack. The Batch API is 50% off input and output on every model (Opus 5.5 drops to $2 / $10, Haiku 5.5 to $0.05 / $0.25). Prompt cache reads cost 0.05x the input price on Opus 5.5 and Sonnet 5.5, 0.025x on Fable 5.1, and 0.1x on Haiku 5.5. Fast mode on Opus 5.5 is $8 / $40 per MTok for up to 2.5x higher output speed, and it does not combine with Batch.

The tokenizer changed. Anthropic's pricing page notes that Claude 4.7 and later models use a newer tokenizer that produces approximately 30% more tokens for the same text. If you compare a cost estimate from an older model guide, scale it up; the models overview puts 1M tokens at roughly 2.5 million Unicode characters on the current tokenizer.

Legacy models still answer. Opus 5, Opus 4.8, Opus 4.7, Opus 4.6, Opus 4.5, Sonnet 5, Sonnet 4.6, Haiku 4.5 and Fable 5 remain available. Note that Opus 5 ($5 / $25) costs more than Opus 5.5 ($4 / $20), so staying on the old snapshot is not a saving.

03 — Section

Opus vs Sonnet for coding: where the extra cost pays

Opus 5.5 is exactly 2x Sonnet 5.5 per token, both on input ($4 vs $2) and output ($20 vs $10). That makes the comparison simple: Opus is worth it when it saves you more than one extra Sonnet attempt, or more than the time you would spend fixing Sonnet's output.

Where Opus earns it. Anthropic positions Opus 5.5 for long-running agentic coding. In practice that means tasks where a wrong early decision is expensive: a migration that touches 40 files, a race condition, an architecture choice that the rest of the session builds on. Claude Code's docs report that in Anthropic's testing, Opus 5.5 at medium effort matches or exceeds Opus 5 at high on coding and knowledge-work evaluations.

Where Sonnet is enough. Well-scoped changes with a clear spec: a new endpoint, a parser for a known JSON shape, unit tests for an existing function, a script that calls one API. These are also the tasks you review line by line anyway, so a faster model shortens the loop.

The hybrid Claude Code ships with. Claude Code has an opusplan alias: it uses opus in plan mode for reasoning and architecture decisions, then switches to sonnet for code generation and execution. On the Anthropic API both phases run with the 1M context window. It is the documented way to pay Opus prices only for the thinking part.

Effort before model. The effort scale (low, medium, high, xhigh, max) trades token spend against capability inside one model. Claude Code's guidance: medium fits day-to-day engineering with a clear scope; high fits bug fixing where edge cases are likely; max is for hard problems like finding security vulnerabilities, and is "prone to overthinking, so test before adopting it broadly." Higher effort means more generated tokens, which is where most of a coding session's cost goes at $20 per million output tokens on Opus.

Haiku for the side work. Many coding sessions are mostly reading: grepping, summarizing files, checking a log. Anthropic's "Combine models" section describes an orchestrator that delegates bulk work to lower-cost workers so most tokens bill at the lower rate. In Claude Code that is a subagent pinned to haiku.

04 — Section

Which model Claude Code uses, and how to switch

Claude Code's model configuration docs (code.claude.com/docs/en/model-config) define the aliases. On the Anthropic API, opus resolves to Opus 5.5, sonnet to Sonnet 5.5 and haiku to Haiku 5.5. The fable alias resolves to Fable 5.1, and best uses Fable where it is available to you and Opus otherwise.

AliasWhat it selects on the Anthropic APIGood for
defaultOpus 5.5 on Pro, Max, Ultra, Team, Enterprise and the Anthropic APIMost sessions
sonnetSonnet 5.5Daily coding tasks
opusplanOpus in plan mode, Sonnet for executionPlan-heavy work on a budget
haikuHaiku 5.5Simple tasks, subagents
fableFable 5.1 (not the default on any plan)Tasks longer than one sitting

Switching. Run /model sonnet during a session, launch with claude --model opus, or set ANTHROPIC_MODEL. Running /model saves your choice as the default for new sessions; in the picker, press s to switch for the current session only. To pin a version rather than follow the alias, use the full ID, for example claude-opus-5-5.

Other providers resolve differently. On Amazon Bedrock and Google Cloud's Agent Platform, sonnet resolves to Sonnet 4.5 and haiku to Haiku 4.5; on Microsoft Foundry, default is Sonnet 4.5. If you are on one of those, set the full model ID or the ANTHROPIC_DEFAULT_SONNET_MODEL variable to get the current generation.

One-off deep reasoning. Typing ultrathink in a prompt asks for deeper reasoning on that turn without changing the session's effort setting, which is a cheaper habit than raising effort for a whole session.

05 — Section

How big real X data is when you paste it into a prompt

Coding with real data is where model price stops being abstract. A developer building on X (Twitter) data typically does three things with Claude: pastes an API response as a fixture and asks for a parser, asks for a script that calls the API, and runs a model over many posts to label them. The first and third are dominated by input tokens, so we measured how many tokens real tweets are.

We collected 955 distinct posts in 2026 through the TwitterAPI.io API: the latest timeline posts of six organization accounts (Claude, Anthropic, OpenAI Developers, Vercel, GitHub, Cursor) and the latest search results for four model-name queries. We measured each tweet's full JSON, a trimmed 8-field record, and each full 20-tweet page. Tokens are estimated as characters divided by 2.5, Anthropic's published ratio for the current tokenizer; JSON punctuation can tokenize differently from prose, so treat these as estimates and confirm with Anthropic's token counting endpoint for your own data.

What you pasteMedian charactersMedian tokens (est.)90th percentile tokens (est.)
One full tweet JSON object4,8061,9225,108
One trimmed tweet (8 fields)427171546
Tweet text only23494468
One full 20-tweet API page118,98747,59573,454

The full object is mostly not the tweet. A tweet's text is about 94 tokens at the median, but its full JSON is about 1,922: the author object, entities, media variants, cards and any quoted or retweeted post ride along. Keeping only id, createdAt, text, the author's userName and four engagement counts cuts the median record by 91.1%.

Why it matters for Haiku. One raw 20-tweet page is about 47,595 tokens at the median and 73,454 at the 90th percentile. Two raw pages plus a prompt approach Haiku 5.5's 100,000-token threshold, above which the whole request bills at 5x the rate. Trimmed, the same 40 tweets are under 7,000 tokens.

06 — Section

Claude model pricing on a real coding task

Here is the same coding request priced on each model: paste one 20-tweet page as a fixture, add a 2,000-token instruction and code context, and get 3,000 tokens of code back. The input is 49,595 tokens with the raw page and 5,416 with the trimmed page (estimates). The 3,000-token output is an assumption; adaptive thinking and higher effort levels generate more tokens than that on hard tasks.

ModelRaw fixture, per requestTrimmed fixture, per request100 requests, trimmed
Claude Fable 5.1$0.646$0.204$20.42
Claude Opus 5.5$0.258$0.082$8.17
Claude Sonnet 5.5$0.129$0.041$4.08
Claude Haiku 5.5$0.0065$0.0020$0.200

Read the table two ways. Across models, Opus 5.5 is 2x Sonnet 5.5 and 40x Haiku 5.5 for the same request. Within a model, trimming the fixture cuts the Opus 5.5 request from $0.258 to $0.082, a bigger saving than switching from Opus to Sonnet with the raw page ($0.129). Data hygiene beats model shopping.

With caching. In a multi-turn coding session the fixture is re-read on every turn. Prompt cache reads cost 0.05x the input price on Opus 5.5, so a cached 47,000-token fixture costs under $0.01 per turn to re-read on Opus 5.5 instead of about $0.19. Anthropic's pricing page notes that the 5-minute cache pays off after one read.

Labeling at volume is a different job. Classifying 1,000 trimmed tweets (20 per request, a 500-token instruction each, 10 output tokens per tweet) is an estimated input of about 196,000 tokens and 10,000 output tokens:

Model1,000 tweets, standard1,000 tweets, Batch API
Claude Fable 5.1$2.46$1.23
Claude Opus 5.5$0.983$0.492
Claude Sonnet 5.5$0.492$0.246
Claude Haiku 5.5$0.025$0.012

That is the clearest case for Haiku: Anthropic built it for classification and extraction, and at these volumes the gap between models is a factor of 40 to 100 for work where the bigger models add little. Write the classifier with Opus or Sonnet; run it with Haiku.

Bar chart of the estimated cost of one coding request per Claude model, with a raw 20-tweet fixture versus a trimmed one: Fable 5.1, Opus 5.5, Sonnet 5.5 and Haiku 5.5
Estimated cost of one coding request at list prices, raw vs trimmed 20-tweet fixture. Token counts estimated from 955 X posts collected in 2026.
07 — Section

What X developers are saying about each model

Benchmarks change monthly and every index ranks differently, so we looked at a simpler signal: how much X conversation each current model name gets next to the word "coding." We ran a Latest search for each phrase (for example "opus 5.5" coding) and measured how fast the most recent 100 posts arrived.

QueryPosts collectedTime spanPosts per dayDistinct authors
"opus 5.5" coding1009.6 h249.595
"sonnet 5.5" coding10097.9 h24.586
"fable 5.1" coding100127.0 h18.993
"haiku 5.5" coding100137.9 h17.488

Opus 5.5 dominates the conversation. The Opus 5.5 query filled 100 posts in 9.6 hours, about 249.5 posts a day, roughly 10x the rate of Sonnet 5.5 (24.5 a day). That fits Anthropic recommending Opus 5.5 as the starting point and Claude Code defaulting to it: it is the model most developers are actually coding with and posting about.

What this cannot show. Volume is not quality. A newer or default model gets more posts simply because more people meet it. The sample is the most recent 100 posts per query at collection time in 2026, phrase matching misses posts that say "Opus" without the version, and it includes complaints as well as praise. We report aggregates only and do not quote or profile individual posters.

If you want to run this kind of tracking yourself (which model names developers mention, how sentiment shifts after a release) the same search call in the code below does it for $0.15 per 1,000 posts returned.

Bar chart of X posts per day mentioning each Claude model name together with coding: Opus 5.5 far ahead of Sonnet 5.5, Haiku 5.5 and Fable 5.1
Posts per day for each "<model> coding" query, most recent 100 posts per query, collected in 2026. A volume signal, not a quality ranking.
08 — Section

A worked X-data coding workflow, and what it costs

The code below is the full loop: fetch recent posts from TwitterAPI.io, trim them, and hand them to the Claude model you choose with a coding instruction. The model is an environment variable, so you can run the same task on Sonnet 5.5 and Opus 5.5 and compare the output and the usage token counts the Messages API returns.

The data side. /twitter/tweet/advanced_search with queryType=Latest returns up to 20 tweets per page at 15 credits per tweet returned, so one full page is $0.003 and 1,000 tweets are $0.15. A search that returns nothing bills the 15-credit minimum ($0.00015). No X account or developer approval is needed for reads. For comparison, the official X API pay-per-usage rate card (docs.x.com/x-api/getting-started/pricing) charges $0.005 per post read, $5 per 1,000, about 33x more.

The model side. With the trimmed 20-tweet fixture from the example, the request is about 5,400 input tokens: an estimated $0.0408 on Sonnet 5.5 or $0.0817 on Opus 5.5 with a 3,000-token answer. The data that fed it cost $0.003. In a coding workflow over X data, the model is nearly always the larger bill, which is why trimming the payload and choosing the model per step matter more than the data price.

Or skip the glue code with MCP. Claude Code can attach the hosted TwitterAPI.io MCP server so the model calls X search and timelines as tools while it codes. Paste your TwitterAPI.io API key as the Bearer token:

Cost guardrails worth adding. Cap pages per run (max_pages), dedupe tweet IDs across runs, log usage.input_tokens from every Claude response, and send bulk labeling through the Batch API at half price. New TwitterAPI.io accounts that pass the automatic bot check get up to $1 of free credits (at most 100,000 credits, no card, one per person or network, expiring after 31 days); purchased credits never expire. Paid plans start at $29 a month (see /pricing), and rate limits rise from 0.2 requests per second before the first payment to 20 once paid.

bash
claude mcp add --transport http twitterapi https://mcp.twitterapi.io/mcp \
  --header "Authorization: Bearer $TWITTERAPI_IO_KEY"

# then, inside Claude Code:
/model sonnet      # everyday coding
/model opusplan    # Opus plans, Sonnet executes
09 — Section

How we collected this, and how to choose for your own code

Question. How many tokens does real X data cost when you hand it to a Claude model during a coding task, what does that cost per current model, and which model names get the most X conversation next to "coding"?

Accounts and queries. Timelines (/twitter/user/last_tweets, 5 pages each) of six organization accounts: @claudeai, @AnthropicAI, @OpenAIDevs, @vercel, @github and @cursor_ai. Latest search (/twitter/tweet/advanced_search, 5 pages each) for four phrases: "opus 5.5", "sonnet 5.5", "haiku 5.5" and "fable 5.1", each with the word coding.

Window and size. The most recent posts at collection time, collected in 2026. 50 requests, 955 distinct posts after removing duplicates across queries, about $0.15 in API credits.

Method. Character lengths of each tweet's full JSON, a trimmed 8-field record and each full 20-tweet page; tokens estimated as characters / 2.5 per Anthropic's published ratio for the current tokenizer. Costs use the list prices on Anthropic's pricing page; the coding task assumes a 2,000-token prompt and 3,000 output tokens.

What the sample cannot show. Token counts are estimates, not measured with Anthropic's token counting endpoint, and real outputs with adaptive thinking can be longer than our 3,000-token assumption. We did not run or benchmark any model, so nothing here ranks model quality. The search volume figure reflects the most recent 100 posts per query only.

Privacy. Aggregates only. Organization accounts are named; search results come from private individuals, so raw search pages were never stored with the study, and the published sample holds only de-identified size rows (no IDs, text or handles).

A practical way to choose. Follow Anthropic's own capability-first path: implement with Opus 5.5, evaluate on your real tasks, then lower effort or move steps down to Sonnet 5.5 or Haiku 5.5 where quality holds. Build a small eval set from your own code and data, as the choosing-a-model guide recommends, rather than trusting any leaderboard, including the ones that still rank last generation's models.

Ready to wire X data into your coding workflow? Create a key on the /dashboard, read the endpoint reference at docs.twitterapi.io, and start with the script above on Sonnet 5.5.

python
import os, json, requests

TW_KEY = os.environ["TWITTERAPI_IO_KEY"]          # TwitterAPI.io key (no X account needed)
CLAUDE_KEY = os.environ["ANTHROPIC_API_KEY"]      # Claude API key
BASE = "https://api.twitterapi.io"

# Pick the model per job: Haiku for bulk labeling, Sonnet for everyday code, Opus for long agentic work.
MODEL = os.environ.get("CLAUDE_MODEL", "claude-sonnet-5-5")

def fetch_tweets(query, max_pages=3):
    """Latest posts for a search query, following next_cursor. 15 credits per tweet returned."""
    tweets, cursor = [], ""
    for _ in range(max_pages):
        r = requests.get(
            f"{BASE}/twitter/tweet/advanced_search",
            headers={"X-API-Key": TW_KEY},
            params={"query": query, "queryType": "Latest", "cursor": cursor},
            timeout=30,
        )
        r.raise_for_status()
        body = r.json()
        tweets.extend(body.get("tweets", []))
        if not body.get("has_next_page"):
            break
        cursor = body.get("next_cursor", "")
    return tweets

def trim(t):
    """Keep 8 fields: about 91% fewer characters than the full tweet JSON in our 2026 sample."""
    a = t.get("author") or {}
    return {
        "id": t.get("id"), "createdAt": t.get("createdAt"), "text": t.get("text"),
        "author": a.get("userName"), "likeCount": t.get("likeCount"),
        "retweetCount": t.get("retweetCount"), "replyCount": t.get("replyCount"),
        "viewCount": t.get("viewCount"),
    }

def ask_claude(tweets):
    prompt = (
        "Here are recent X posts as JSON lines. Write a Python function that groups them by "
        "author and returns the 5 posts with the highest likeCount, with tests.\n\n"
        + "\n".join(json.dumps(trim(t), ensure_ascii=False) for t in tweets)
    )
    r = requests.post(
        "https://api.anthropic.com/v1/messages",
        headers={"x-api-key": CLAUDE_KEY, "anthropic-version": "2023-06-01",
                 "content-type": "application/json"},
        json={"model": MODEL, "max_tokens": 4000,
              "messages": [{"role": "user", "content": prompt}]},
        timeout=300,
    )
    r.raise_for_status()
    body = r.json()
    usage = body.get("usage", {})
    print("input tokens:", usage.get("input_tokens"), "output tokens:", usage.get("output_tokens"))
    return "".join(b.get("text", "") for b in body.get("content", []) if b.get("type") == "text")

if __name__ == "__main__":
    posts = fetch_tweets('"claude code" lang:en -is:retweet', max_pages=1)  # one page = 20 tweets = $0.003
    print(f"fetched {len(posts)} posts")
    if posts:
        print(ask_claude(posts))
10 — Questions

Questions readers ask

Which Claude model is best for coding?

Claude Opus 5.5 (claude-opus-5-5) for most coding work. Anthropic's models overview says to start with Opus 5.5 for most workloads and lists it for complex agentic coding and large-scale refactoring. Use Sonnet 5.5 for faster everyday code generation at half the price, Haiku 5.5 for subagents and bulk classification, and Fable 5.1 when a task runs for hours or Opus 5.5 at high effort still falls short.

Is Claude Opus or Sonnet better for coding?

Opus 5.5 is the stronger model and costs exactly twice as much per token ($4 / $20 vs $2 / $10 per million tokens). Use Opus for multi-file changes, hard debugging and long agent sessions; use Sonnet 5.5 for well-scoped tasks you review line by line. Claude Code's opusplan alias combines them: Opus in plan mode, Sonnet for execution.

How much do Claude models cost?

Per million tokens on the Claude API, input / output: Fable 5.1 $10 / $50, Opus 5.5 $4 / $20, Sonnet 5.5 $2 / $10, Haiku 5.5 $0.10 / $0.50 for prompts up to 100,000 tokens ($0.50 / $2.50 above). The Batch API halves all of these. See our Claude API pricing guide for caching and legacy models.

What model does Claude Code use by default?

Per Claude Code's model configuration docs, default resolves to Opus 5.5 on Pro, Max, Ultra, Team and Enterprise plans and on the Anthropic API. On Microsoft Foundry it is Sonnet 4.5. Fable models are never the default; select them with /model fable.

Do Claude models have different context windows?

Not in the current lineup. Fable 5.1, Opus 5.5, Sonnet 5.5 and Haiku 5.5 all have a 1M-token context window and 128K max output on the synchronous Messages API. Haiku 5.5 does charge more for prompts over 100,000 tokens.

Is Claude Haiku good enough for coding?

For narrow, high-volume steps, yes: Anthropic positions Haiku 5.5 for subagent tasks, extraction, classification and routing. For writing and refactoring real code, Anthropic's guidance points to Sonnet 5.5 or Opus 5.5. A common pattern is to write the code with Opus or Sonnet and run the resulting classifier with Haiku.

How many tokens is a tweet?

In our 2026 sample of 955 X posts, a full tweet JSON object was about 1,922 tokens at the median, a trimmed 8-field record about 171, and the text alone about 94 (estimates at 2.5 characters per token). A full 20-tweet API page was about 47,595 tokens.

Should I switch models or change the effort level?

Try effort first. Anthropic's choosing-a-model guide says tuning effort "is often a better lever than switching models." Opus 5.5 defaults to medium on the API; raise it for bug fixing or lower it for quick edits before moving to a different model.

11 — Further reading

Continue

Sources & further reading
More from this series
Build it

Stop reading. Start building.

Starter credits cover real testing on real data. Google sign-in, no card, no application queue.

Get an API key

Already building with TwitterAPI.io? Publish an honest tutorial or build log about it and earn up to $200 a month in API credits.