gemini-docs-dbfiles / docstore /034ae534-2b29-4bcf-9871-a9967f35e54c
arshjaved's picture
Upload all project files and folders
2e9b585 verified
Because standard Gemini API text and content generation calls are stateless, when using thinking in multi-turn interactions (such as chat), the model doesn't have access to thought context from previous turns. You can maintain thought context using thought signatures, which are encrypted representations of the model's internal thought process. The model returns thought signatures in the response object when thinking and function calling are enabled. To ensure the model maintains context across multiple turns of a conversation, you must provide the thought signatures back to the model in the subsequent requests. You will receive thought signatures when: Thinking is enabled and thoughts are generated. The request includes function declarations . Note: Thought signatures are only available when you're using function calling, specifically, your request must include function declarations . You can find an example of thinking with function calls on the Function calling page. Other usage limitations to consider with function calling include: Signatures are returned from the model within other parts in the response, for example function calling or text parts. Return the entire response with all parts back to the model in subsequent turns. Don't concatenate parts with signatures together. Don't merge one part with a signature with another part without a signature. Pricing Note: Summaries are available in the free and paid tiers of the API. Thought signatures will increase the input tokens you are charged when sent back as part of the request. When thinking is turned on, response pricing is the sum of output tokens and thinking tokens. You can get the total number of generated thinking tokens from the thoughtsTokenCount field. Python # ... print ( "Thoughts tokens:" , response . usage_metadata . thoughts_token_count ) print ( "Output tokens:" , response . usage_metadata . candidates_token_count ) JavaScript // ... console . log ( `Thoughts tokens: ${ response . usageMetadata