Skip to main content

Azure AI Image Generation

Azure AI provides powerful image generation capabilities using FLUX models from Black Forest Labs to create high-quality images from text descriptions.

Overviewโ€‹

PropertyDetails
DescriptionAzure AI Image Generation uses FLUX models to generate high-quality images from text descriptions.
Provider Route on LiteLLMazure_ai/
Provider DocAzure AI FLUX Models โ†—
Supported Operations/images/generations

Setupโ€‹

API Key & Base URLโ€‹

# Set your Azure AI API credentials
import os
os.environ["AZURE_AI_API_KEY"] = "your-api-key-here"
os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint" # e.g., https://your-endpoint.eastus2.inference.ai.azure.com/

Get your API key and endpoint from Azure AI Studio.

Supported Modelsโ€‹

Model NameDescriptionCost per Image
azure_ai/FLUX-1.1-proLatest FLUX 1.1 Pro model for high-quality image generation$0.04
azure_ai/FLUX.1-Kontext-proFLUX 1 Kontext Pro model with enhanced context understanding$0.04

Image Generationโ€‹

Usage - LiteLLM Python SDKโ€‹

Basic Image Generation
import litellm
import os

# Set your API credentials
os.environ["AZURE_AI_API_KEY"] = "your-api-key-here"
os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint"

# Generate a single image
response = litellm.image_generation(
model="azure_ai/FLUX.1-Kontext-pro",
prompt="A cute baby sea otter swimming in crystal clear water",
api_base=os.environ["AZURE_AI_API_BASE"],
api_key=os.environ["AZURE_AI_API_KEY"]
)

print(response.data[0].url)

Usage - LiteLLM Proxy Serverโ€‹

1. Configure your config.yamlโ€‹

Azure AI Image Generation Configuration
model_list:
- model_name: azure-flux-kontext
litellm_params:
model: azure_ai/FLUX.1-Kontext-pro
api_key: os.environ/AZURE_AI_API_KEY
api_base: os.environ/AZURE_AI_API_BASE
model_info:
mode: image_generation

- model_name: azure-flux-11-pro
litellm_params:
model: azure_ai/FLUX-1.1-pro
api_key: os.environ/AZURE_AI_API_KEY
api_base: os.environ/AZURE_AI_API_BASE
model_info:
mode: image_generation

general_settings:
master_key: sk-1234

2. Start LiteLLM Proxy Serverโ€‹

Start LiteLLM Proxy Server
litellm --config /path/to/config.yaml

# RUNNING on http://0.0.0.0:4000

3. Make requests with OpenAI Python SDKโ€‹

Azure AI Image Generation via Proxy - OpenAI SDK
from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
base_url="http://localhost:4000", # Your proxy URL
api_key="sk-1234" # Your proxy API key
)

# Generate image with FLUX Kontext Pro
response = client.images.generate(
model="azure-flux-kontext",
prompt="A serene Japanese garden with cherry blossoms and a peaceful pond",
n=1,
size="1024x1024"
)

print(response.data[0].url)

Supported Parametersโ€‹

Azure AI Image Generation supports the following OpenAI-compatible parameters:

ParameterTypeDescriptionDefaultExample
promptstringText description of the image to generateRequired"A sunset over the ocean"
modelstringThe FLUX model to use for generationRequired"azure_ai/FLUX.1-Kontext-pro"
nintegerNumber of images to generate (1-4)12
sizestringImage dimensions"1024x1024""512x512", "1024x1024"
api_basestringYour Azure AI endpoint URLRequired"https://your-endpoint.eastus2.inference.ai.azure.com/"
api_keystringYour Azure AI API keyRequiredEnvironment variable or direct value

Getting Startedโ€‹

  1. Create an account at Azure AI Studio
  2. Deploy a FLUX model in your Azure AI Studio workspace
  3. Get your API key and endpoint from the deployment details
  4. Set your AZURE_AI_API_KEY and AZURE_AI_API_BASE environment variables
  5. Start generating images using LiteLLM

Additional Resourcesโ€‹