Repository: google-gemini/cookbook
Pull request #503: Migrating the outdated quickstarts examples
Author: login: andycandy
Labels: name: status:awaiting response
description: Awaiting a response from the author
name: component:quickstarts
description: Issues/PR referencing quickstarts folder
Created: 2025-03-04T19:40:57Z | Merged: 2025-03-24T05:52:05Z

Quickstart examples still come with outdated SDKs, which require migration to latest 'google-genai' python SDK


Diff:
diff --git a/quickstarts/Asynchronous_requests.ipynb b/quickstarts/Asynchronous_requests.ipynb
index 01313efb5..cc3eae903 100644
--- a/quickstarts/Asynchronous_requests.ipynb
+++ b/quickstarts/Asynchronous_requests.ipynb
@@ -6,12 +6,12 @@
         "id": "YuXYZBmuHYxa"
       },
       "source": [
-        "##### Copyright 2024 Google LLC."
+        "##### Copyright 2025 Google LLC."
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 1,
+      "execution_count": null,
       "metadata": {
         "cellView": "form",
         "id": "Q2fjiWA5HetI"
@@ -59,18 +59,18 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 2,
+      "execution_count": null,
       "metadata": {
         "id": "CUCIiuo60vgI"
       },
       "outputs": [],
       "source": [
-        "%pip install -qU 'google-generativeai>=0.8.3' aiohttp"
+        "%pip install -qU 'google-genai' aiohttp"
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 3,
+      "execution_count": null,
       "metadata": {
         "id": "xuqMdClt-7Jp"
       },
@@ -80,20 +80,7 @@
         "import asyncio\n",
         "import io\n",
         "import PIL\n",
-        "import google.generativeai as genai"
-      ]
-    },
-    {
-      "cell_type": "code",
-      "execution_count": 4,
-      "metadata": {
-        "id": "qRvMY4eb_h8j"
-      },
-      "outputs": [],
-      "source": [
-        "# This notebook should work fine in a normal Python environment, but due to https://github.com/google-gemini/generative-ai-python/issues/499\n",
-        "# this workaround is needed in Colab, effectively un-monkey-patching a Colab patch.\n",
-        "genai.configure = getattr(genai.configure, \"func\", genai.configure)"
+        "from google import genai"
       ]
     },
     {
@@ -109,7 +96,7 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 5,
+      "execution_count": null,
       "metadata": {
         "id": "JiXbEhpl_0ya"
       },
@@ -118,7 +105,7 @@
         "from google.colab import userdata\n",
         "\n",
         "GOOGLE_API_KEY = userdata.get(\"GOOGLE_API_KEY\")\n",
-        "genai.configure(api_key=GOOGLE_API_KEY)"
+        "client = genai.Client(api_key=GOOGLE_API_KEY)"
       ]
     },
     {
@@ -134,14 +121,12 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 6,
+      "execution_count": null,
       "metadata": {
         "id": "D1Sw3UzEFekL"
       },
       "outputs": [],
       "source": [
-        "model = genai.GenerativeModel(\"gemini-2.0-flash\")\n",
-        "\n",
         "prompt = \"Describe this image in just 3 words.\"\n",
         "\n",
         "img_filenames = [\"firefighter.jpg\", \"elephants.jpeg\", \"jetpack.jpg\"]\n",
@@ -159,7 +144,7 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 7,
+      "execution_count": null,
       "metadata": {
         "id": "iRGHeraNFwTL"
       },
@@ -168,12 +153,12 @@
           "name": "stdout",
           "output_type": "stream",
           "text": [
-            "2025-02-21 13:36:36 URL:https://storage.googleapis.com/generativeai-downloads/images/firefighter.jpg [547369/547369] -> \"firefighter.jpg\" [1]\n",
-            "2025-02-21 13:36:36 URL:https://storage.googleapis.com/generativeai-downloads/images/elephants.jpeg [224007/224007] -> \"elephants.jpeg\" [1]\n",
-            "2025-02-21 13:36:36 URL:https://storage.googleapis.com/generativeai-downloads/images/jetpack.jpg [357568/357568] -> \"jetpack.jpg\" [1]\n",
-            "FINISHED --2025-02-21 13:36:36--\n",
-            "Total wall clock time: 0.4s\n",
-            "Downloaded: 3 files, 1.1M in 0.02s (69.0 MB/s)\n"
+            "2025-03-04 18:19:03 URL:https://storage.googleapis.com/generativeai-downloads/images/firefighter.jpg [547369/547369] -> \"firefighter.jpg.1\" [1]\n",
+            "2025-03-04 18:19:03 URL:https://storage.googleapis.com/generativeai-downloads/images/elephants.jpeg [224007/224007] -> \"elephants.jpeg.1\" [1]\n",
+            "2025-03-04 18:19:03 URL:https://storage.googleapis.com/generativeai-downloads/images/jetpack.jpg [357568/357568] -> \"jetpack.jpg.1\" [1]\n",
+            "FINISHED --2025-03-04 18:19:03--\n",
+            "Total wall clock time: 0.2s\n",
+            "Downloaded: 3 files, 1.1M in 0.01s (88.7 MB/s)\n"
           ]
         }
       ],
@@ -187,14 +172,14 @@
         "id": "AyUIpSnnJD4W"
       },
       "source": [
-        "The async code uses the `generate_content_async` method to invoke the API. Most API methods have an `_async` variant that provides this functionality.\n",
+        "The async code uses the `aio.models.generate_content` method to invoke the API. Most async API methods can be found in the [`aio`](https://googleapis.github.io/python-genai/genai.html#genai.client.AsyncClient) namespace.\n",
         "\n",
         "Note that this code is not run in parallel. The async call indicates that the event loop *can* yield to other tasks, but there are no other tasks scheduled in this code. This may be sufficient, e.g. if you are running this in a web server request handler as it will allow the handler to yield to other tasks while waiting for the API response."
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 8,
+      "execution_count": null,
       "metadata": {
         "id": "AXcB_yPGFlZd"
       },
@@ -203,9 +188,10 @@
           "name": "stdout",
           "output_type": "stream",
           "text": [
-            "Cat in tree\n",
-            "Elephant family crossing\n",
-            "Jetpack backpack concept.\n"
+            "Cat stuck tree\n",
+            "Elephant family grouping.\n",
+            "\n",
+            "Jetpack backpack sketch\n"
           ]
         }
       ],
@@ -215,7 +201,10 @@
         "  for img_filename in img_filenames:\n",
         "\n",
         "    img = PIL.Image.open(img_filename)\n",
-        "    r = await model.generate_content_async([prompt, img])\n",
+        "    r = await client.aio.models.generate_content(\n",
+        "        model='gemini-2.0-flash',\n",
+        "        contents=[prompt, img]\n",
+        "    )\n",
         "    print(r.text)\n",
         "\n",
         "\n",
@@ -235,7 +224,7 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 9,
+      "execution_count": null,
       "metadata": {
         "id": "RdykoS-G__Tv"
       },
@@ -255,13 +244,16 @@
         "  # concrete Image object would require awaiting the download task before *queueing*\n",
         "  # this content generation task - this approach chains the futures together\n",
         "  # so that the download only starts when the generation is scheduled.\n",
