Claude Sonnet 5 vs Opus 5: Which Should You Use for Coding? (Cost per Finished Task)
Sonnet 5 or Opus 5 for coding? Blogs quote conflicting benchmarks and even conflicting prices. This guide sticks to Anthropic's own spec pages, then gives you a repeatable test and a cost-per-finished-task formula so your own repo decides.
1. The decision rule in one sentence
Search for this comparison and you will find blogs quoting SWE-bench numbers that contradict each other, and at least one that quotes a different Sonnet 5 price from the one on Anthropic's own page. Rather than pick a side, use a rule that survives any benchmark: escalate to Opus 5 when the cost of a wrong answer is larger than the price difference for that task. A failed unit-test rewrite costs you a re-run; a refactor that silently breaks three services costs you an afternoon. A lot of day-to-day coding falls into the first bucket, which is why Sonnet 5 makes sense as the default. The rest of this guide is about measuring that rule on your own code instead of guessing.
2. What the official spec sheets actually say
Everything in this section comes from Anthropic's model pages at platform.claude.com, checked in October 2026; recheck them before relying on any number. Shared: 1M-token context window, 128K max output on the synchronous Messages API, adaptive thinking, default effort `high`, text and image input with text output, and up to 300K output tokens on the Message Batches API with a beta header. Different: list price ($2 / $10 for Sonnet 5 versus $5 / $25 for Opus 5 per million input / output tokens), reliable knowledge cutoff (January 2026 versus May 2026) and release date (June 30, 2026 versus July 24, 2026). Lifecycle: both pages now label the model legacy, with retirement not sooner than June 30, 2027 for Sonnet 5 and July 24, 2027 for Opus 5. The knowledge cutoff gap matters more than people expect: if your stack uses libraries released in early 2026, Opus 5 has simply seen more of them.
3. Price each finished task, not each token
Per-token price tells you nothing about what a working change costs. Use cost per finished task = total spend on a batch ÷ number of tasks that ended in an accepted change. A task that needed four rounds of corrections, or that you abandoned and fixed by hand, still spent tokens. Illustrative arithmetic: if Sonnet 5 spends $1.20 on ten tasks and finishes six, that is $0.20 per finished task; if Opus 5 spends $2.40 and finishes nine, that is about $0.27 — closer than the list price suggests, and possibly worth it if the three extra finishes were the hard ones. Two hidden variables move this number: output length (both models default to high effort, and thinking shows up in the usage figures, so compare usage.output_tokens with the text you actually see) and context growth in long sessions, where every turn resends history. For monthly budgeting, see /hub/llm-api-monthly-cost-estimate.
No overseas card needed: cocodot's OpenAI-compatible API — switch your base_url to call the models on sale.
Top up via Alipay / WeChat Pay, USDT / USDC · billed per token · switch your base_url to connect
4. A one-afternoon test on your own repo
Pick ten tasks you or your team actually did last month, in three groups: four scoped tasks (add a field, write tests for one module), three cross-file tasks (rename a concept used in several packages, change an interface and its callers) and three fuzzy tasks (a bug report with no reproduction steps). Run each task on both models with the same prompt, the same tool settings and a fresh session. Record four numbers per run: did the test suite pass on the first attempt, how many follow-up turns you needed, total tokens from the usage field, and files touched that should not have been. That last one is the clearest signal on cross-file work — a model that edits unrelated files costs you review time even when tests pass. Ten tasks is small, but it is your code, and it beats any leaderboard built on someone else's.
5. Where Opus 5 earns its price, and where it does not
From the test above, a common pattern is easy to predict. Worth escalating: requirements you cannot state precisely, refactors where five or more files must change consistently, long autonomous agent runs where an early wrong judgment corrupts every later step, and bugs Sonnet 5 has already failed twice. Usually wasted: completions, renames, CRUD endpoints, format conversions, unit tests for code that already exists, and explaining a function. A practical setup is to keep Sonnet 5 as the main model in your editor or agent and switch the model name for a specific task when you hit one of the first group. Because both run on the same key, that switch is a one-line change. If you are weighing Anthropic against OpenAI's flagship instead, see /hub/opus-5-vs-gpt-56-sol.
6. Migration gotchas before you switch
Three details from the official pages catch people out. First, sampling parameters: Anthropic's Sonnet 5 page states that setting temperature, top_p or top_k to non-default values returns a 400 error, so an older script or tool config that sets temperature will break when pointed at Sonnet 5 — remove those fields rather than guessing at values. Second, legacy status: Anthropic recommends migrating to Sonnet 5.5 and Opus 5.5; legacy models stay available until their retirement dates, but plan the move instead of discovering it from an error. Third, pin exact model IDs (claude-sonnet-5, claude-opus-5) in configuration rather than scattering them through code, so a later switch is one edit. If a renamed or retired ID starts returning a model-not-found error, the troubleshooting order is in /hub/api-model-not-found-fix; for overloaded responses during busy hours, see /hub/claude-api-529-overloaded.
7. Caching and long sessions: an honest note
Long coding sessions resend the same system prompt and file context on every turn, so prompt caching matters more than model choice for many teams. Officially, Anthropic lists cache reads at $0.20 per million tokens for Sonnet 5 and $0.50 for Opus 5, with 5-minute cache writes at $2.50 and $6.25 and 1-hour cache writes at $4 and $10 respectively; the Opus 5 page also notes a minimum cacheable prompt of 512 tokens. On cocodot, cache hits are billed at half the input price, and cache writes at 1.25x the input price (2x for the portion written to the 1-hour cache), the same structure as the official pricing. That means if your workload is dominated by cache hits, such as an agent rereading a large codebase all day, going direct to Anthropic is cheaper, and you should do that. Where a gateway helps is the output side, uncached input, and paying when your usual card is not accepted. When the context outgrows the window anyway, see /hub/context-length-exceeded-fix.
8. Calling both models through cocodot
cocodot exposes an OpenAI-compatible endpoint: set base_url to https://cocodot.co/api/ai/v1, send Authorization: Bearer with your key, and set model to mcs-6 (Claude Sonnet 5) or mco-7 (Claude Opus 5); the official names claude-sonnet-5 and claude-opus-5 map to the same models. For Claude Code, export ANTHROPIC_BASE_URL=https://cocodot.co/api/ai, set ANTHROPIC_AUTH_TOKEN to your cocodot key and ANTHROPIC_MODEL to mcs-6 or mco-7; the full setup is in /hub/claude-code. Whether other models, including the 5.5 versions, are available on cocodot and under which names is shown by the public model list at GET https://cocodot.co/api/ai/v1/models. Listed Claude / GPT / Gemini rates are at or below the official list price; check the pricing page for each model's current rate. Top-ups are by Alipay / WeChat Pay, USDT / USDC. The trial credit from email verification is usable after your first top-up, so add a small balance before testing either of these. If you want to confirm you are getting the model you asked for from any gateway, the checks are in /hub/ai-relay-model-downgrade-verify.
Side by side (official values from Anthropic's model pages, checked October 2026)
| Claude Sonnet 5 | Claude Opus 5 | |
|---|---|---|
| Official list price (input / output per M tokens) | $2 / $10 | $5 / $25 |
| Context window / max output | 1M / 128K | 1M / 128K |
| Thinking / default effort | Adaptive / high | Adaptive / high |
| Reliable knowledge cutoff | January 2026 | May 2026 |
| Status | Legacy (released June 30, 2026) | Legacy (released July 24, 2026) |
| Best fit | Scoped features, tests, reproducible bugs | Ambiguous specs, cross-file refactors, long agent runs |
| Model name on cocodot | mcs-6 (or claude-sonnet-5) | mco-7 (or claude-opus-5) |