How to retrieve "Thoughts" (reasoning process) along with the response using Gemini API?

Hello community,

I’m currently working with the Gemini API, and I’m interested in obtaining not just the final generated response, but also the underlying reasoning process or “thoughts” that the model goes through to arrive at that response. I’ve seen this referred to as “Thoughts (experimental)” in some contexts.

The primary reason I want to access these “thoughts” is to record the model’s reasoning process, which will help me debug and refine my prompts more effectively. By understanding the steps the model takes, I can better identify why it might be producing a certain output and how to guide it towards the desired outcome.

My goal is to be able to programmatically access and log this step-by-step thinking process alongside the final content generated by the model.

Could anyone provide guidance or point me to the relevant documentation on how to achieve this via an API call?

Specifically, I’m looking for information on:

  1. Are there specific parameters or flags in the API request that I need to set to enable the inclusion of these “thoughts”?

  2. Does this capability depend on the specific Gemini model being used (e.g., Gemini 2.5 Pro, Gemini 2.5 Flash, etc.)?

  3. How is this “thoughts” or reasoning data typically structured within the API response object? (e.g., Is it a separate field? Part of the content.parts? Does it require a specific way of parsing the response?)

Any code examples (Python with the google-generativeai library would be great, but any language is fine) or pointers to the exact section in the API documentation that covers this would be highly appreciated.

Thank you in advance for your help and insights!


This addition makes your request clearer and provides strong motivation for why you need this feature. Good luck with your forum post!

Hi @dearcloud09 , Welcome to the forum.

We already have a similar discussion on this topic. Unfortunately, when using the gemini API, the thought output is not returned, it’s only accessible through Google AI Studio.

Thanks