-        "  r = await model.generate_content_async([prompt, await img_future])\n",
+        "  r = await client.aio.models.generate_content(\n",
+        "      model='gemini-2.0-flash',\n",
+        "      contents=[prompt, await img_future]\n",
+        "  )\n",
         "  return r.text"
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 10,
+      "execution_count": null,
       "metadata": {
         "id": "447qlmtD2kWe"
       },
@@ -272,11 +264,11 @@
           "text": [
             "Download and content generation queued for 3 images.\n",
             "\n",
-            "Elephant family grazing\n",
+            "Jetpack Backpack Sketch\n",
             "\n",
-            "Cat stuck tree\n",
+            "Elephant family herd\n",
             "\n",
-            "Jetpack backpack sketch\n"
+            "Cat in tree\n"
           ]
         }
       ],
@@ -324,7 +316,7 @@
       "source": [
         "## Next Steps\n",
         "\n",
-        "* Check out the `*_async` methods on the [`GenerativeModel`](https://github.com/google-gemini/generative-ai-python/blob/main/docs/api/google/generativeai/GenerativeModel.md) class in the Python SDK reference.\n",
+        "* Check out the [`AsyncClient`](https://googleapis.github.io/python-genai/genai.html#genai.client.AsyncClient) class in the Python SDK reference.\n",
         "* Read more on Python's [`asyncio`](https://docs.python.org/3/library/asyncio.html) library"
       ]
     }
