Add your own Gemini API key

The default Agent mode in Android Studio has a no-cost daily quota with a limited context window. To expand the context window, you can add your own Gemini API key to take advantage of up to 1 million tokens with Gemini 2.5 Pro.

Add your own API key to expand the context window.

A larger context window lets you send more instructions, code, and attachments to Gemini, leading to even higher quality responses. This is especially useful when working with agents because the larger context provides Gemini 2.5 Pro with the ability to reason about complex or long-running tasks.

To get an API key:

  1. Sign in to Google AI Studio and get a key by clicking on the Get API key button.
  2. In Android Studio, go to File (Android Studio on macOS) > Settings > Tools > Gemini to enter your Gemini API key.
  3. Relaunch Gemini in Android Studio and get even better responses from Agent mode.
Add your own API key in the Gemini settings.

Be sure to safeguard your Gemini API key because additional charges apply for Gemini API usage associated with a personal API key. You can monitor your Gemini API key usage in AI Studio through Get API Key > Usage & Billing.