How to beginner to intermediate · 3 min read

Reasoning models use cases

Quick answer
Reasoning models like deepseek-reasoner and claude-sonnet-4-5 excel at tasks requiring multi-step logic, complex problem solving, and decision making. Use cases include code debugging, mathematical proofs, legal analysis, and scientific research where stepwise reasoning is critical.

PREREQUISITES

  • Python 3.8+
  • OpenAI API key (free tier works)
  • pip install openai>=1.0

Setup

Install the openai Python SDK and set your API key as an environment variable.

  • Run pip install openai
  • Set environment variable OPENAI_API_KEY with your API key
bash
pip install openai

Step by step

Use a reasoning model like deepseek-reasoner to solve a multi-step logic problem. The example below queries the model to explain a logic puzzle stepwise.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

messages = [
    {"role": "user", "content": "Explain step-by-step how to solve this puzzle: If all cats are animals and some animals are dogs, can some cats be dogs?"}
]

response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=messages
)

print(response.choices[0].message.content)
output
Step 1: All cats are animals, so cats are a subset of animals.
Step 2: Some animals are dogs, meaning dogs are another subset of animals.
Step 3: Since cats and dogs are subsets of animals, but no direct overlap is stated, some cats cannot be dogs.
Conclusion: No, some cats cannot be dogs based on the given information.

Common variations

You can use other reasoning-capable models like claude-sonnet-4-5 or gpt-4o for similar tasks. Async calls and streaming outputs are also supported in their respective SDKs.

python
import os
from anthropic import Anthropic

client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=512,
    system="You are a reasoning assistant.",
    messages=[{"role": "user", "content": "Prove by logic if the statement 'If it rains, the ground is wet' implies 'If the ground is not wet, it did not rain'."}]
)

print(message.content[0].text)
output
Yes, this is an example of contrapositive logic: 'If it rains, the ground is wet' logically implies 'If the ground is not wet, it did not rain.'

Troubleshooting

If the model returns vague or incomplete reasoning, increase max_tokens or clarify the prompt with explicit stepwise instructions. For API errors, verify your API key and model name.

Key Takeaways

  • Use reasoning models for tasks requiring multi-step logic and complex problem solving.
  • Models like deepseek-reasoner and claude-sonnet-4-5 excel at code debugging, legal analysis, and scientific reasoning.
  • Clarify prompts and adjust token limits to improve reasoning output quality.
Verified 2026-04 · deepseek-reasoner, claude-sonnet-4-5, gpt-4o
Verify ↗