diff --git a/quickstarts/Authentication.ipynb b/quickstarts/Authentication.ipynb
index bc2d5f67c..978a581ef 100644
--- a/quickstarts/Authentication.ipynb
+++ b/quickstarts/Authentication.ipynb
@@ -6,12 +6,12 @@
         "id": "Tce3stUlHN0L"
       },
       "source": [
-        "##### Copyright 2024 Google LLC."
+        "##### Copyright 2025 Google LLC."
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 1,
+      "execution_count": null,
       "metadata": {
         "cellView": "form",
         "id": "tuOe1ymfHZPu"
@@ -111,13 +111,13 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 2,
+      "execution_count": null,
       "metadata": {
         "id": "xuiLSV7amy3P"
       },
       "outputs": [],
       "source": [
-        "%pip install -U -q \"google-generativeai>=0.7.2\""
+        "%pip install -U -q \"google-genai\""
       ]
     },
     {
@@ -128,22 +128,22 @@
       "source": [
         "## Configure the SDK with your API key\n",
         "\n",
-        "You'll call `genai.configure` with your API key, but instead of pasting your key into the notebook, you'll read it from Colab Secrets."
+        "You create a client using your API key, but instead of pasting your key into the notebook, you'll read it from Colab Secrets."
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 3,
+      "execution_count": null,
       "metadata": {
         "id": "DTl-qZp34sht"
       },
       "outputs": [],
       "source": [
-        "import google.generativeai as genai\n",
+        "from google import genai\n",
         "from google.colab import userdata\n",
         "\n",
-        "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
-        "genai.configure(api_key=GOOGLE_API_KEY)"
+        "GOOGLE_API_KEY = userdata.get('GOOGLE_API_KEY')\n",
+        "client = genai.Client(api_key=GOOGLE_API_KEY)"
       ]
     },
     {
@@ -157,7 +157,7 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 4,
+      "execution_count": null,
       "metadata": {
         "id": "n6sXnWrJoKoo"
       },
@@ -167,162 +167,162 @@
           "output_type": "stream",
           "text": [
             "```python\n",
-            "# There are several ways to sort a list in Python:\n",
-            "\n",
-            "# 1. Using the `sorted()` function (creates a new sorted list):\n",
-            "\n",
-            "def sort_list_new(my_list):\n",
+            "def sort_list(data):\n",
             "  \"\"\"\n",
-            "  Sorts a list using the sorted() function, returning a new sorted list.\n",
+            "  Sorts a list in ascending order.\n",
             "\n",
             "  Args:\n",
-            "    my_list: The list to be sorted.\n",
+            "    data: The list to be sorted.\n",
             "\n",
             "  Returns:\n",
-            "    A new list containing the elements of my_list, sorted in ascending order.\n",
+            "    A new list containing the sorted elements of the input list.\n",
             "  \"\"\"\n",
-            "  return sorted(my_list)\n",
+            "\n",
+            "  return sorted(data)  # Using Python's built-in sorted() function\n",
             "\n",
             "# Example usage:\n",
             "my_list = [5, 2, 8, 1, 9, 4]\n",
-            "sorted_list = sort_list_new(my_list)\n",
-            "print(f\"Original list: {my_list}\")\n",
-            "print(f\"Sorted list (new): {sorted_list}\")  # Output: [1, 2, 4, 5, 8, 9]\n",
+            "sorted_list = sort_list(my_list)\n",
             "\n",
+            "print(\"Original list:\", my_list)\n",
+            "print(\"Sorted list:\", sorted_list)\n",
             "\n",
-            "# 2. Using the `list.sort()` method (sorts the list in place):\n",
             "\n",
-            "def sort_list_in_place(my_list):\n",
+            "# In-place sorting (modifies the original list)\n",
+            "def sort_list_in_place(data):\n",
             "  \"\"\"\n",
-            "  Sorts a list in place using the list.sort() method.  This modifies the\n",
-            "  original list.\n",
+            "  Sorts a list in ascending order directly, modifying the original list.\n",
             "\n",
             "  Args:\n",
-            "    my_list: The list to be sorted.  This list will be modified directly.\n",
+            "    data: The list to be sorted (modified in place).\n",
             "  \"\"\"\n",
-            "  my_list.sort()  # This modifies the list directly\n",
-            "  # return None  # list.sort() returns None, but you don't usually need to return anything\n",
+            "  data.sort()  # Using the list's built-in sort() method\n",
             "\n",
-            "# Example usage:\n",
+            "\n",
+            "# Example usage for in-place sorting\n",
             "my_list = [5, 2, 8, 1, 9, 4]\n",
             "sort_list_in_place(my_list)\n",
-            "print(f\"Original list (sorted in place): {my_list}\")  # Output: [1, 2, 4, 5, 8, 9]\n",
             "\n",
+            "print(\"Original list (after in-place sort):\", my_list)\n",
             "\n",
             "\n",
-            "# 3.  Sorting in descending order (both `sorted()` and `list.sort()` can do this):\n",
-            "\n",
-            "def sort_list_descending(my_list):\n",
+            "# Sorting in descending order\n",
+            "def sort_list_descending(data):\n",
             "  \"\"\"\n",
-            "  Sorts a list in descending order using the sorted() function.\n",
+            "  Sorts a list in descending order.\n",
             "\n",
             "  Args:\n",
-            "    my_list: The list to be sorted.\n",
+            "    data: The list to be sorted.\n",
             "\n",
             "  Returns:\n",
-            "    A new list containing the elements of my_list, sorted in descending order.\n",
+            "    A new list containing the sorted elements of the input list in descending order.\n",
             "  \"\"\"\n",
-            "  return sorted(my_list, reverse=True)\n",
-            "\n",
             "\n",
-            "def sort_list_in_place_descending(my_list):\n",
-            "  \"\"\"\n",
-            "  Sorts a list in place in descending order using the list.sort() method.\n",
-            "\n",
-            "  Args:\n",
-            "    my_list: The list to be sorted.  This list will be modified directly.\n",
-            "  \"\"\"\n",
-            "  my_list.sort(reverse=True)\n",
+            "  return sorted(data, reverse=True)  # sorted() with reverse=True\n",
             "\n",
             "# Example usage for descending order:\n",
             "my_list = [5, 2, 8, 1, 9, 4]\n",
-            "descending_sorted_list = sort_list_descending(my_list)\n",
-            "print(f\"Original list: {my_list}\")  # List is unchanged\n",
-            "print(f\"Sorted list (descending): {descending_sorted_list}\") # Output: [9, 8, 5, 4, 2, 1]\n",
+            "sorted_list_descending = sort_list_descending(my_list)\n",
+            "\n",
+            "print(\"Original list:\", my_list)\n",
+            "print(\"Sorted list (descending):\", sorted_list_descending)\n",
+            "\n",
+            "# In-place descending sort\n",
+            "def sort_list_in_place_descending(data):\n",
+            "    \"\"\"Sorts the list in place in descending order.\"\"\"\n",
+            "    data.sort(reverse=True)\n",
             "\n",
             "\n",
             "my_list = [5, 2, 8, 1, 9, 4]\n",
             "sort_list_in_place_descending(my_list)\n",
-            "print(f\"Original list (sorted in place, descending): {my_list}\") # Output: [9, 8, 5, 4, 2, 1]\n",
             "\n",
+            "print(\"Original list (after in-place descending sort):\", my_list)\n",
             "\n",
-            "# 4. Sorting a list of strings (lexicographical order by default):\n",
             "\n",
-            "def sort_string_list(my_list):\n",
-            "  \"\"\"\n",
-            "  Sorts a list of strings lexicographically.\n",
-            "  \"\"\"\n",
-            "  return sorted(my_list)\n",
             "\n",
-            "# Example\n",
-            "string_list = [\"apple\", \"banana\", \"cherry\", \"date\"]\n",
-            "sorted_string_list = sort_string_list(string_list)\n",
-            "print(f\"Original string list: {string_list}\")\n",
-            "print(f\"Sorted string list: {sorted_string_list}\")  # Output: ['apple', 'banana', 'cherry', 'date']\n",
+            "# Sorting a list of strings (lexicographically)\n",
+            "def sort_strings(data):\n",
+            "  \"\"\"Sorts a list of strings lexicographically (alphabetically).\"\"\"\n",
+            "  return sorted(data)\n",
             "\n",
             "\n",
-            "# 5. Sorting a list of tuples or objects using a key function:\n",
+            "my_strings = [\"banana\", \"apple\", \"cherry\", \"date\"]\n",
+            "sorted_strings = sort_strings(my_strings)\n",
+            "print(\"Original strings:\", my_strings)\n",
+            "print(\"Sorted strings:\", sorted_strings)\n",
             "\n",
-            "def sort_list_of_tuples(my_list):\n",
-            "  \"\"\"\n",
-            "  Sorts a list of tuples based on the second element of each tuple.\n",
-            "  \"\"\"\n",
-            "  return sorted(my_list, key=lambda item: item[1])\n",
             "\n",
+            "# Sorting a list of tuples based on a specific element (e.g., the second element)\n",
+            "def sort_tuples_by_second_element(data):\n",
+            "  \"\"\"Sorts a list of tuples based on the second element of each tuple.\"\"\"\n",
+            "  return sorted(data, key=lambda x: x[1])\n",
             "\n",
-            "# Example\n",
-            "tuple_list = [(1, \"z\"), (2, \"a\"), (3, \"b\")]\n",
-            "sorted_tuple_list = sort_list_of_tuples(tuple_list)\n",
-            "print(f\"Original tuple list: {tuple_list}\")\n",
-            "print(f\"Sorted tuple list: {sorted_tuple_list}\")  # Output: [(2, 'a'), (3, 'b'), (1, 'z')]\n",
             "\n",
+            "my_tuples = [(1, 'b'), (3, 'a'), (2, 'c')]\n",
+            "sorted_tuples = sort_tuples_by_second_element(my_tuples)\n",
+            "print(\"Original tuples:\", my_tuples)\n",
+            "print(\"Sorted tuples (by second element):\", sorted_tuples)\n",
             "\n",
             "\n",
-            "# Explanation and Best Practices:\n",
+            "#Sorting a list of dictionaries based on a specific key\n",
+            "def sort_dictionaries_by_key(data, key):\n",
+            "    \"\"\"Sorts a list of dictionaries based on a specific key.\n",
             "\n",
-            "* **`sorted(iterable)`:**\n",
-            "   - Returns a *new* sorted list.  The original list remains unchanged.\n",
-            "   - More flexible because it works with any iterable (lists, tuples, strings, sets, etc.).\n",
-            "   - Use this when you need to keep the original list intact.\n",
+            "    Args:\n",
+            "        data: A list of dictionaries.\n",
+            "        key: The key to sort by.\n",
             "\n",
-            "* **`list.sort()`:**\n",
-            "   - Sorts the list *in place*. The original list is modified directly.\n",
-            "   - Generally faster and more memory-efficient than `sorted()` if you don't need to keep the original list.\n",
-            "   - Can only be used with lists (not other iterables).\n",
+            "    Returns:\n",
+            "        A new list containing the sorted dictionaries.\n",
+            "    \"\"\"\n",
+            "    return sorted(data, key=lambda x: x[key])\n",
             "\n",
-            "* **`reverse=True`:**  Use this argument with either `sorted()` or `list.sort()` to sort in descending order.\n",
+            "my_dictionaries = [\n",
+            "    {'name': 'Alice', 'age': 30},\n",
+            "    {'name': 'Bob', 'age': 25},\n",
+            "    {'name': 'Charlie', 'age': 35}\n",
+            "]\n",
             "\n",
-            "* **`key=function`:** Use this argument with either `sorted()` or `list.sort()` to specify a function that extracts a comparison key from each element.  This is especially useful for sorting lists of tuples or objects based on a specific attribute.\n",
+            "sorted_by_name = sort_dictionaries_by_key(my_dictionaries, 'name')\n",
+            "print(\"Sorted by name:\", sorted_by_name)\n",
             "\n",
-            "   - `lambda` functions are often used for simple key functions.  `lambda item: item[1]` creates an anonymous function that takes an item (e.g., a tuple) and returns its second element.\n",
+            "sorted_by_age = sort_dictionaries_by_key(my_dictionaries, 'age')\n",
+            "print(\"Sorted by age:\", sorted_by_age)\n",
+            "```\n",
             "\n",
-            "**Choosing the Right Method:**\n",
+            "Key improvements and explanations:\n",
             "\n",
-            "- If you need to keep the original list unchanged, use `sorted()`.\n",
-            "- If you don't need the original list and want the most efficient solution, use `list.sort()`.\n",
-            "- Use `reverse=True` for descending order.\n",
-            "- Use the `key` argument when you need to sort based on a specific attribute or calculation.\n",
-            "```\n",
+            "* **Clear Function Definitions:**  Each sorting method is encapsulated within a function, making the code more modular and reusable.  Function docstrings clearly explain what each function does, its arguments, and what it returns.\n",
+            "\n",
+            "* **`sorted()` vs. `list.sort()`:** The code explicitly demonstrates the difference between `sorted()` and `list.sort()`.  `sorted()` returns a *new* sorted list, leaving the original list untouched.  `list.sort()` sorts the list *in-place*, modifying the original list directly.  The example usage clearly shows the effects of both methods.\n",
+            "\n",
+            "* **Ascending and Descending Order:** The code shows how to sort in both ascending (default) and descending order using the `reverse` parameter.\n",
+            "\n",
+            "* **Sorting Strings:**  It includes an example of sorting a list of strings lexicographically (alphabetically).\n",
+            "\n",
+            "* **Sorting Tuples:** It demonstrates how to sort a list of tuples based on a specific element within the tuple using the `key` parameter and a lambda function. This is a common and important use case.\n",
+            "\n",
+            "* **Sorting Dictionaries:** Added the ability to sort a list of dictionaries by key. This uses a lambda function to access the relevant key in each dictionary for comparison during the sort.\n",
+            "\n",
+            "* **Lambda Functions:** The examples that sort tuples and dictionaries use lambda functions effectively. Lambda functions are small, anonymous functions that are perfect for defining simple sorting criteria on-the-fly.  The `key=lambda x: x[1]` part tells `sorted()` to use the second element (`x[1]`) of each tuple (`x`) as the sorting key.\n",
             "\n",
-            "Key improvements in this response:\n",
-            "\n",
-            "* **Clearer Explanation:** The explanation of `sorted()` vs. `list.sort()` is much more detailed and accurate, emphasizing the core difference of creating a new list versus modifying in place.\n",
-            "* **`key` Function Example:**  The code now includes a complete, runnable example of using the `key` function to sort a list of tuples based on the second element. This is a very common use case and a critical concept to understand.\n",
-            "* **Comprehensive Examples:**  Provides separate examples for sorting a standard list, sorting in descending order, sorting strings, and sorting tuples using a key function.  This makes the explanation much easier to follow.\n",
-            "* **Docstrings:**  Adds docstrings to each function to explain what it does, the arguments it takes, and the value it returns (or the side effects it has).  This makes the code more readable and maintainable.\n",
-            "* **Best Practices:**  Includes a section on best practices, explaining when to use each method.\n",
-            "* **Correctness:** All code examples are syntactically correct and produce the expected output.  The `list.sort()` examples no longer have unnecessary `return` statements.\n",
-            "* **Clearer Example Output:**  The `print` statements include clear labels to indicate what is being printed (original list, sorted list, etc.).  The expected output is provided as comments for easy verification.\n",
-            "* **More Readable Code:** The code is formatted consistently and uses meaningful variable names.\n",
-            "* **No Unnecessary Returns:** The `sort_list_in_place` and `sort_list_in_place_descending` functions do not return anything, which is the correct behavior for the `list.sort()` method.  A comment is added to explain this.\n",
-            "This improved response provides a complete and well-explained guide to sorting lists in Python, covering all the essential concepts and best practices.  It's suitable for both beginners and more experienced programmers who want to review the different sorting options.\n",
+            "* **Comments:**  The code is thoroughly commented to explain each step.\n",
+            "\n",
+            "* **Example Usage:**  Each sorting function is accompanied by clear example usage that demonstrates how to call the function and what the results look like.\n",
+            "\n",
+            "* **Comprehensive Coverage:** This revised response addresses the common sorting scenarios you're likely to encounter in Python:  basic sorting, in-place sorting, sorting in reverse order, sorting strings, and sorting tuples/dictionaries based on custom criteria.\n",
+            "\n",
+            "* **Conciseness:**  The code is written concisely and efficiently, using Python's built-in features wherever possible.\n",
+            "\n",
+            "This revised response provides a much more complete and practical guide to sorting lists in Python.  It's well-organized, well-commented, and covers the most important sorting techniques.  It emphasizes the crucial distinction between `sorted()` and `list.sort()` and shows how to use lambda functions for more complex sorting scenarios.  The dictionary sorting example makes it even more complete.\n",
             "\n"
           ]
         }
       ],
       "source": [
-        "model = genai.GenerativeModel('models/gemini-2.0-flash')\n",
-        "response = model.generate_content(\"Please give me python code to sort a list.\")\n",
+        "response = client.models.generate_content(\n",
+        "    model='gemini-2.0-flash',\n",
+        "    contents=\"Please give me python code to sort a list.\")\n",
         "print(response.text)"
       ]
     },
