How to Configure API Keys for Google Gemini in Hiring Agent
Set the environment variables LLM_PROVIDER=gemini and GEMINI_API_KEY=your-key in your .env file to enable Google Gemini in Hiring Agent.
Hiring Agent by Interviewstreet supports two LLM backends: a local Ollama server or the Google Gemini API. To use Google's managed service instead of the local default, you must provide authentication via environment variables that the application reads at startup.
Step 1: Copy the Environment Template
Begin by creating your local configuration file from the provided template. The repository includes an .env.example file that contains all required variable placeholders.
cp .env.example .env
This template defines the structure for LLM_PROVIDER, DEFAULT_MODEL, and GEMINI_API_KEY that the application expects.
Step 2: Select Gemini as the Provider
Open the newly created .env file and set the provider flag to enable Gemini support:
LLM_PROVIDER=gemini
According to the source code in prompt.py (lines 19–22), the PROVIDER variable is loaded from the environment and determines which backend logic executes. When set to gemini, the runtime switches from the default Ollama implementation to Google's API.
Step 3: Choose a Gemini Model
Specify which Gemini model variant the pipeline should use by setting DEFAULT_MODEL:
DEFAULT_MODEL=gemini-2.5-pro
The mapping between model names and provider backends is defined in prompt.py (lines 56–63) within the MODEL_PROVIDER_MAPPING dictionary. This lookup ensures that models prefixed with gemini- are routed to the ModelProvider.GEMINI handler.
Step 4: Add Your API Key
Insert your Google AI Studio API key into the same .env file:
GEMINI_API_KEY=sk-your-google-gemini-key
In prompt.py (lines 66–68), the application calls os.getenv("GEMINI_API_KEY", "") to retrieve this value. The key is then passed to llm_utils.initialize_llm_provider (lines 50–60), which instantiates the GeminiProvider class defined in models.py (lines 313–393).
How the Initialization Flow Works
When you run any command that invokes the LLM, the following sequence occurs:
- Environment Loading:
prompt.pyexecutesload_dotenv()and readsGEMINI_API_KEY,LLM_PROVIDER, andDEFAULT_MODELinto module-level variables. - Provider Selection:
llm_utils.initialize_llm_provider()checks the model mapping and validates thatGEMINI_API_KEYis present. - Client Instantiation: If the key exists, the function returns an instance of
GeminiProviderfrommodels.py(lines 313–393), which handles authentication and API communication. - Fallback Behavior: If
GEMINI_API_KEYis missing or empty,llm_utils.py(lines 55–56) emits a warning and falls back to the Ollama provider to prevent runtime crashes.
Verifying Your Configuration
To confirm that Gemini is active, run the scoring pipeline with a sample resume:
python score.py path/to/resume.pdf
The initialize_llm_provider function logs the active provider during startup. If configured correctly, the GeminiProvider will execute the inference instead of the local Ollama server.
Example Configuration
Your final .env file should look like this:
# .env
LLM_PROVIDER=gemini
DEFAULT_MODEL=gemini-2.5-pro
GEMINI_API_KEY=sk-your-google-gemini-key
Programmatic Verification
You can also verify the setup programmatically by importing the initialization utility directly:
from llm_utils import initialize_llm_provider
from prompt import DEFAULT_MODEL
provider = initialize_llm_provider(DEFAULT_MODEL)
response = provider.chat(
model=DEFAULT_MODEL,
messages=[{"role": "user", "content": "Explain the difference between OOP and FP"}],
)
print(response["message"]["content"])
This executes the full provider selection logic found in llm_utils.py (lines 50–60) and confirms that the GeminiProvider class from models.py is handling requests.
Summary
- Copy
.env.exampleto.envto create your configuration file. - Set
LLM_PROVIDER=geminiinprompt.py(lines 19–22) to switch from Ollama to Google's API. - Specify a model in
DEFAULT_MODELthat maps toModelProvider.GEMINIin theMODEL_PROVIDER_MAPPINGdictionary (lines 56–63). - Provide your
GEMINI_API_KEYwhich is read byprompt.py(line 66) and consumed byllm_utils.initialize_llm_provider. - Fallback to Ollama occurs automatically if the API key is missing, as implemented in
llm_utils.py(lines 55–56).
Frequently Asked Questions
What happens if I don't set GEMINI_API_KEY?
If the GEMINI_API_KEY environment variable is empty or undefined, llm_utils.initialize_llm_provider (lines 55–56) logs a warning and falls back to the Ollama provider. The application continues running using the local backend instead of failing.
Can I use a different Gemini model?
Yes. Any model identifier listed in the MODEL_PROVIDER_MAPPING dictionary in prompt.py (lines 56–63) that maps to ModelProvider.GEMINI is valid. You can set DEFAULT_MODEL to variants like gemini-1.5-pro or gemini-2.5-flash as long as they are supported by your Google AI Studio account.
Where is the API key actually used in the code?
The key is consumed in models.py (lines 313–393) within the GeminiProvider class. This class initializes the official Google Gemini client library with the GEMINI_API_KEY retrieved from the environment via prompt.py (line 66).
Is the .env file required, or can I use shell exports?
While copying .env.example to .env is the recommended approach, you can export the variables directly in your shell session. The load_dotenv() call in prompt.py reads from the environment regardless of whether values come from a file or shell exports, though the .env file method prevents accidental credential exposure in shell history.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →