OpenAI
By default, DeepEval uses gpt-5.4 to power all of its evaluation metrics. To enable this, you’ll need to set up your OpenAI API key. DeepEval also supports all other OpenAI models, which can be configured directly in code.
Setting Up Your API Key
DeepEval autoloads .env.local then .env at import time (process env -> .env.local -> .env).
Recommended (local dev):
# .env.local
OPENAI_API_KEY=<your-openai-api-key>Alternative (Shell/CI):
export OPENAI_API_KEY=<your-openai-api-key>Alternative (notebook):
If you're working in a notebook environment (Jupyter or Colab), set your OPENAI_API_KEY in a cell:
%env OPENAI_API_KEY=<your-openai-api-key>Command Line
Run the following command in your CLI to specify an OpenAI model to power all metrics.
deepeval set-openai \
--model=gpt-4.1 \
--cost-per-input-token=0.000002 \
--cost-per-output-token=0.000008In Code
You may use OpenAI models other than gpt-5.4, which can be configured directly in code.
from deepeval.metrics import AnswerRelevancyMetric
from deepeval.models import OpenAIModel
model = OpenAIModel(
model="gpt-4.1",
temperature=0,
cost_per_input_token=0.000002,
cost_per_output_token=0.000008
)
answer_relevancy = AnswerRelevancyMetric(model=model)There are ZERO mandatory and SEVEN optional parameters when creating an OpenAIModel:
- [Optional]
model: A string specifying the name of the GPT model to use. Defaulted toOPENAI_MODEL_NAMEif not set; falls back togpt-5.4. - [Optional]
api_key: A string specifying the OpenAI API key for authentication. Defaults toOPENAI_API_KEYif not passed; raises an error at runtime if unset. - [Optional]
base_url: A string specifying your OpenAI URL. - [Optional]
temperature: A float specifying the model temperature. Defaults toTEMPERATUREif not passed; falls back to0.0if unset. - [Optional]
cost_per_input_token: A float specifying the cost for each input token for the provided model. Defaults toOPENAI_COST_PER_INPUT_TOKENif available indeepeval's model cost registry, elseNone. - [Optional]
cost_per_output_token: A float specifying the cost for each output token for the provided model. Defaults toOPENAI_COST_PER_OUTPUT_TOKENif available indeepeval's model cost registry, elseNone. - [Optional]
generation_kwargs: A dictionary of additional generation parameters forwarded to the OpenAIchat.completions.create(...)andbeta.chat.completions.parse(...)calls.
deepeval by default uses OpenAI models for evaluations, you can simply pass the name of your desired model in metric initialization and set the OPENAI_API_KEY to use OpenAI models:
from deepeval.metrics import AnswerRelevancyMetric
answer_relevancy = AnswerRelevancyMetric(
model="gpt-4.1",
)Available OpenAI Models
Below is a list of commonly used OpenAI models:
gpt-5gpt-5-minigpt-5-nanogpt-4.1gpt-4.5-previewgpt-4ogpt-4o-minio1o1-proo1-minio3-minigpt-4-turbogpt-4gpt-4-32kgpt-3.5-turbogpt-3.5-turbo-instructgpt-3.5-turbo-16k-0613davinci-002babbage-002