# Thinking
Many recent models support "extended thinking", in which the model uses additional tokens to reason about the prompt, before generating its response. This can improve performance, especially for complex tasks like math, coding, or multi-step reasoning.
Mirascope supports enabling and configuring thinking, as well as viewing the model's generated thoughts.
## Enabling Thinking
Configure thinking via the `thinking` parameter, which accepts a `ThinkingConfig`:
```python
from mirascope import llm
@llm.call("google/gemini-3-pro", thinking={"level": "high", "include_thoughts": True})
def solve(problem: str) -> str:
return problem
response = solve("What is the first prime number that contains 42 as a substring?")
print(response.pretty())
```
### Thinking Levels
The `level` field controls how much reasoning the model performs. If set to `"default"`, then we'll respect that provider's default behavior. Otherwise, you can configure it by choosing `"none"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, or `"max"`.
The interpretation of the thinking level depends on the model and provider. Some model's don't support thinking at all, while others don't allow you to disable it, or only support two levels, like `"low"` and `"high"`. Mirascope will choose the setting that best matches your chosen thinking level.
## Accessing Thoughts
To include the model's reasoning in the response, set `include_thoughts=True`. The thoughts will then appear in `response.thoughts`.
```python
from mirascope import llm
@llm.call(
"anthropic/claude-sonnet-4-5",
thinking={"level": "medium", "include_thoughts": True},
)
def solve(problem: str) -> str:
return problem
response = solve("How many primes below 100 contain 7 as a digit?")
for thought in response.thoughts:
print(f"Thought: {thought.thought}")
print(f"Answer: {response.texts[0].text}")
```
Each `llm.Thought` contains a `thought` string with the model's reasoning. Depending on the provider, this may be a summary of the reasoning process (often generated by a different model), or the raw reasoning tokens themselves. Some providers may charge additional fees for thought content.
<Note>
Without `include_thoughts=True`, thoughts will not be included in the response, even if the model is using thinking internally.
</Note>
## Reasoning Token Usage
While a model's reasoning may not be part of the final output, you will still be billed for the token usage. Access `response.reasoning_tokens` to see how many tokens the reasoning process generated. Note that the `output_tokens` field includes *all* output tokens, including reasoning tokens.
<Note>
Not every model breaks out reasoning tokens separately from output tokens. (For example: Anthropic doesn't.) In such cases, the reasoning_tokens will always be 0.
</Note>
## Cross-Provider Thought Persistence
By default, when you pass a conversation with thoughts to a different model, those thoughts may be ignored—providers handle prior reasoning differently, and often the actual thoughts are persisted on the server-side.
Set `encode_thoughts_as_text=True` to re-encode thoughts as regular text content, ensuring the new model can read the prior reasoning:
```python
from mirascope import llm
@llm.call(
"anthropic/claude-sonnet-4-5",
thinking={"level": "medium", "include_thoughts": True},
)
def analyze(question: str) -> str:
return question
response = analyze("List the first 10 prime numbers.")
# Resume with a different provider, encoding thoughts as text
# so the new model can read the prior reasoning
with llm.model(
"openai/gpt-5-mini",
thinking={"level": "none", "encode_thoughts_as_text": True},
):
followup = response.resume("What's the sum of those primes?")
print(followup.pretty())
```
This is primarily useful when:
- Switching providers mid-conversation
- Working around provider-specific limitations on thought persistence
- Ensuring reasoning is preserved across tool call boundaries
<Note>
When `encode_thoughts_as_text=True`, Mirascope re-encodes messages rather than reusing raw provider responses. This may disable provider-specific optimizations like cached reasoning tokens.
</Note>
## Next Steps
- [Tools](/docs/learn/llm/tools) — Combine thinking with tool calling
- [Streaming](/docs/learn/llm/streaming) — Learn more about streaming responses
- [Agents](/docs/learn/llm/agents) — Build agents that reason through complex tasks