Skip to main content

Gemini

deepeval allows you to directly integrate Gemini models into all available LLM-based metrics, either through the command line or directly within your python code.

Command Line

Run the following command in your terminal to configure your deepeval environment to use Gemini models for all metrics.

deepeval set-gemini \
--model=<model> # e.g. "gemini-2.5-flash"
info

The CLI command above sets Gemini as the default provider for all metrics, unless overridden in Python code. To use a different default model provider, you must first unset Gemini:

deepeval unset-gemini
Persisting settings

You can persist CLI settings with the optional --save flag. See Flags and Configs -> Persisting CLI settings.

Python

Alternatively, you can specify your model directly in code using GeminiModel from deepeval's model collection. By default, model is set to gemini-2.5-pro.

from deepeval.models import GeminiModel
from deepeval.metrics import AnswerRelevancyMetric

model = GeminiModel(
model="gemini-2.5-pro",
api_key="Your Gemini API Key",
temperature=0
)

answer_relevancy = AnswerRelevancyMetric(model=model)

There are ZERO mandatory and FOUR optional parameters when creating an GeminiModel:

  • [Optional] model: A string specifying the name of the Gemini model to use. Defaults to GEMINI_MODEL_NAME if not passed; raises an error at runtime if unset.
  • [Optional] api_key: A string specifying the Google API key for authentication. Defaults to GOOGLE_API_KEY if not passed; raises an error at runtime if unset.
  • [Optional] temperature: A float specifying the model temperature. Defaults to TEMPERATURE if not passed; falls back to 0.0 if unset.
  • [Optional] generation_kwargs: A dictionary of additional generation parameters forwarded to the Gemini API generate_content(...) call.

Parameters may be explicitly passed to the model at initialization time, or configured with optional settings. The mandatory parameters are required at runtime, but you can provide them either explicitly as constructor arguments, or via deepeval settings / environment variables (constructor args take precedence). See Environment variables and settings for the Gemini-related environment variables.

note

At runtime, you must provide an API key (via api_key or GOOGLE_API_KEY) unless you’re using Vertex AI. See Vertex AI.

Available Gemini Models

note

This list only displays some of the available models. For a comprehensive list, refer to the Gemini's official documentation.

Below is a list of commonly used Gemini models:

gemini-3-pro-preview gemini-3-flash-preview gemini-2.5-pro gemini-2.5-flash gemini-2.5-flash-lite gemini-2.0-flash gemini-2.0-flash-lite gemini-pro-latest gemini-flash-latest gemini-flash-lite-latest

Confident AI
Try DeepEval on Confident AI for FREE
View and save evaluation results, curate datasets and manage annotations, monitor online performance, trace for AI observability, and auto-optimize prompts.
Try it for Free