litellm/llms/openai/image_generation/guardrail_translation/README.md
Handler for processing OpenAI's image generation endpoint with guardrails.
This handler processes image generation requests by:
{
"model": "dall-e-3",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "1024x1024",
"quality": "standard"
}
{
"created": 1589478378,
"data": [
{
"url": "https://...",
"revised_prompt": "A cute baby sea otter..."
}
]
}
The handler is automatically discovered and applied when guardrails are used with the image generation endpoint.
curl -X POST 'http://localhost:4000/v1/images/generations' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer your-api-key' \
-d '{
"model": "dall-e-3",
"prompt": "A cute baby sea otter wearing a hat",
"guardrails": ["content_moderation"],
"size": "1024x1024"
}'
The guardrail will be applied to the prompt text before the image generation request is sent to the provider.
curl -X POST 'http://localhost:4000/v1/images/generations' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer your-api-key' \
-d '{
"model": "dall-e-3",
"prompt": "Generate an image of John Doe at [email protected]",
"guardrails": ["mask_pii"],
"metadata": {
"guardrails": ["mask_pii"]
}
}'
prompt (string)Override these methods to customize behavior:
process_input_messages(): Customize how the prompt is processedprocess_output_response(): Add custom processing for image metadata if neededCallTypes.image_generation - Synchronous image generationCallTypes.aimage_generation - Asynchronous image generationprompt parameter