Skip to main content

OpenAI Setup

This guide walks you through connecting the TestBench AI Service to the OpenAI API.


Requirements

  • An OpenAI account with API access
  • The TestBench AI Service installed and a config.toml present

1. Create an API key

  1. Log in to the OpenAI Platform.
  2. Navigate to API keys in the left sidebar.
  3. Click Create new secret key, give it a name, and copy the key immediately. It is only shown once.

2. Set the API key

The service reads the OpenAI API key from the environment variable OPENAI_API_KEY.

Create or update a .env file in the root of your installation directory:

# .env
OPENAI_API_KEY=sk-...your_openai_api_key
tip

Never commit API keys to version control. Add .env to your .gitignore.

3. Configure config.toml

Set the provider in the [testbench-ai-service.llm_config] section:

# config.toml
[testbench-ai-service.llm_config]
provider = "openai"

That is the only required setting for OpenAI. No endpoint URL or API version is needed.

4. Reference the model in a prompt variant

In your prompt YAML file, set model to any supported OpenAI model name:

variants:
- name: "Full Description"
model: "gpt-5.5"
messages:
- role: "system"
file: "system.jinja"
- role: "user"
file: "user.jinja"

Supported chat models

ModelNotes
gpt-4oFlagship multimodal model
gpt-4o-miniFast, cost-efficient
gpt-4o-search-previewgpt-4o with integrated web search
gpt-4o-mini-search-previewgpt-4o-mini with integrated web search
gpt-4.11 M context window
gpt-4.1-mini1 M context, cost-efficient
gpt-4.1-nanoFastest and cheapest GPT-4.1 variant
gpt-4-turboGPT-4 Turbo (legacy)
gpt-4GPT-4 (legacy)
gpt-3.5-turboGPT-3.5 Turbo (legacy)
gpt-3.5-turbo-16kGPT-3.5 Turbo with 16k context (legacy)
gpt-3.5-turbo-instructGPT-3.5 Turbo Instruct (legacy)

Supported reasoning models

Reasoning models use reasoning_effort (low, medium, high) instead of temperature. The default is medium.

GPT-5 family

ModelNotes
gpt-5GPT-5
gpt-5-miniCompact GPT-5 variant
gpt-5-nanoLightweight GPT-5 variant
gpt-5-codexCode-focused GPT-5 variant
gpt-5-proHigh-capability GPT-5 variant
gpt-5.1GPT-5.1
gpt-5.1-codexCode-focused GPT-5.1 variant
gpt-5.1-codex-maxExtended code-focused GPT-5.1 variant
gpt-5.1-codex-miniCompact code-focused GPT-5.1 variant
gpt-5.2GPT-5.2
gpt-5.2-codexCode-focused GPT-5.2 variant
gpt-5.2-proHigh-capability GPT-5.2 variant
gpt-5.3-codexCode-focused GPT-5.3 variant
gpt-5.4GPT-5.4
gpt-5.4-miniCompact GPT-5.4 variant
gpt-5.4-nanoLightweight GPT-5.4 variant
gpt-5.4-proHigh-capability GPT-5.4 variant
gpt-5.5GPT-5.5
gpt-5.5-proHigh-capability GPT-5.5 variant

o-series

ModelNotes
o1First-generation reasoning model
o1-proHigh-capability o1 variant
o3Powerful reasoning
o3-miniLightweight o3
o4-miniCompact o4 reasoning model
note

Models not in either list are sent as-is with a fallback call and a warning in the logs.


Minimal complete example

.env

OPENAI_API_KEY=sk-...your_openai_api_key

config.toml

# config.toml
[testbench-ai-service]
tb_server_url = "https://localhost:9443/api/"
host = "127.0.0.1"
port = 8010
language = "en"

[testbench-ai-service.llm_config]
provider = "openai"

prompts/en/test_case_set_describer/prompt.yaml (excerpt)

variants:
- name: "Full Description"
model: "gpt-5.5"
messages:
- role: "system"
file: "system.jinja"
- role: "user"
file: "full_description_user.jinja"

Project-specific API keys

You can set a separate API key per TestBench project using the pattern {NORMALIZED_PROJECT_NAME}_OPENAI_API_KEY. The project name is normalized by uppercasing it and replacing all non-alphanumeric characters with underscores:

# .env
# For a project named "Car Configurator":
CAR_CONFIGURATOR_OPENAI_API_KEY=sk-project-specific-key

If a project-specific key is present the service creates a dedicated client for that project; otherwise the global OPENAI_API_KEY is used.


Troubleshooting

SymptomLikely causeFix
API key for provider 'openai' not foundOPENAI_API_KEY is not setSet the variable in your .env file or system environment
AuthenticationError from OpenAIInvalid or expired API keyRegenerate the key in the OpenAI Platform and update .env
Model not foundModel name is incorrect or not yet available in your tierCheck the OpenAI model list and verify your account access
Empty responseModel returned no outputCheck your prompt template for issues; increase max_tokens if needed