# How to Set the Google AI Studio API Key for Gemini in the Hiring Agent

> Learn how to set your Google AI Studio API key for Gemini in the Hiring Agent. Find out how to configure the GEMINI_API_KEY environment variable for seamless integration.

- Repository: [HackerRank/hiring-agent](https://github.com/interviewstreet/hiring-agent)
- Tags: how-to-guide
- Published: 2026-07-03

---

**The Hiring Agent project reads your Gemini API key from the `GEMINI_API_KEY` environment variable and automatically initializes the `GeminiProvider` class when this variable is present.**

The InterviewStreet Hiring Agent supports Google's Gemini models through the Google AI Studio API. To enable this integration, you must configure the **Google AI Studio API key** using environment variables that the application reads at startup. This guide shows you how to set up the key in the `interviewstreet/hiring-agent` repository and verify that the system correctly routes LLM requests to the Gemini provider.

## Copy the Environment Configuration Template

Start by creating your local environment file from the provided template. The repository includes an `.env.example` file that contains placeholder entries for all supported API keys.

```bash
cp .env.example .env

```

The example file already contains the `GEMINI_API_KEY` placeholder entry that you will populate with your actual key.

## Add Your Google AI Studio API Key

Edit the `.env` file and replace the placeholder value with your actual API key from Google AI Studio. You can obtain your key from the [Google AI Studio API keys page](https://aistudio.google.com/api-keys).

```dotenv
GEMINI_API_KEY=your_actual_api_key_here

```

This variable is defined in [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py) (lines 66-68), which loads the configuration using `load_dotenv()` at application startup.

## Select the Gemini Provider

By default, the Hiring Agent uses the Ollama backend for local inference. To switch to Gemini, set the `LLM_PROVIDER` environment variable to `gemini` and specify your preferred model.

```dotenv
LLM_PROVIDER=gemini
DEFAULT_MODEL=gemini-2.5-pro

```

Add these entries to the same `.env` file alongside your API key. The `DEFAULT_MODEL` can be any supported Gemini model identifier available in your Google AI Studio account.

## How the Application Validates the Key

The initialization logic in [`llm_utils.py`](https://github.com/interviewstreet/hiring-agent/blob/main/llm_utils.py) (lines 50-60) checks for the presence of `GEMINI_API_KEY` when you select the Gemini provider. If the key is missing, the system logs a warning and falls back to Ollama. If present, it creates a `GeminiProvider` instance.

```python

# From llm_utils.py

if model_provider == ModelProvider.GEMINI:
    if not GEMINI_API_KEY:
        logger.warning("⚠️ Gemini API key not found. Falling back to Ollama.")
    else:
        logger.info(f"🔄 Using Google Gemini API provider with model {model_name}")
        provider = GeminiProvider(api_key=GEMINI_API_KEY)

```

The `GeminiProvider` class, implemented in [`models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/models.py) (lines 13-22), wraps the official Google Gemini client and handles all downstream API interactions.

## Verify the Integration

After starting the application, check the logs to confirm the Gemini provider is active. You should see the message: "Using Google Gemini API provider with model [model_name]".

You can also verify the configuration programmatically by inspecting the environment variables loaded in [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py):

```python
from prompt import GEMINI_API_KEY, PROVIDER

print("Provider:", PROVIDER)               # → gemini

print("Gemini API key set:", bool(GEMINI_API_KEY))  # → True

```

## Complete Configuration Example

Here is a minimal `.env` configuration that enables Gemini with the 2.5 Pro model:

```dotenv

# Core LLM Configuration

LLM_PROVIDER=gemini
DEFAULT_MODEL=gemini-2.5-pro

# API Keys

GEMINI_API_KEY=sk-abcdef1234567890abcdefg

```

## Direct Provider Initialization

For testing or custom scripts, you can initialize the provider directly without relying on the automatic configuration flow:

```python
from llm_utils import initialize_llm_provider

provider = initialize_llm_provider("gemini-2.5-pro")
response = provider.chat(
    model="gemini-2.5-pro",
    messages=[{"role": "user", "content": "Hello, Gemini!"}]
)
print(response["message"]["content"])

```

This bypasses the environment check and uses the specific model you pass as an argument.

## Summary

- **Environment Variable**: The Hiring Agent requires `GEMINI_API_KEY` to authenticate with Google AI Studio.
- **Configuration File**: Copy `.env.example` to `.env` and populate the key value.
- **Provider Selection**: Set `LLM_PROVIDER=gemini` to override the default Ollama backend.
- **Validation**: Check application logs for "Using Google Gemini API provider" to confirm successful setup.
- **Fallback Behavior**: If the key is missing, the system automatically falls back to Ollama with a warning logged.

## Frequently Asked Questions

### What happens if I don't set the GEMINI_API_KEY?

If the `GEMINI_API_KEY` environment variable is not set and you have selected `LLM_PROVIDER=gemini`, the application logs a warning and falls back to the Ollama backend according to the logic in [`llm_utils.py`](https://github.com/interviewstreet/hiring-agent/blob/main/llm_utils.py) (lines 50-60). Your requests will be processed locally rather than through the Google AI Studio API.

### Can I use different Gemini models with the same API key?

Yes. The `GEMINI_API_KEY` authenticates your account, while the specific model is determined by the `DEFAULT_MODEL` environment variable or the `model` parameter passed to the provider. You can use `gemini-2.5-pro`, `gemini-1.5-pro`, or any other model available in your Google AI Studio account.

### Where is the Gemini API key stored in the code?

The [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py) file defines the `GEMINI_API_KEY` constant by reading it from the environment (lines 66-68). This value is then passed to the `GeminiProvider` constructor in [`llm_utils.py`](https://github.com/interviewstreet/hiring-agent/blob/main/llm_utils.py) when initializing the provider. The key is never hardcoded in the source files and should always be provided via environment variables.

### Do I need to restart the application after changing the .env file?

Yes. The Hiring Agent loads environment variables at startup when `load_dotenv()` executes in [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py). Changes to the `.env` file require a restart to take effect, as the configuration is not hot-reloaded during runtime.