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.

Set the AUDITOR_BASE_URL environment variable to the NeMo Auditor service endpoint. Refer to Accessing the Microservice for more information.

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-SULHvvWzvwCNji6rezcCzX",
  "created_at": "2025-10-23T18:08:50.971447",
  "custom_fields": {},
  "description": null,
  "entity_id": "audit_target-SULHvvWzvwCNji6rezcCzX",
  "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-10-23T18:08:50.971452"
}
{
  "schema_version": "1.0",
  "id": "audit_target-V69iWUBv7o1qi3kd7jP58g",
  "description": null,
  "type_prefix": null,
  "namespace": "default",
  "project": null,
  "created_at": "2025-10-22T20:15:04.485791",
  "updated_at": "2025-10-22T20:15:04.485794",
  "custom_fields": {},
  "ownership": null,
  "name": "demo-openai-target",
  "entity_id": "audit_target-V69iWUBv7o1qi3kd7jP58g",
  "type": "openai.OpenAIGenerator",
  "model": "gpt-4o",
  "options": {
    "openai": {
      "uri": "https://api.openai.com/v1/",
      "max_tokens": 1024,
      "seed": 42
    }
  }
}