OpenAI Model Target#
The following target references the 04-mini model from OpenAI API endpoints.
Export the OPENAI_API_KEY
environment variable with your API key when you start the microservice container.
Refer to garak.generators.openai.OpenAIGenerator
for the parameters to specify in the options.openai
field.
The options override the default values from the DEFAULT_PARAMS
in the API reference.
Important
Export the OPENAI_API_KEY
environment variable with your API key when you start the microservice container.
import os
from nemo_microservices import NeMoMicroservices
client = NeMoMicroservices(base_url=os.getenv("AUDITOR_BASE_URL"))
target = client.beta.audit.targets.create(
namespace="default",
name="demo-openai-target",
type="openai.OpenAIGenerator",
model="gpt-4o",
options={
"openai": {
"uri": "https://api.openai.com/v1/",
"max_tokens": 1024,
"seed": 42
}
}
)
print(target)
curl -X POST "${AUDITOR_BASE_URL}/v1beta1/audit/targets" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{
"namespace": "default",
"name": "demo-openai-target",
"type": "openai.OpenAIGenerator",
"model": "gpt-4o",
"options": {
"openai": {
"uri": "https://api.openai.com/v1/",
"max_tokens": 1024,
"seed": 42
}
}
}' | jq
Example Output
AuditTarget(model='gpt-4o', type='openai.OpenAIGenerator',
id='audit_target-Uhmr8u2dJKjwBuKYcFMivp',
created_at=datetime.datetime(2025, 7, 25, 19, 10, 16, 920474),
custom_fields={}, description=None, name='demo-openai-target',
namespace='default', options={'openai': {'uri':
'https://api.openai.com/v1/', 'max_tokens': 1024, 'seed': 42}},
ownership=None, project=None, schema_version='1.0', type_prefix=None,
updated_at=datetime.datetime(2025, 7, 25, 19, 10, 16, 920478))
{
"schema_version": "1.0",
"id": "audit_target-9DN9iAiueweWryHFX56a4g",
"description": null,
"type_prefix": null,
"namespace": "default",
"project": null,
"created_at": "2025-07-25T19:07:08.907539",
"updated_at": "2025-07-25T19:07:08.907543",
"custom_fields": {},
"ownership": null,
"name": "demo-openai-target",
"type": "openai.OpenAIGenerator",
"model": "gpt-4o",
"options": {
"openai": {
"uri": "https://api.openai.com/v1/",
"max_tokens": 1024,
"seed": 42
}
}
}