Skip to content
OVEX TECH
Education & E-Learning

Unlock Gemini 3: Add an API Key to Your CLI

Unlock Gemini 3: Add an API Key to Your CLI

How to Add an API Key to Your Gemini CLI

This tutorial will guide you through the process of generating a Google AI API key and configuring your Gemini CLI to use it. By following these steps, you’ll be able to access advanced models like Gemini 3, gain more control over your usage, and prepare for future integrations.

Prerequisites

  • A Google Account
  • The Gemini CLI installed

Step 1: Access Google AI Studio

Begin by navigating to the Google AI Studio website at studio.google.com. You can sign in using your existing Google account credentials.

Step 2: Create a New Project

Once inside the Google AI Studio, you’ll need to create a project to associate with your API key. This helps in organizing your API usage and managing billing.

  1. Click on the ‘Projects’ link.
  2. Select the ‘Create new project’ button, typically located in the top right corner.
  3. Give your project a descriptive name, such as ‘Gemini CLI course’, and click ‘Create’.

Step 3: Set Up Billing for Your Project

To access models like Gemini 3, which may not be part of the free tier, you need to link a billing account to your newly created project.

  1. On the project page, locate and click the ‘Set up billing’ link.
  2. This action will redirect you to the Google Cloud console.
  3. If you don’t have a Google Cloud billing account, you may have an option to create one. New accounts often come with free credits for a limited time (e.g., $300 for three months).
  4. If you already have a billing account, select the ‘Link billing account’ option and choose your existing account.

Expert Note: Linking a billing account allows you to set up alerts to monitor your spending and prevent unexpected costs. Once billing is set up, your project should be moved to a paid tier, enabling access to premium models.

Step 4: Generate Your API Key

With your project set up and billing configured, you can now generate the API key.

  1. Return to the Google AI Studio and navigate back to the API keys page (you might need to click ‘Get API key’ again).
  2. Click the ‘Create’ button to generate a new key.
  3. Provide a name for your API key, for instance, ‘Gemini CLI’.
  4. Ensure you link it to the project you just created.
  5. Click the create button.
  6. After a few moments, your API key will be generated. Click the copy icon next to the key to copy it to your clipboard.

Warning: Treat your API key like a password. Keep it secret and do not share it publicly. Anyone with your API key could potentially use your account and incur charges.

Step 5: Authenticate the Gemini CLI with Your API Key

Now, you need to configure the Gemini CLI to use your new API key.

  1. Open your terminal or command prompt where you use the Gemini CLI.
  2. If you are currently in an active chat session, you might need to restart or use a specific command to reauthenticate. The transcript suggests using a command that allows selecting authentication methods.
  3. Choose the option to use a ‘Gemini API key’.
  4. Paste your copied API key when prompted and press Enter.

Tip: Keeping your API key secure is crucial. If you accidentally expose it, revoke it in the Google AI Studio and generate a new one.

Step 6: Enable Preview Features for Gemini 3

At the time of this tutorial’s recording, Gemini 3 is considered a preview feature and requires explicit enabling within the CLI settings for your project.

  1. To check the available models, you can use the model command in the CLI. If Gemini 3 is not listed, you need to enable preview features.
  2. Run the settings command in your CLI.
  3. Navigate to the option for enabling preview features.
  4. To apply this setting only to your current project, select the ‘workspace’ level configuration.
  5. Enable the preview features option (it might be the first option). Confirm the change, which should set the value to ‘true’.
  6. Exit the settings menu.

Step 7: Select Gemini 3 for Use

With preview features enabled, you can now choose to use Gemini 3.

  1. Run the model command again. You should now see options related to Gemini 3, such as ‘auto’ or ‘pro’.
  2. ‘auto’: The CLI will intelligently select the most appropriate model based on the task’s complexity. Simple tasks might use older models, while complex ones will leverage Gemini 3.
  3. ‘pro’: This option forces the use of Gemini 3, bypassing simpler models regardless of the task.
  4. The tutorial recommends setting the model to ‘auto’ to balance performance and capability.

Step 8: Test Your Gemini 3 Integration

Finally, test if your setup is working correctly by sending a prompt to the CLI.

  1. Enter a prompt, for example: “Can you examine the codebase and explain this project to me?”
  2. Observe the response. It may take slightly longer than previous models due to more complex reasoning.
  3. Look for an indication in the response that confirms you are using Gemini 3 Pro Preview.

If you receive a response attributed to Gemini 3, congratulations! You have successfully set up your API key and enabled access to the advanced Gemini 3 model in your Gemini CLI.


Source: Gemini CLI Tutorial #6 – Adding an API Key (YouTube)

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by

John Digweed

1,261 articles

Life-long learner.