← Blog

Claude API Chain of Thought Prompting Guide

2026-09-27 · 5 min read · SubToAPI Team

Chain of thought (CoT) prompting means asking Claude to reason step by step before giving a final answer, instead of jumping straight to a conclusion. It matters because it measurably improves accuracy on math, logic, multi-step planning, and any task where the model benefits from "thinking out loud" rather than pattern-matching to a quick answer.

This guide covers how to structure chain of thought prompts for Claude, when to use Claude's built-in extended thinking versus manual CoT prompting, and how to parse the output reliably in production code.

Why Chain of Thought Works with Claude

Large language models generate tokens sequentially, and each generated token becomes part of the context for the next one. When you force the model to write out intermediate reasoning steps, those steps become available context for producing the final answer. Skip the reasoning and the model has to compress multi-step logic into a single forward pass, which is where errors creep in.

Claude models respond well to explicit instructions to reason before answering. This is especially true for:

Two Ways to Get Chain of Thought Out of Claude

1. Manual prompting

You write the instruction directly into your prompt, asking Claude to think step by step before answering. This works with any Claude model and any API that proxies to it.

Solve this problem. Think through it step by step,
showing your reasoning, before giving your final answer.
Put your final answer on its own line starting with "Answer:".

Problem: A train leaves station A at 60 km/h. Two hours later,
a second train leaves the same station at 90 km/h following
the same route. How far from station A does the second train
catch up to the first?

Claude will typically write out the reasoning ("the first train has a 120 km head start... the second train gains 30 km/h on the first...") before landing on the final numeric answer.

2. Extended thinking (model-native reasoning)

Newer Claude models support extended thinking, where the model produces a separate reasoning block before its response, without you having to hand-craft the "think step by step" instruction. This is more reliable for hard problems because the model is trained specifically to use that reasoning space effectively, and the thinking budget can be tuned per request.

If you're calling Claude directly, check the current model documentation for how to enable extended thinking and set a thinking token budget. If you're routing requests through SubToAPI, the same message parameters pass through to the underlying model, so extended thinking works the same way it does with a direct integration — see /docs/messages for the request shape.

A Practical CoT Prompt Template

A reusable structure that works well for most reasoning tasks:

You are solving a problem that requires careful reasoning.

1. Break the problem into sub-steps.
2. Work through each sub-step explicitly.
3. Check your work for errors before finalizing.
4. Give your final answer in the format: "Answer: <result>"

Problem: {problem}

Keeping the output format explicit (step 4) matters more than people expect. Without it, you'll get inconsistent formatting that's annoying to parse downstream — sometimes the answer is in the last sentence, sometimes it's bolded, sometimes it's buried in a paragraph.

Example: Calling Claude via SubToAPI with CoT

If you're using SubToAPI to turn your Claude access into an API key-based service, a chain of thought request looks like this:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "A store had 240 items. It sold 35% on Monday and 20% of the remainder on Tuesday. How many items are left? Think step by step, then give the final number on its own line starting with Answer:."
      }
    ]
  }'

In JavaScript:

const res = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "claude-sonnet-4-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content:
          "List the pros and cons of using a message queue vs direct API calls for this scenario: a checkout service that needs to notify inventory, email, and analytics. Reason through each option before concluding.",
      },
    ],
  }),
});

const data = await res.json();
console.log(data.content[0].text);

Because SubToAPI exposes usage metadata per request, you can also track how much reasoning cost you're spending on CoT prompts versus direct-answer prompts, which is useful when a subset of your traffic (e.g., complex support tickets) needs deeper reasoning and the rest doesn't. See /docs/quickstart to get an API key set up.

Parsing the Output Reliably

Don't try to regex out reasoning from a single blob of prose. Instead:

  1. Enforce a clear delimiter in your prompt (Answer: on its own line, or ask for JSON with a reasoning and answer field).
  2. If you need structured output, combine CoT with a tool definition so Claude returns a structured result after reasoning — see /docs/tools for how tool calls work through the API.
  3. Log the full reasoning trace in development so you can debug why the model reached a given conclusion, but strip it from what you show end users unless transparency is part of the product.

When Not to Use Chain of Thought

CoT adds latency and token cost. Skip it for:

For everything else — math, planning, multi-hop reasoning, debugging — the accuracy improvement from explicit reasoning steps is usually worth the extra tokens.

Questions

Does chain of thought prompting increase API costs? Yes. The reasoning tokens Claude generates before the final answer count toward output tokens, so CoT prompts and extended thinking cost more per request than direct-answer prompts. Reserve it for tasks where accuracy gains justify the extra spend.

Is chain of thought the same as extended thinking? No. Manual CoT is a prompting technique you write yourself ("think step by step"). Extended thinking is a model-native feature where Claude generates a dedicated reasoning block, often with a configurable token budget, and tends to produce more reliable reasoning on hard problems.

How do I stop Claude from showing its reasoning to end users? Ask for a clear final-answer delimiter (like a line starting with "Answer:") and parse only that portion in your application, or use a tool call to get structured output after the reasoning step. Store the full trace in logs if you need it for debugging.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →