# How to Configure Google Gemini API for the Hiring Agent

> Easily configure the Google Gemini API for your Hiring Agent. Set the GEMINI_API_KEY and LLM_PROVIDER variables in your env file to leverage Gemini's power.

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

---

**Set the `GEMINI_API_KEY` environment variable in your `.env` file and configure `LLM_PROVIDER=gemini` to switch the Hiring Agent from Ollama to Google Gemini.**

The Hiring Agent by InterviewStreet supports multiple LLM backends, including local Ollama instances and cloud-based Google Gemini models. Configuring Gemini requires setting a single API key and selecting a model name, after which the application automatically routes all inference requests to Google's Generative AI API.

## Prerequisites

Before configuring Gemini, ensure your environment has the required dependencies. The repository includes `google-generativeai` in its [`requirements.txt`](https://github.com/interviewstreet/hiring-agent/blob/main/requirements.txt) for interacting with the Gemini API.

```bash
pip install -r requirements.txt

```

You will also need a valid Google Gemini API key from [Google AI Studio](https://aistudio.google.com/).

## Environment Configuration

The Hiring Agent uses environment variables to select the LLM provider and authenticate with external APIs. Create a `.env` file in your project root by copying the provided template:

```bash
cp main/.env.example .env

```

Edit the `.env` file to include these three critical variables:

```bash
LLM_PROVIDER=gemini          # Switches from Ollama to Gemini backend

DEFAULT_MODEL=gemini-2.5-pro # Or gemini-2.5-flash, gemini-1.5-pro, etc.

GEMINI_API_KEY=YOUR_ACTUAL_API_KEY_HERE

```

The `GEMINI_API_KEY` is read by [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py) using `python-dotenv`'s `load_dotenv()` function, which executes at module import time to populate `os.getenv("GEMINI_API_KEY")`.

## How the Configuration Works

Understanding the internal flow helps troubleshoot configuration issues. The Hiring Agent implements a provider pattern that maps model names to specific implementations.

### Provider Selection in prompt.py

In [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py), lines 36-44 and 55-63 define a mapping between model names and the `ModelProvider.GEMINI` enum. When you set `DEFAULT_MODEL` to any Gemini model identifier (e.g., `gemini-2.5-pro`), the system resolves this to use the Gemini backend.

The API key is loaded in lines 12-18, where `load_dotenv()` processes your `.env` file, and lines 66-68 store the key in a module-level variable for later use.

### GeminiProvider Implementation

The `GeminiProvider` class in [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py) (lines 13-21) handles the actual API communication. Its constructor:

1. Receives the API key from [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py)
2. Calls `google.generativeai.configure(api_key=...)` to initialize the Google client
3. Stores the configured client for subsequent chat operations

When generating responses, the `chat()` method (lines 48-66 and 70-78) constructs a `GenerativeModel` instance using your specified model name. It passes generation parameters—such as `temperature` and `top_p` defined in `MODEL_PARAMETERS` from [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py)—to the Gemini API and returns standardized response objects compatible with the rest of the Hiring Agent codebase.

### Key Validation

The [`llm_utils.py`](https://github.com/interviewstreet/hiring-agent/blob/main/llm_utils.py) module validates that `GEMINI_API_KEY` is not empty before constructing the provider instance. If the environment variable is missing or blank, the code raises an error immediately rather than attempting to call the Gemini API without credentials.

## Testing Your Configuration

After updating your `.env` file, verify the configuration by running the resume evaluation script:

```bash
python -m main.evaluate path/to/candidate_resume.json

```

If configured correctly, the agent will initialize the Gemini provider and process the resume using your selected model. You should see no errors related to missing API keys or provider misconfiguration.

## Summary

- **Environment Setup**: Place `GEMINI_API_KEY`, `LLM_PROVIDER=gemini`, and `DEFAULT_MODEL` in a `.env` file in your project root.
- **Loading Mechanism**: [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py) uses `python-dotenv` to load these variables at runtime, mapping Gemini model names to `ModelProvider.GEMINI`.
- **Provider Implementation**: [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py) contains the `GeminiProvider` class that configures the Google client via `google.generativeai.configure()` and handles all chat completions.
- **Validation**: The system validates key presence in [`llm_utils.py`](https://github.com/interviewstreet/hiring-agent/blob/main/llm_utils.py) before execution, preventing empty credential errors.

## Frequently Asked Questions

### What Gemini models are supported by the Hiring Agent?

The Hiring Agent supports any model identifier recognized by Google's Generative AI API, including `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-1.5-pro`, and `gemini-1.5-flash`. These mappings are defined in [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py) and resolve to `ModelProvider.GEMINI` when selected via the `DEFAULT_MODEL` environment variable.

### Can I configure Gemini without using a .env file?

Yes. You can set the environment variables programmatically before importing the Hiring Agent modules. Since [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py) reads environment variables at import time, you must set them in Python before importing:

```python
import os
os.environ["GEMINI_API_KEY"] = "your-key-here"
os.environ["LLM_PROVIDER"] = "gemini"
from main.evaluate import evaluate_resume

```

### How do I switch back to Ollama from Gemini?

Change the `LLM_PROVIDER` environment variable to `ollama` (or remove it entirely, as Ollama is the default backend) and update `DEFAULT_MODEL` to an Ollama-supported model name such as `llama3.1` or `mistral`. The provider selection logic in [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py) will automatically route requests to the local Ollama instance instead of the Gemini API.

### Why does the Hiring Agent require a Gemini API key instead of using application default credentials?

The `GeminiProvider` class in [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py) explicitly initializes the Google client using `google.generativeai.configure(api_key=...)` rather than Application Default Credentials (ADC). This design choice ensures that users can easily rotate keys via environment variables and supports deployment scenarios where ADC may not be available, such as containerized environments or CI/CD pipelines.