Stay organized with collections
Save and categorize content based on your preferences.
Use code completion and code generation
This document describes how you can use
Gemini in Colab Enterprise, which is a product
in the Gemini for Google Cloud portfolio,
to help you write and generate code in a Colab Enterprise notebook.
This document is intended for data analysts, data scientists, and
data developers who work with Colab Enterprise. It assumes you have
knowledge of how to write code in a notebook environment.
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.
In the Region menu, select the region that contains your notebook.
Click the notebook that you want to open.
In the toolbar, click the
pen_sparkHelp
me code button and select Code completion if it
isn't already selected.
In a code cell of your notebook, start entering code.
Colab Enterprise suggests a potential way to complete your
code in gray italic text.
For example, if you enter import p,
Colab Enterprise might suggest a code completion that
imports pandas as pd followed by a line that reads a CSV file
and stores the contents in a pandas dataframe.
To accept the suggested code completion, press Tab.
Use code generation
To generate code using Gemini for Google Cloud:
In the Google Cloud console, go to
the Colab Enterprise My notebooks page.
In the Region menu, select the region that contains your notebook.
Click the notebook that you want to open.
In the toolbar, click the
pen_sparkHelp
me code button and select Code generation if it
isn't already selected.
In your notebook, add a blank code cell, or click a code cell that
doesn't have any code in it.
Click
sparkAvailable
AI features, and then click Generate code.
In the
pen_sparkGenerate
field, type a description of the code that you want to generate,
and then press Enter.
To close the Generate panel, click Close.
Turn off code completion and code generation
To turn off code completion and code generation, do the
following:
In the Colab Enterprise toolbar, click the
pen_sparkHelp
me code button.
Clear the features that you want to turn off.
Troubleshoot
This section shows you how to resolve issues with using
Gemini in Colab Enterprise.
Gemini features not working
When you type in a Colab Enterprise notebook, code completion suggestions don't appear.
Or, the pen_sparkHelp me code button
doesn't appear above a code cell.
In your Colab Enterprise settings, you might have turned off the
Show context-powered code completions setting.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThis guide explains how to use Gemini in Colab Enterprise to assist with writing code within a notebook environment, including code completion and generation.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize Gemini's features, you must have the appropriate IAM roles assigned to your user account, specifically the Colab Enterprise User and Gemini for Google Cloud User roles.\u003c/p\u003e\n"],["\u003cp\u003eGemini offers code completion, which suggests code snippets as you type, and code generation, which creates code based on descriptions you provide, along with a feature to fix errors in your existing code.\u003c/p\u003e\n"],["\u003cp\u003eGemini features can be turned on or off via the "Help me code" button in the Colab Enterprise toolbar, which also allows you to select or deselect the features you wish to utilize.\u003c/p\u003e\n"],["\u003cp\u003eIf Gemini features are not working, ensure that the "Show context-powered code completions" setting is enabled in the Colab Enterprise editor settings.\u003c/p\u003e\n"]]],[],null,["# Use code completion and code generation\n=======================================\n\nThis document describes how you can use\nGemini in Colab Enterprise, which is a product\nin the [Gemini for Google Cloud](/gemini/docs/overview) portfolio,\nto help you write and generate code in a Colab Enterprise notebook.\n\nLearn [how and when Gemini\nfor Google Cloud uses your data](/gemini/docs/discover/data-governance).\n\nThis document is intended for data analysts, data scientists, and\ndata developers who work with Colab Enterprise. It assumes you have\nknowledge of how to write code in a notebook environment.\n\nBefore you begin\n----------------\n\n| As an early-stage technology, Gemini for Google Cloud\n| products can generate output that seems plausible but is factually incorrect. We recommend that you\n| validate all output from Gemini for Google Cloud products before you use it.\n| For more information, see\n| [Gemini for Google Cloud and responsible AI](/gemini/docs/discover/responsible-ai).\n\n1. [Ensure that\n Gemini in Colab Enterprise is set up for your\n Google Cloud user account and project.](/gemini/docs/colab/set-up-gemini)\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n-\n\n\n Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com, cloudaicompanion.googleapis.com, dataform.googleapis.com, compute.googleapis.com)\n\n-\n\n\n Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com, cloudaicompanion.googleapis.com, dataform.googleapis.com, compute.googleapis.com)\n\n### Required roles\n\n\nTo get the permissions that\nyou need to use Gemini in Colab Enterprise,\n\nask your administrator to grant you the\nfollowing IAM roles on the project:\n\n- [Colab Enterprise User](/iam/docs/roles-permissions/aiplatform#aiplatform.colabEnterpriseUser) (`roles/aiplatform.colabEnterpriseUser`)\n- [Gemini for Google Cloud User](/iam/docs/roles-permissions/cloudaicompanion#cloudaicompanion.user) (`roles/cloudaicompanion.user`)\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n| One or more of the required roles includes the `dataform.repositories.list` permission. Users who are granted the `dataform.repositories.list` permission or the [Code Creator\n| (`roles/dataform.codeCreator`)](/iam/docs/understanding-roles#dataform.codeCreator) role in a project can list the names of code assets in that project by using the Dataform API or the Dataform command-line interface (CLI). Non-administrators using BigQuery Studio can only see code assets that they created or that were shared with them.\n\nEnable code completion and code generation\n------------------------------------------\n\nTo enable code completion and code generation, do the following:\n\n1. In the Google Cloud console, go to\n the Colab Enterprise **My notebooks** page.\n\n [Go to My notebooks](https://console.cloud.google.com/vertex-ai/colab/notebooks)\n2.\n In the toolbar, click the\n pen_spark **Help\n me code** button and select the features that you want to use.\n\n - **Code completion** suggests code while you type.\n - **Code generation** generates code from a description of what you want.\n\n\n If the\n pen_spark **Help\n me code** button isn't active, or if you don't see a list of\n features when you click the button, see\n [Set up Gemini\n in Colab Enterprise for a project](/gemini/docs/colab/set-up-gemini).\n\nUse code completion\n-------------------\n\nTo use code completion in a Colab Enterprise notebook, do the following:\n\n1. In the Google Cloud console, go to\n the Colab Enterprise **My notebooks** page.\n\n [Go to My notebooks](https://console.cloud.google.com/vertex-ai/colab/notebooks)\n2. In the **Region** menu, select the region that contains your notebook.\n\n3. Click the notebook that you want to open.\n\n4. In the toolbar, click the pen_spark **Help\n me code** button and select **Code completion** if it isn't already selected.\n5. In a code cell of your notebook, start entering code.\n Colab Enterprise suggests a potential way to complete your\n code in gray italic text.\n\n For example, if you enter `import p`,\n Colab Enterprise might suggest a code completion that\n imports `pandas as pd` followed by a line that reads a CSV file\n and stores the contents in a pandas dataframe. \n\n\n6. To accept the suggested code completion, press \u003ckbd\u003eTab\u003c/kbd\u003e.\n\nUse code generation\n-------------------\n\nTo generate code using Gemini for Google Cloud:\n\n1. In the Google Cloud console, go to\n the Colab Enterprise **My notebooks** page.\n\n [Go to My notebooks](https://console.cloud.google.com/vertex-ai/colab/notebooks)\n2. In the **Region** menu, select the region that contains your notebook.\n\n3. Click the notebook that you want to open.\n\n4. In the toolbar, click the\n pen_spark **Help\n me code** button and select **Code generation** if it\n isn't already selected.\n\n5. In your notebook, add a blank code cell, or click a code cell that\n doesn't have any code in it.\n\n6. Click\n spark **Available\n AI features** , and then click **Generate code**.\n\n7. In the\n pen_spark **Generate**\n field, type a description of the code that you want to generate,\n and then press \u003ckbd\u003eEnter\u003c/kbd\u003e.\n\n8. To close the **Generate** panel, click **Close**.\n\nTurn off code completion and code generation\n--------------------------------------------\n\nTo turn off code completion and code generation, do the\nfollowing:\n\n1. In the Colab Enterprise toolbar, click the\n pen_spark **Help\n me code** button.\n\n2. Clear the features that you want to turn off.\n\nTroubleshoot\n------------\n\nThis section shows you how to resolve issues with using\nGemini in Colab Enterprise.\n\n### Gemini features not working\n\n\nWhen you type in a Colab Enterprise notebook, code completion suggestions don't appear.\n\nOr, the pen_spark **Help me code** button\ndoesn't appear above a code cell.\n\nIn your Colab Enterprise settings, you might have turned off the\n**Show context-powered code completions** setting.\n\nTo resolve this issue, do the following:\n\n1. Click arrow_drop_down **Toggle\n header visibility**.\n2. On the **Tools** menu, click **Settings**.\n3. Click **Editor**.\n4. Select **Show context-powered code completions**.\n5. Click **Save**.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- Read the [Gemini for Google Cloud\n overview](/gemini/docs/overview).\n\n- For more ways to write and edit code with Gemini\n assistance, see the following:\n\n - [Chat about your notebook with Gemini](/colab/docs/chat)\n - [Explain code cells](/colab/docs/explain-cells)\n - [Explain and fix errors](/colab/docs/explain-errors)\n - [Use the Data Science Agent](/colab/docs/use-data-science-agent)\n- Learn [how Gemini for Google Cloud uses\n your data](/gemini/docs/discover/data-governance)."]]