← Blog

Claude API Chain of Thought Prompting Guide

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

Chain of thought (CoT) prompting is a technique where you ask Claude to work through a problem step by step before giving a final answer, instead of jumping straight to a conclusion. On the Claude API, you implement this either by explicitly instructing the model to reason out loud in your prompt, or by using Claude's built-in extended thinking feature, which produces a structured reasoning block separate from the final response.

The short answer to "how do I do chain of thought prompting with the Claude API": for most tasks, add explicit instructions to your prompt asking Claude to break the problem down before answering, and structure the output so reasoning and final answer are clearly separated (e.g. with XML tags). For harder reasoning tasks — math, multi-step logic, debugging, planning — use Claude's extended thinking mode, which is designed specifically for this and generally outperforms manually-prompted CoT.

Why chain of thought prompting works

Language models generate tokens sequentially, and each generated token becomes context for the next one. When you force the model to write out intermediate reasoning steps, those steps become part of the context it uses to produce the final answer. This reduces the chance of skipping a logical step or jumping to a plausible-sounding but wrong conclusion, especially on tasks involving arithmetic, multi-condition logic, or multi-step planning.

The tradeoff is token usage: CoT responses are longer, which means higher latency and cost. It's worth reserving explicit CoT for tasks where accuracy actually depends on it — simple classification, extraction, or short-answer tasks usually don't benefit and just waste tokens.

Manual chain of thought prompting

The simplest approach is to ask directly in your system or user prompt:

Solve this problem. First, think through the problem step by step,
showing your reasoning. Then give your final answer on a new line
prefixed with "Answer:".

A more robust version separates reasoning from the answer using tags, which makes parsing easier downstream:

Before answering, work through the problem inside <thinking> tags.
Then give your final answer inside <answer> tags. Only the content
inside <answer> should be a direct response to the user's question.

Example request:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "A train leaves at 2pm traveling 60mph. Another leaves at 3pm from the same station traveling 90mph in the same direction. At what time does the second train catch the first? Use <thinking> and <answer> tags."
      }
    ]
  }'

Claude will output a <thinking> block with the step-by-step math, followed by an <answer> block with just the result. You can then parse the response and show users only the answer, or expose the reasoning for transparency and debugging.

Prompt patterns that improve CoT quality

Using extended thinking instead

For genuinely hard reasoning tasks, Claude's extended thinking mode is a better fit than manual CoT prompting. Instead of instructing the model to narrate its reasoning in the visible response, you enable a thinking parameter and Claude generates a dedicated reasoning block with an allocated token budget, then produces the final answer separately. This tends to produce deeper, more coherent reasoning chains than prompt-based CoT, particularly on problems that require backtracking or exploring multiple approaches before settling on one.

The rough shape of a request with extended thinking looks like this:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 2048,
    "thinking": { "type": "enabled", "budget_tokens": 1024 },
    "messages": [
      { "role": "user", "content": "Plan a database schema for a multi-tenant SaaS with row-level isolation. Explain tradeoffs." }
    ]
  }'

The response includes a thinking block ahead of the final text block. You generally shouldn't try to prompt-inject formatting into the thinking block itself — let the model reason freely there, and put your formatting/output instructions in the prompt targeting the final answer.

Streaming chain of thought output

If you're building a UI that shows reasoning progress to users, both manual CoT and extended thinking work with streaming — you'll receive the reasoning tokens incrementally before the final answer tokens. See the streaming docs for the event format if you're building this against SubToAPI: /docs/streaming.

Doing this through SubToAPI

If you're already routing Claude traffic through SubToAPI, chain of thought prompting works exactly the same way — it's a prompting technique, not a special API mode, so nothing changes at the transport layer. You send the same thinking parameter or the same explicit reasoning instructions to https://api.subtoapi.app/v1/messages with your sub_live_... key, and get back usage metadata alongside the response so you can track how much extra token spend CoT is costing you per request. That's useful when you're deciding whether a given endpoint actually needs extended reasoning or can run cheaper without it. See /docs/messages for the request format and /docs/quickstart to get a key.

FAQ

Does chain of thought prompting actually improve Claude's accuracy?

Yes, for multi-step reasoning tasks like math, logic puzzles, and planning. For simple lookups, classification, or short factual answers it usually adds latency and cost without meaningfully improving correctness, so apply it selectively.

What's the difference between manual CoT and extended thinking?

Manual CoT is prompt instructions asking Claude to reason in the visible response text. Extended thinking is a built-in API feature with a dedicated thinking parameter and token budget that produces a separate, more thorough reasoning block, typically with better results on hard problems.

Should I show the reasoning steps to end users?

It depends on the product. Showing reasoning builds trust and helps debugging, but it increases response length and can expose intermediate mistakes. A common pattern is to log the full CoT output server-side and only display the final answer in the UI.

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 →