Skip to main content

Azure AI Image Editing

Azure AI provides powerful image editing capabilities using FLUX models from Black Forest Labs to modify existing images based on text descriptions.

Overviewโ€‹

PropertyDetails
DescriptionAzure AI Image Editing uses FLUX models to modify existing images based on text prompts.
Provider Route on LiteLLMazure_ai/
Provider DocAzure AI FLUX Models โ†—
Supported Operations/images/edits

Setupโ€‹

API Key & Base URL & API Versionโ€‹

# 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/
os.environ["AZURE_AI_API_VERSION"] = "2025-04-01-preview" # Example API version

Get your API key and endpoint from Azure AI Studio.

Supported Modelsโ€‹

Model NameDescriptionCost per Image
azure_ai/FLUX.1-Kontext-proFLUX 1 Kontext Pro model with enhanced context understanding for editing$0.04

Image Editingโ€‹

Usage - LiteLLM Python SDKโ€‹

Basic Image Editing
import os
import base64
from pathlib import Path

import litellm

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

# Edit an image with a prompt
response = litellm.image_edit(
model="azure_ai/FLUX.1-Kontext-pro",
image=open("path/to/your/image.png", "rb"),
prompt="Add a winter theme with snow and cold colors",
api_base=os.environ["AZURE_AI_API_BASE"],
api_key=os.environ["AZURE_AI_API_KEY"],
api_version=os.environ["AZURE_AI_API_VERSION"]
)

img_base64 = response.data[0].get("b64_json")
img_bytes = base64.b64decode(img_base64)
path = Path("edited_image.png")
path.write_bytes(img_bytes)

Usage - LiteLLM Proxy Serverโ€‹

1. Configure your config.yamlโ€‹

Azure AI Image Editing Configuration
model_list:
- model_name: azure-flux-kontext-edit
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
api_version: os.environ/AZURE_AI_API_VERSION
model_info:
mode: image_edit

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 image editing requests with OpenAI Python SDKโ€‹

Azure AI Image Editing 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
)

# Edit image with FLUX Kontext Pro
response = client.images.edit(
model="azure-flux-kontext-edit",
image=open("path/to/your/image.png", "rb"),
prompt="Transform this image into a beautiful oil painting style",
)

img_base64 = response.data[0].b64_json
img_bytes = base64.b64decode(img_base64)
path = Path("proxy_edited_image.png")
path.write_bytes(img_bytes)

Supported Parametersโ€‹

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

ParameterTypeDescriptionDefaultExample
imagefileThe image file to editRequiredFile object or binary data
promptstringText description of the desired changesRequired"Add snow and winter elements"
modelstringThe FLUX model to use for editingRequired"azure_ai/FLUX.1-Kontext-pro"
nintegerNumber of edited images to generate (You can specify only 1)11
api_basestringYour Azure AI endpoint URLRequired"https://your-endpoint.eastus2.inference.ai.azure.com/"
api_keystringYour Azure AI API keyRequiredEnvironment variable or direct value
api_versionstringAPI version for Azure AIRequired"2025-04-01-preview"

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, AZURE_AI_API_BASE and AZURE_AI_API_VERSION environment variables
  5. Prepare your source image
  6. Use litellm.image_edit() to modify your images with text instructions

Additional Resourcesโ€‹