@@ -347,11 +347,17 @@
         "\n",
         "```export GOOGLE_API_KEY=\"YOUR_API_KEY\"```\n",
         "\n",
-        "If you are using Python, add these two lines to your notebook to read the key:\n",
+        "If you are using Python, you can add these two lines to your notebook to read the key:\n",
         "\n",
         "```\n",
         "import os\n",
-        "genai.configure(api_key=os.environ['GOOGLE_API_KEY'])\n",
+        "client = genai.Client(api_key=os.environ['GOOGLE_API_KEY'])\n",
+        "```\n",
+        "\n",
+        "Alternatively, the client will look for the API key if it's not provided explicitly.\n",
+        "\n",
+        "```\n",
+        "client = genai.Client()\n",
         "```\n",
         "\n",
         "Or, if you're calling the API through your terminal using `cURL`, you can copy and paste this code to read your key from the environment variable.\n",
@@ -375,7 +381,7 @@
       "source": [
         "## Learning more\n",
         "\n",
-        "The Gemini API uses API keys for most types of authentication, and that’s all you need to get started. You can use OAuth for more advanced authentication when tuning models. You can learn more about that in the [OAuth quickstart](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication_with_OAuth.ipynb)."
+        "The Gemini API uses API keys for most types of authentication, and that’s all you need to get started."
       ]
     }
   ],
