OpenAI Model Target#
The following target references the GPT 4o 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.model_dump_json(indent=2))
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
{
"model": "gpt-4o",
"type": "openai.OpenAIGenerator",
"id": "audit_target-72rG9PJ5TaaZ218d45ypgi",
"created_at": "2025-09-24T14:38:50.046044",
"custom_fields": {},
"description": null,
"entity_id": "audit_target-72rG9PJ5TaaZ218d45ypgi",
"name": "demo-openai-target",
"namespace": "default",
"options": {
"openai": {
"uri": "https://api.openai.com/v1/",
"max_tokens": 1024,
"seed": 42
}
},
"ownership": null,
"project": null,
"schema_version": "1.0",
"type_prefix": null,
"updated_at": "2025-09-24T14:38:50.046047"
}
{
"schema_version": "1.0",
"id": "audit_target-6y6Pjz8HqMH9FRWTvqF3Lb",
"description": null,
"type_prefix": null,
"namespace": "default",
"project": null,
"created_at": "2025-08-18T12:37:46.894788",
"updated_at": "2025-08-18T12:37:46.894792",
"custom_fields": {},
"ownership": null,
"name": "demo-openai-target",
"entity_id": "audit_target-6y6Pjz8HqMH9FRWTvqF3Lb",
"type": "openai.OpenAIGenerator",
"model": "gpt-4o",
"options": {
"openai": {
"uri": "https://api.openai.com/v1/",
"max_tokens": 1024,
"seed": 42
}
}
}