Update everything to use google-genai SDK
Description of the feature request:
Lots of notebooks are using the google-generativeai SDK, but now that google-genai is at 1.0, we should be using that.
e.g. pip install google-generativeai needs to be replaced with pip install google-genai and then relevant code and text needs to be updated.
There's lots to do right now, but we can do every notebook independently so this would be a great one to open to community contributions. If you want to work on one, check the open PR list to see if someone has already done it, then just send a PR directly (but stick to one notebook per PR).
And here's the migration guide: https://ai.google.dev/gemini-api/docs/migrate
Are there plans to create a google-genai SDK for JS?
Updating Anomaly_detection_with_embeddings.ipynb. Informed to avoid duplicate efforts by other contributors, thanks
Are there plans to create a google-genai SDK for JS?
I guess we already have it https://github.com/google-gemini/generative-ai-js, currently at google/[email protected] at the time of comment.
@markmcd need help in accepting Google contributor licence agreement there is always an server error. Any suggestions?
@markmcd need help in accepting Google contributor licence agreement there is always an server error. Any suggestions?
I also have the same issue.
Are there plans to create a google-genai SDK for JS?
@mitrick2 A new typescript unified SDK is on its way. (and BTW, we're also accepting submissions in other languages than Python if you have great examples)
@charantek1styearbtech @ROHANDWIVEDI2005 @Faakhir30 As for the CLA issue, it's being investigated internally. And it seems it was fixed a couple of hours ago, so please try again and tell me if that still doesn't work.
Thanks you all for your contributions!
Hey all,
Thanks a lot for all your submissions! This is greatly helping us.
I've fallen sick and I have to prepare 4 talks for next week (here, if you are in Paris) so I couldn't find the time to review all the Pull requests. But rest assured that I'm not forgetting you and I'll catch up with everything you submitted next week.
Hi @markmcd @Giom-V
While updating the notebooks to use the new google-genai SDK, I noticed that start_chat() and send_message() are still available, but they no longer retain chat history automatically like they did in google-generativeai.
In the previous SDK, chat history was managed within the chat object, allowing past interactions to persist. For example, in Prompting.ipynb
model = genai.GenerativeModel('gemini-2.0-flash')
chat = model.start_chat(history=[])
With google-genai, start_chat() does not seem to keep track of previous exchanges. Instead, it looks like we now need to manually store and pass chat history with each request.
To address this, I plan to store chat history as a list of dictionaries, where each entry contains a role ("user" or "model") and the message content. The model’s response is then appended back to the list to ensure continuity in future exchanges.
Can you confirm if this is the correct approach, or is there a recommended way to handle chat history in google-genai?
Thank you!
I also got confused at first but there's still a way to get the history. Check the function calling notebook that I updated last week, I use it in there for the example without automatic FC.
Thank you, @Giom-V. I will check the function calling notebook for reference.
Use chat.get_history() in Python SDK 1.5 or higher.
Hi @markmcd, @Giom-V,
I've created several PRs that migrate cookbook examples to use the new google-genai SDK as requested in the issue. These migrations maintain the original functionality while updating the API calls to the latest version.
PR links:
- https://github.com/google-gemini/cookbook/pull/590
- https://github.com/google-gemini/cookbook/pull/589
- https://github.com/google-gemini/cookbook/pull/587
I've thoroughly tested each example to ensure they run correctly with the updated SDK.
Thank you, Chamika Jayasinghe
Hi @markmcd, @Giom-V I have finished migrating the Search_Wikipedia_using_ReAct.ipynb to new google-genai sdk from old google-generative-ai sdk. and ready to make a pull request and informing others to avoid duplicate submissions. The code looks good but I think we need to modify the model_instructions.txt file because the code output seems to be incorrect. We can open a new issue for this one that needs a fix. I have attached a screenshot for reference along with the correct output from the web. Do let me know.
Thank You Raunak Nag
If anyone is interested in picking up where me and @Giom-V left off at #487, please feel free to!
Thank you all for your submission (especially those of you who migrated dozen of notebooks).
I made a quick check on what had not been migrated yet so you can have a quick way to find something to work on:
- quickstarts/Video.ipynb: https://github.com/google-gemini/cookbook/pull/592
- quickstarts/Safety.ipynb: https://github.com/google-gemini/cookbook/pull/634
- quickstarts/Error_handling.ipynb: Not sure if the new SDK supports it but give it a try!
- quickstarts/PDF_files.ipynb: https://github.com/google-gemini/cookbook/pull/626
- examples/Search_Wikipedia_using_ReAct.ipynb: https://github.com/google-gemini/cookbook/pull/604
- examples/Voice_memos.ipynb: https://github.com/google-gemini/cookbook/pull/589
- examples/Translate_a_Public_Domain_Book.ipynb
- quickstarts/New_in_002.ipynb: No need to migrate, I'll merge it into an "advanced parameter notebook" (or make this one instead ;))
- examples/Classify_text_with_embeddings.ipynb: https://github.com/google-gemini/cookbook/pull/622
- quickstarts/Tuning.ipynb: No need to migrate as it's a 1.5 feature only at the moment
- quickstarts/Authentication_with_OAuth.ipynb: No need to migrate, I'm not sure if that's still possible
- examples/langchain/Chat_with_SQL_using_langchain.ipynb: https://github.com/google-gemini/cookbook/pull/646
- examples/prompting/Zero_shot_prompting.ipynb: https://github.com/google-gemini/cookbook/issues/621
- examples/Search_reranking_using_embeddings.ipynb: https://github.com/google-gemini/cookbook/pull/637
- examples/prompting/Few_shot_prompting.ipynb: https://github.com/google-gemini/cookbook/pull/639
- examples/Story_Writing_with_Prompt_Chaining.ipynb: https://github.com/google-gemini/cookbook/pull/644
- examples/prompting/Role_prompting.ipynb: https://github.com/google-gemini/cookbook/pull/579
- examples/prompting/Providing_base_cases.ipynb: https://github.com/google-gemini/cookbook/pull/643
- examples/prompting/Basic_Evaluation.ipynb: https://github.com/google-gemini/cookbook/pull/642
- examples/weaviate/personalized_description_with_weaviate_and_gemini_api.ipynb
- quickstarts/Function_calling_config.ipynb: I think it would be better to merge it into the function calling notebook: https://github.com/google-gemini/cookbook/pull/631
Once again thank you all and don't hesitate to continue to improve the cookbook by fixing typos, adding missing examples (like an example using generate_content instead of chat for the grounding, or a function calling example using a OpenAPI schema object like we do on AI Studio), or maybe just proposing more interesting or more fun prompts in the notebook (just keep in mind the is still Google stuff we you can't be too unhinged so I might be difficult).
If anyone is interested in picking up where me and @Giom-V left off at #487, please feel free to!
I‘ve migrated examples/Classify_text_with_embeddings.ipynb in #622. Feel free to check it out!
Hi @markmcd, @Giom-V I have finished migrating the Search_Wikipedia_using_ReAct.ipynb to new google-genai sdk from old google-generative-ai sdk. and ready to make a pull request and informing others to avoid duplicate submissions. The code looks good but I think we need to modify the model_instructions.txt file because the code output seems to be incorrect. We can open a new issue for this one that needs a fix. I have attached a screenshot for reference along with the correct output from the web. Do let me know.
Thank You Raunak Nag
![]()
![]()
Hi @markmcd, @Giom-V I have finished migrating the Search_Wikipedia_using_ReAct.ipynb to new google-genai sdk from old google-generative-ai sdk. and ready to make a pull request and informing others to avoid duplicate submissions. The code looks good but I think we need to modify the model_instructions.txt file because the code output seems to be incorrect. We can open a new issue for this one that needs a fix. I have attached a screenshot for reference along with the correct output from the web. Do let me know.
Thank You Raunak Nag
![]()
![]()
@markmcd @Giom-V Do review this once!
Hi everyone! If this topic is still open, I'd like to contribute — could you let me know exactly what I need to do?
Hi everyone! If this topic is still open, I'd like to contribute — could you let me know exactly what I need to do?
Thanks for volunteering your help. The easiest is to take one of the notebooks I listed in this post that isn't been worked on (double-check the open pull request just in case). And then migrate them to use the new google-genai SDK following this migration guide.
Be warned that I'll likely ask you to not only update the code but to also correct the wording if it's a bit old and to improve the readability of the code in various ways. You can check past PR to get an idea.
@All, I will be travelling to Google Cloud Next this week, which mean that I won't have much time to review and merge all of your pull requests (especially since there are more and more every day... and think you for that!).
I know that some of you wanted to use them to apply for the GSoC, feel free to still use them, even if they haven't been merged yet.
Hi @Giom-V Have a safe trip and good luck with your meetings.
I made a new PR #679 to update the weaviate example
Hey @Mu-Magdy , I think you didn't notice, I already submitted a PR for that notebook #659
Hi @andycandy Yes I didn't notice at first. But I think you need to update you pr to be reviewable. I can help with that if you want
Hi @andycandy Yes I didn't notice at first. But I think you need to update you pr to be reviewable. I can help with that if you want
No, thank you tho. It was an old PR which I didn't get time to check back. It's all updated now :)
@Giom-V I have submitted PR #768 to update the notebook with the new SDK. Please let me know if there is anything else I should do.
Hi @markmcd, is this topic still open and what exactly needs to be done to solve this? I see this examples/Voice_memos.ipynb has not been updated with the new sdk. Should i update this?