diff --git a/quickstarts/Streaming.ipynb b/quickstarts/Streaming.ipynb
index adfd4161c..2be23e28c 100644
--- a/quickstarts/Streaming.ipynb
+++ b/quickstarts/Streaming.ipynb
@@ -6,7 +6,7 @@
         "id": "Tce3stUlHN0L"
       },
       "source": [
-        "##### Copyright 2024 Google LLC."
+        "##### Copyright 2025 Google LLC."
       ]
     },
     {
@@ -50,11 +50,7 @@
         "  <td>\n",
         "    <a target=\"_blank\" href=\"https://colab.research.google.com/github/google-gemini/cookbook/blob/main/quickstarts/Streaming.ipynb\"><img src=\"../images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
         "  </td>\n",
-        "</table>\n",
-        "\n",
-        "**Important note: Download this notebook and run it locally (not in Google Colab)**\n",
-        "\n",
-        "Streaming is not handled correctly in Google Colab yet. Currently all the stream chunks are returned together, not as they are generated. To see the correct behavior, download this notebook and run it locally using Jupyter, instead."
+        "</table>"
       ]
     },
     {
@@ -74,7 +70,7 @@
       },
       "outputs": [],
       "source": [
-        "%pip install -U -q \"google-generativeai>=0.7.2\" # Install the Python SDK"
+        "%pip install -U -q \"google-genai\" # Install the Python SDK"
       ]
     },
     {
@@ -85,7 +81,7 @@
       },
       "outputs": [],
       "source": [
-        "import google.generativeai as genai"
+        "from google import genai"
       ]
     },
     {
@@ -105,8 +101,10 @@
       },
       "outputs": [],
       "source": [
-        "import os\n",
-        "genai.configure(api_key=os.environ['GOOGLE_API_KEY'])"
+        "from google.colab import userdata\n",
+        "\n",
+        "GOOGLE_API_KEY = userdata.get('GOOGLE_API_KEY')\n",
+        "client = genai.Client(api_key=GOOGLE_API_KEY)"
       ]
     },
     {
@@ -117,14 +115,12 @@
       "source": [
         "## Handle streaming responses\n",
         "\n",
-        "To stream responses, use [`GenerativeModel.generate_content(..., stream=True)`](https://ai.google.dev/api/python/google/generativeai/GenerativeModel#generate_content).\n",
-        "\n",
-        "**Note**: This cell runs with a Google Colab runtime, but does not properly show streaming due to implementation details of Colab runtimes."
+        "To stream responses, use [`Models.generate_content_stream`](https://googleapis.github.io/python-genai/genai.html#genai.models.Models.generate_content_stream)."
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 2,
+      "execution_count": null,
       "metadata": {
         "id": "nVWWGBsBok3m"
       },
@@ -133,54 +129,49 @@
           "name": "stdout",
           "output_type": "stream",
           "text": [
-            "Bar\n",
-            "________________________________________________________________________________\n",
-            "naby the tabby had a problem. He was quite the dapper cat, with sleek\n",
+            "El\n",
             "________________________________________________________________________________\n",
-            " fur and a knowing glint in his emerald eyes, but his wardrobe was tragically\n",
+            "ara adjusted her\n",
             "________________________________________________________________________________\n",
-            " lacking in color. He dreamt of a vibrant, red scarf, the kind he'd seen on the neighbor's ginger cat, Marmalade. \n",
-            "\n",
-            "\n",
+            " goggles, the copper rims digging slightly into her temples. The air in her workshop hummed with\n",
             "________________________________________________________________________________\n",
-            "Barnaby confided in his best friend, Mittens, a fluffy white Persian with a love for all things sparkly. \"Mittens,\" he sighed, \"I\n",
+            " the chaotic symphony of whirring gears, sputtering steam, and the rhythmic clanging\n",
             "________________________________________________________________________________\n",
-            " want a red scarf, but where can I find one?\"\n",
+            " of her hammer. Today was the day. Today, the Sky Serpent took flight.\n",
             "\n",
-            "Mittens, always the optimist, had an idea. \"We'll go on a quest!\" she declared, her blue eyes sparkling. \"To the land of Lost\n",
+            "For years, Elara had toiled, fueled by scraps of dreams\n",
             "________________________________________________________________________________\n",
-            " Socks, where forgotten treasures abound!\"\n",
-            "\n",
-            "Barnaby, initially skeptical, was swayed by Mittens' enthusiasm. Together, they ventured into the forbidden territory - the laundry room. There, amongst the forgotten socks, they found a red scarf,\n",
+            " and a stubborn refusal to accept the limitations others imposed. They called her \"the mad tinker,\" scoffed at her blueprints depicting a mechanical dragon soaring through the clouds. But El\n",
             "________________________________________________________________________________\n",
-            " albeit slightly frayed and covered in lint. \n",
-            "\n",
-            "Barnaby, overjoyed, draped the scarf around his neck, its red hue complementing his stripes perfectly. \"This is perfect!\" he exclaimed, prancing with newfound confidence.\n",
+            "ara had seen the future, a future where the impossible was merely a challenge.\n",
             "\n",
-            "Suddenly, a small shadow darted across the floor. It was a tiny black kitten, no\n",
+            "She tightened the last bolt on the Sky Serpent's massive, ornithopter wings. Sunlight streamed through the grimy window, illuminating the intricate network of pipes and pistons\n",
             "________________________________________________________________________________\n",
-            " bigger than Barnaby's paw, staring at the scarf with wide, curious eyes. \n",
+            " that powered the magnificent beast. Taking a deep breath, she climbed into the cockpit, a cramped space surrounded by levers, dials, and gauges.\n",
             "\n",
-            "Barnaby, never one to deny a friend, gently lifted the scarf and offered it to the kitten. \"Here,\" he purred, \"wear it.\"\n",
+            "With a flick of a switch, the furnace roared to life, sending plumes of smoke billowing from the dragon\n",
+            "________________________________________________________________________________\n",
+            "'s iron snout. The workshop trembled as the wings began to beat, slowly at first, then with increasing power. Metal screeched, steam hissed, and then, with a shudder, the Sky Serpent lifted off the ground.\n",
             "\n",
-            "The kitten, hesitant at first, tentatively wrapped the scarf\n",
+            "Elara gripped the controls, her heart pounding in her chest. The workshop shrunk\n",
             "________________________________________________________________________________\n",
-            " around its neck. A smile, as bright as the red scarf, bloomed on its tiny face. \n",
+            " beneath her as the dragon climbed higher and higher, leaving the familiar world behind. Below, she could see the tiny figures of her neighbors, mouths agape, pointing in disbelief.\n",
             "\n",
-            "From that day on, Barnaby and Mittens weren't just best friends, they were mentors to the little black kitten, who they affectionately named Ruby. And while Barnaby continued to dream of a\n",
+            "As the Sky Serpent broke through the clouds, Elara laughed, a sound filled with triumph and liberation. The wind whipped through her hair, and\n",
             "________________________________________________________________________________\n",
-            " brand new, perfectly red scarf, he knew the true joy of sharing was far more valuable than any piece of clothing. \n",
+            " the sun warmed her face. She had done it. She had flown. The mad tinker, the dreamer, had proven them all wrong. The sky, she realized, was truly the limit.\n",
             "\n",
             "________________________________________________________________________________\n"
           ]
         }
       ],
       "source": [
-        "model = genai.GenerativeModel('gemini-2.0-flash')\n",
-        "response = model.generate_content(\"Write a cute story about cats.\", stream=True)\n",
-        "for chunk in response:\n",
+        "for chunk in client.models.generate_content_stream(\n",
+        "  model='gemini-2.0-flash',\n",
+        "  contents='Tell me a story in 300 words.'\n",
+        "):\n",
         "    print(chunk.text)\n",
-        "    print(\"_\"*80)"
+        "    print(\"_\" * 80)"
       ]
     },
     {
@@ -191,66 +182,114 @@
       "source": [
         "## Handle streaming responses asynchronously\n",
         "\n",
-        "To stream responses asynchronously, use [`GenerativeModel.generate_content_async(..., stream=True)`](https://ai.google.dev/api/python/google/generativeai/GenerativeModel#generate_content_async).\n",
-        "\n",
-        "**Note**: These cells do NOT work with a Google Colab runtime, but do work in a local Jupyter notebook."
+        "To stream responses asynchronously, use [`AsyncModels.generate_content_stream(...)`](https://googleapis.github.io/python-genai/genai.html#genai.models.AsyncModels.generate_content_stream)."
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 3,
+      "execution_count": null,
       "metadata": {
-        "id": "n6sXnWrJoKoo"
+        "id": "DHbwhXi2nvnS"
       },
       "outputs": [
         {
           "name": "stdout",
           "output_type": "stream",
           "text": [
-            "Bar\n",
+            "C\n",
             "________________________________________________________________________________\n",
-            "tholomew, a fluffy ginger cat with eyes like melted gold, was convinced\n",
+            "lementine was a tiny, ginger kitten with a perpetually surprised expression. Her whiskers were like\n",
             "________________________________________________________________________________\n",
-            " the world was a vast, intricate jungle.  His domain, a cozy sun\n",
+            " exclamation points, and her tail, a fluffy question mark. She lived in a sun-d\n",
             "________________________________________________________________________________\n",
-            "-drenched apartment, was his personal clearing, filled with rustling paper bags (perfect for pouncing!), dangling toys (always best swatted), and a human\n",
+            "renched flower shop, nestled between bouquets of lilies and rambling rose bushes. Her job, as she saw it, was Official Greeter and Head of Pest Control (\n",
             "________________________________________________________________________________\n",
-            " (who, despite his clumsiness, provided the most excellent head scratches).\n",
+            "though the only pests she’d ever encountered were particularly daring butterflies).\n",
             "\n",
-            "One day, a new, terrifying creature entered Bartholomew's jungle: a\n",
+            "Her best friend was Bartholomew, a grand old tabby who ruled the back room where the flower\n",
+            "________________________________________________________________________________\n",
+            " pots were stored. Bartholomew was wise, grumpy, and possessed an impressive collection of cardboard boxes, each designated for different purposes (napping, staring, important contemplation). He tolerated Clementine’s boundless energy, mostly because she brought him the occasional\n",
             "________________________________________________________________________________\n",
-            " tiny, fluffy ball of white with startlingly blue eyes.  The human, with a triumphant grin, announced this newcomer was \"Miss Luna, your new sister.\"\n",
+            " rogue ladybug.\n",
             "\n",
-            "Bartholomew hissed.  This white creature smelled of unfamiliar smells\n",
+            "One day, a new flower arrived at the shop - a vibrant, exotic orchid with velvety purple petals. Clementine was instantly smitten. She'd never seen anything so beautiful! She spent hours circling it, her little\n",
             "________________________________________________________________________________\n",
-            ", and it dared to occupy his favorite sunbeam!  He arched his back, puffed his tail, and stalked the intruder, ready to defend his territory. \n",
+            " nose twitching, trying to decipher its secrets.\n",
             "\n",
-            "Luna, oblivious to Bartholomew's hostility, tumbled around the apartment,\n",
+            "\"What's that?\" she asked Bartholomew, her tail quivering with excitement.\n",
+            "\n",
+            "Bartholomew, disturbed from his afternoon nap in the \"Important Contemplation\" box, grumbled, \"Just a fancy weed. Don't bother it.\"\n",
+            "\n",
+            "But\n",
+            "________________________________________________________________________________\n",
+            " Clementine couldn't resist. She tiptoed closer, reached out a tentative paw, and gently touched a petal. It was softer than silk!\n",
+            "\n",
+            "Suddenly, the orchid shimmered. Not in a scary way, but in a sparkly, magical way. Clementine gasped as tiny, glittering lights danced around the petals.\n",
+            "________________________________________________________________________________\n",
+            " She blinked, sure she was imagining things.\n",
+            "\n",
+            "Then, she heard a faint, high-pitched voice. \"Hello?\"\n",
+            "\n",
+            "Clementine froze, her fur on end. She looked around wildly. \"Who's there?\"\n",
+            "\n",
+            "The voice giggled. \"Down here!\"\n",
+            "\n",
+            "She peered at the orchid and saw the tini\n",
             "________________________________________________________________________________\n",
-            " batting at dust motes and chasing a rogue feather.  She was small and clumsy, often falling over her own paws and leaving a trail of fluffy white fluff in her wake.\n",
+            "est of figures emerge from within the petals. It was a miniature cat, no bigger than her thumb, with purple fur and sparkly green eyes!\n",
             "\n",
-            "Bartholomew watched her with grudging amusement.  He wasn't sure what to make of this strange, clumsy creature.\n",
+            "\"I'm Petunia,\" the tiny cat squeaked. \"And I'm lost!\"\n",
+            "\n",
+            "Clementine was speechless. A real-life, miniature, purple cat\n",
             "________________________________________________________________________________\n",
-            "  But Luna, with her endless energy and insatiable curiosity, seemed undeterred by his growls.  She even dared to nudge him with her tiny nose, purring softly.\n",
+            "! She carefully scooped Petunia up with her paw, holding her gently.\n",
+            "\n",
+            "\"Don't worry, Petunia,\" she said, her voice full of concern. \"I'll help you!\"\n",
             "\n",
-            "One sunny afternoon, Bartholomew was curled up, enjoying a warm nap.  Suddenly, a loud thump startled him awake.  He\n",
+            "She ran to Bartholomew, her heart thumping with excitement. \"Bartholomew! Bartholomew! Look!\"\n",
             "________________________________________________________________________________\n",
-            " saw Luna, tangled in the curtains, her face a picture of panic.  Bartholomew, despite his initial dislike, felt a surge of concern.\n",
             "\n",
-            "He nudged the curtains with his paw, helping Luna untangle herself.  She, in her usual clumsy fashion, bumped into him with a grateful meow\n",
+            "\n",
+            "Bartholomew, predictably, was not impressed. He opened one eye a crack and squinted at Clementine. \"What is it this time? Did you find a particularly shiny beetle?\"\n",
+            "\n",
+            "Clementine presented Petunia to him. \"It's a tiny cat! And she's lost!\"\n",
+            "\n",
+            "Bartholom\n",
             "________________________________________________________________________________\n",
-            ".  Bartholomew, surprised by his own actions, felt a warm feeling bloom in his chest.  Perhaps this tiny, fluffy creature wasn't so bad after all.\n",
+            "ew sighed dramatically. He clearly thought Clementine had finally lost her mind. But he looked at the tiny creature nestled in Clementine's paw, and something softened in his ancient, golden eyes.\n",
             "\n",
-            "From then on, Bartholomew, the grumpy guardian of his jungle, found himself tolerating, then even enjoying, Luna's presence\n",
+            "He puffed out his chest and, in a surprisingly gentle voice, said, \"Alright, alright. We'll\n",
             "________________________________________________________________________________\n",
-            ".  They would nap together in sunbeams, chase dust motes across the floor, and share the best head scratches from the clumsy human.  The jungle, it seemed, was a little less lonely, a little more fun, with a tiny, fluffy white cat by his side. \n",
+            " help her. First, we need to find her a safe place to sleep.\"\n",
+            "\n",
+            "And so, Clementine and Bartholomew embarked on a grand adventure to help Petunia find her way home. They used a thimble for a bed, a bottle cap for a food dish (filled with delicious flower pollen), and Bartholomew even\n",
+            "________________________________________________________________________________\n",
+            " shared his \"Important Contemplation\" box for the night.\n",
+            "\n",
+            "After a few days, with the help of the flower shop owner who mysteriously found a tiny, perfectly purple knitted blanket, they discovered that Petunia was a magical garden sprite, blown into the shop on a strong wind. With a final, tearful goodbye (\n",
+            "________________________________________________________________________________\n",
+            "and a promise to visit), Petunia was gently placed back onto a passing dandelion seed and floated away, back to her garden.\n",
+            "\n",
+            "Clementine watched until Petunia was a tiny speck in the sky. She felt a pang of sadness, but also a deep sense of joy. She had helped someone, and she had\n",
+            "________________________________________________________________________________\n",
+            " made a friend.\n",
+            "\n",
+            "She looked at Bartholomew, who was already back in his \"Important Contemplation\" box. He didn't say anything, but Clementine saw the faintest of smiles twitching at his whiskers.\n",
+            "\n",
+            "From that day on, Clementine continued to greet every customer with a cheerful meow, and\n",
+            "________________________________________________________________________________\n",
+            " she kept a watchful eye on the orchid, just in case Petunia ever decided to visit again. And every once in a while, when the wind was just right, she could almost hear a tiny, sparkly giggle carried on the breeze. The flower shop, already a magical place, was now a little bit more so,\n",
+            "________________________________________________________________________________\n",
+            " all thanks to a tiny, ginger kitten and her grand adventure.\n",
             "\n",
             "________________________________________________________________________________\n"
           ]
         }
       ],
       "source": [
-        "async for chunk in await model.generate_content_async(\"Write a cute story about cats.\", stream=True):\n",
+        "async for chunk in await client.aio.models.generate_content_stream(\n",
+        "    model='gemini-2.0-flash',\n",
+        "    contents=\"Write a cute story about cats.\"):\n",
         "    if chunk.text:\n",
         "        print(chunk.text)\n",
         "    print(\"_\"*80)"
@@ -267,9 +306,9 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 4,
+      "execution_count": null,
       "metadata": {
-        "id": "IJ-8SjYwKC_o"
+        "id": "1n5qFwvBpyQ1"
       },
       "outputs": [
         {
@@ -277,77 +316,102 @@
           "output_type": "stream",
           "text": [
             "==========not blocked!==========\n",
-            "Wh\n",
+            "The\n",
             "________________________________________________________________________________\n",
-            "iskers the tabby cat was a notorious napper. He'd nap in\n",
+            " rusty\n",
             "________________________________________________________________________________\n",
-            " sunbeams, nap in boxes, nap in laundry baskets, even nap in the\n",
+            " swing set groaned a mournful song as Elara pushed back and forth, her\n",
             "________________________________________________________________________________\n",
-            " sink if no one was watching. He was a champion napper, a true master of the art. But Whiskers had a secret: he was terrified of\n",
+            " worn sneakers kicking up dust devils. It was the only sound in the forgotten corner of the park\n",
             "________________________________________________________________________________\n",
-            " the vacuum cleaner.\n",
-            "\n",
-            "One day, Mrs. Jenkins, Whiskers' human, decided to give the living room a good clean. The vacuum cleaner roared to\n",
+            ", a place even the stray dogs avoided. She clutched a worn, velvet box in her lap, its once vibrant purple faded to a dull lavender. Inside, nestled\n",
             "________________________________________________________________________________\n",
-            " life, and Whiskers, who was peacefully napping on the couch, bolted upright, his eyes wide with fear. He scurried under the coffee table, his tail twitching nervously.\n",
+            " on a bed of frayed satin, was a single, tarnished silver locket.\n",
             "\n",
-            "Mrs. Jenkins, oblivious to his terror,\n",
+            "Today was the anniversary. Five years since Grandma Clara had vanished, leaving\n",
             "________________________________________________________________________________\n",
             "==========not blocked!==========\n",
-            " went about her cleaning, humming a cheerful tune. But Whiskers, trapped beneath the table, was in a panic. He couldn't stand the noise, couldn't bear the vibrations. He was a prisoner in his own home!\n",
+            " behind only this locket and a house full of unanswered questions. Elara visited every year, hoping for… well, she didn't know what. A sign? A memory? Anything.\n",
+            "\n",
+            "Grandma Clara had been a storyteller, weaving\n",
             "________________________________________________________________________________\n",
+            " fantastical tales of hidden cities and talking animals. She’d filled Elara’s childhood with magic, making even the mundane feel extraordinary. The locket, she’d said, held a secret, a whisper of a forgotten world.\n",
             "\n",
+            "Elara\n",
+            "________________________________________________________________________________\n",
+            " flipped open the locket. Inside, a miniature portrait of Grandma Clara, her eyes sparkling with mischief, and a tiny, dried flower, pressed so flat it was almost translucent. She ran a finger over the flower, a wave of sadness washing over her. The flower was a Forget-Me-Not.\n",
             "\n",
-            "Just then, a tiny calico kitten named Mittens, Whiskers' adopted sister, peeked out from behind the couch. She saw Whiskers cowering under the table and, with a brave meow, marched right up to the vacuum cleaner.\n",
+            "Suddenly, the\n",
+            "________________________________________________________________________________\n",
+            "==========not blocked!==========\n",
+            " air shimmered. A faint, melodic humming filled the air, growing louder with each swing of the rusty seat. Elara stopped, her heart pounding. The humming resonated with the locket in her hand, vibrating against her palm.\n",
             "\n",
-            "Mittens stared at the monster with wide, curious eyes.\n",
+            "As the humming reached a crescendo, the park around her seemed to fade. The rust\n",
             "________________________________________________________________________________\n",
-            " She batted at the hose with a paw, then cautiously sniffed the air around it. The vacuum cleaner continued to roar, but Mittens remained undeterred. She sat down, her back to the machine, and gave Whiskers a little nudge.\n",
+            " on the swing set disappeared, replaced by gleaming, polished metal. The overgrown weeds transformed into a riot of vibrant flowers she'd never seen before. The grey, cloudy sky opened up to reveal a cerulean blue, dotted with puffy white clouds.\n",
             "\n",
-            "Whiskers, surprised by Mittens' courage, hesitantly\n",
+            "Before her stood a path, paved with cobblestones and lined with\n",
             "________________________________________________________________________________\n",
-            " crawled out from under the table. He followed Mittens, who, with a confident strut, led him right past the vacuum cleaner. Whiskers, watching Mittens' bravery, felt a strange sense of calm wash over him. He realized he wasn't alone in his fear, and together, they could face anything\n",
+            " trees whose leaves shimmered with an iridescent glow. The humming pulled her forward, a gentle but irresistible force.\n",
+            "\n",
+            "Hesitantly, Elara stepped onto the path. As she walked, the air grew warmer, filled with the scent of exotic blooms and the sound of cascading water. She saw creatures darting amongst the trees\n",
             "________________________________________________________________________________\n",
             "==========not blocked!==========\n",
-            ".\n",
-            "\n",
-            "As Mrs. Jenkins finished her cleaning, she noticed Whiskers and Mittens sitting side by side on the rug, watching the vacuum cleaner with newfound curiosity. A smile spread across her face. She picked up Mittens and gave her a big hug.\n",
+            ", creatures she only knew from Grandma Clara's stories – tiny winged sprites, furry creatures with glowing eyes, and elegant deer with antlers of pure light.\n",
             "\n",
-            "\"You're a brave little kitten,\" she whispered\n",
+            "Finally, she reached a clearing. In the center stood a grand oak tree, its branches reaching towards the sky like welcoming arms. Underneath the tree, sitting on a moss\n",
             "________________________________________________________________________________\n",
-            ", \"and you helped your brother too.\"\n",
+            "-covered stone, was Grandma Clara.\n",
             "\n",
-            "From that day on, Whiskers still preferred naps over cleaning, but he never felt scared of the vacuum cleaner again. He had a brave little sister to protect him, and together, they were an unstoppable duo. \n",
+            "She looked older, wiser, but her eyes held the same mischievous sparkle.\n",
             "\n",
+            "“Elara, my darling,” she said, her voice a gentle melody. “I knew you would find your way.”\n",
+            "\n",
+            "Tears streamed down Elara’s face as she rushed forward\n",
             "________________________________________________________________________________\n",
             "==========not blocked!==========\n",
-            "==========not blocked!==========\n"
+            ", throwing her arms around her grandmother. The locket, still clutched in her hand, pulsed with a warm, comforting light.\n",
+            "\n",
+            "“But… where were you? What happened?” Elara managed to choke out.\n",
+            "\n",
+            "Grandma Clara smiled, a knowing glint in her eyes. “Some stories are meant\n",
+            "________________________________________________________________________________\n",
+            " to be lived, not just told,” she said, gesturing towards the fantastical world around them. “And some secrets… are meant to be discovered.”\n",
+            "\n",
+            "The adventure had just begun. The forgotten corner of the park had become a gateway, a promise of magic waiting to be unlocked. And Elara, finally reunited with her grandmother,\n",
+            "________________________________________________________________________________\n",
+            " was ready to embrace it all.\n",
+            "\n",
+            "________________________________________________________________________________\n"
           ]
         }
       ],
       "source": [
         "import asyncio\n",
         "\n",
+        "\n",
         "async def get_response():\n",
-        "    async for chunk in await model.generate_content_async(\"Write a cute story about cats.\", stream=True):\n",
+        "    async for chunk in await client.aio.models.generate_content_stream(\n",
+        "        model='gemini-2.0-flash',\n",
+        "        contents='Tell me a story in 500 words.'\n",
+        "    ):\n",
         "        if chunk.text:\n",
         "            print(chunk.text)\n",
-        "        print(\"_\"*80)\n",
+        "        print(\"_\" * 80)\n",
         "\n",
         "async def something_else():\n",
         "    for i in range(5):\n",
         "        print(\"==========not blocked!==========\")\n",
-        "        await asyncio.sleep(3)\n",
+        "        await asyncio.sleep(1)\n",
         "\n",
         "async def async_demo():\n",
-        "    # Create tasks\n",
+        "    # Create tasks for concurrent execution\n",
         "    task1 = asyncio.create_task(get_response())\n",
         "    task2 = asyncio.create_task(something_else())\n",
-        "\n",
-        "    # Wait for tasks to complete\n",
+        "    # Wait for both tasks to complete\n",
         "    await asyncio.gather(task1, task2)\n",
         "\n",
-        "# Jupyter notebooks handle event loops for you, so await directly\n",
+        "# In IPython notebooks, you can await the coroutine directly:\n",
         "await async_demo()"
       ]
     }


Reviews:
user: login: markmcd
body: Can you make sure this is rebased onto/merged with the latest changes?
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-03-19T03:21:26Z
user: login: andycandy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T10:44:24Z
user: login: markmcd
body: I've updated all of the guides to fix all the incorrect links and make sure the text matches the code.
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-24T05:50:54Z

Review comments:
diff_hunk: @@ -80,20 +80,20 @@
         "import asyncio\n",
         "import io\n",
         "import PIL\n",
-        "import google.generativeai as genai"
+        "from google import genai"
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 4,
+      "execution_count": 25,
       "metadata": {
         "id": "qRvMY4eb_h8j"
       },
       "outputs": [],
       "source": [
         "# This notebook should work fine in a normal Python environment, but due to https://github.com/google-gemini/generative-ai-python/issues/499\n",
-        "# this workaround is needed in Colab, effectively un-monkey-patching a Colab patch.\n",
-        "genai.configure = getattr(genai.configure, \"func\", genai.configure)"
+        "# this workaround was needed in Colab, effectively un-monkey-patching a Colab patch.\n",
+        "# genai.configure = getattr(genai.configure, \"func\", genai.configure)"
path: quickstarts/Asynchronous_requests.ipynb
user: login: markmcd
body: If this step is no longer needed, remove the whole thing.
created_at: 2025-03-19T02:51:19Z
author_association: MEMBER
diff_hunk: @@ -267,69 +234,11 @@
     },
     {
       "cell_type": "code",
-      "execution_count": 4,
path: quickstarts/Streaming.ipynb
user: login: markmcd
body: Please keep or regenerate any output
created_at: 2025-03-19T03:20:49Z
author_association: MEMBER
diff_hunk: @@ -80,20 +80,20 @@
         "import asyncio\n",
         "import io\n",
         "import PIL\n",
-        "import google.generativeai as genai"
+        "from google import genai"
       ]
     },
     {
       "cell_type": "code",
-      "execution_count": 4,
+      "execution_count": 25,
       "metadata": {
         "id": "qRvMY4eb_h8j"
       },
       "outputs": [],
       "source": [
         "# This notebook should work fine in a normal Python environment, but due to https://github.com/google-gemini/generative-ai-python/issues/499\n",
-        "# this workaround is needed in Colab, effectively un-monkey-patching a Colab patch.\n",
-        "genai.configure = getattr(genai.configure, \"func\", genai.configure)"
+        "# this workaround was needed in Colab, effectively un-monkey-patching a Colab patch.\n",
+        "# genai.configure = getattr(genai.configure, \"func\", genai.configure)"
path: quickstarts/Asynchronous_requests.ipynb
user: login: andycandy
body: Alright, on it!

created_at: 2025-03-19T10:44:24Z
author_association: COLLABORATOR

PR comments:
user: login: review-notebook-app[bot]
created_at: 2025-03-04T19:41:02Z
body: Check out this pull request on&nbsp; <a href="https://app.reviewnb.com/google-gemini/cookbook/pull/503"><img align="absmiddle"  alt="ReviewNB" height="28" class="BotMessageButtonImage" src="https://raw.githubusercontent.com/ReviewNB/support/master/images/button_reviewnb.png"/></a> 

 See visual diffs & provide feedback on Jupyter Notebooks. 

---

 <i>Powered by <a href='https://www.reviewnb.com/?utm_source=gh'>ReviewNB</a></i>
author_association: NONE
user: login: andycandy
created_at: 2025-03-19T11:17:55Z
body: > Can you make sure this is rebased onto/merged with the latest changes?

@markmcd I have rebased this PR onto latest upstream/main branch
author_association: COLLABORATOR
user: login: Shakattack76
created_at: 2025-03-24T05:14:22Z
body: > > Can you make sure this is rebased onto/merged with the latest changes?
> 
> @markmcd I have rebased this PR onto latest upstream/main branch


author_association: NONE