I deployed the FLUX.1-Kontext-pro model to Azure AI Foundry.
While the image generation works great, the editing endpoint does not seem to work.
Here is the error that is returned:
Failed to generate image: No model specified in request. Please provide a model name in the request body or as a x-ms-model-mesh-model-name header. Trace ID : 6199947b-82fa-4314-98db-03d314a3afc1
I used the same code provided in the playground. Trying to edit in the playground gives the same error message.
Does the edit endpoint work at all ?
# Initialize the DefaultAzureCredential to be used for Entra ID authentication.
# If you receive a `PermissionDenied` error, be sure that you run `az login` in your terminal
# and that you have the correct permissions to access the resource.
# Learn more about necessary permissions: https://aka.ms/azure-openai-roles
credential = DefaultAzureCredential()
token_response = credential.get_token("https://cognitiveservices.azure.com/.default")
base_path = f'openai/deployments/{deployment}/images'
params = f'?api-version={api_version}'
generation_url = f"https://xxxxxx.cognitiveservices.azure.com/{base_path}/generations{params}"
generation_body = {
"prompt": "create a image of cats on a playground",
"n": 1,
"size": "1024x1024",
"output_format": "png"
}
generation_response = requests.post(
generation_url,
headers={
'Authorization': 'Bearer ' + token_response.token,
'Content-Type': 'application/json',
},
json=generation_body
).json()
save_response(generation_response, "generated_image")
# In addition to generating images, you can edit them.
edit_url = f"{endpoint}{base_path}/edits{params}"
edit_body = {
"prompt": "add dogs to the playground",
"n": 1,
"size": "1024x1024"
}
files = {
"image": ("generated_image.png", open("generated_image.png", "rb"), "image/png"),
}
edit_response = requests.post(
edit_url,
headers={'Authorization': 'Bearer ' + token_response.token},
data=edit_body,
files=files
).json()
save_response(edit_response, "edited_image")