| **Note:** The ability to add your own API key is only applicable if you're using Gemini's free tier; business users have access to Gemini 2.5 Pro by default.

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.](https://developer.android.com/static/studio/images/agent-add-api-key.png)

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](https://aistudio.google.com/) 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.](https://developer.android.com/static/studio/images/agent-add-api-key-settings.png)

Be sure to safeguard your Gemini API key because
[additional charges](https://ai.google.dev/gemini-api/docs/pricing) 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**.