Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform
Sorry for the delay in response.
Here is the working Curl and SDK command for reference (Tested before sharing).
Please replace "foundryhubname" and AZURE_API_KEY in below codes.
Note: Curl commands are there in endpoint itself. We can draft Python SDK based on Curl commands codes.
curl -X POST "https://<foundryhubname>.services.ai.azure.com/providers/blackforestlabs/v1/flux-2-pro?api-version=preview" \ -H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_API_KEY" \
-d '{
"prompt" : "A photograph of a red fox in an autumn forest",
"width" : 1024,
"height" : 1024,
"n" : 1,
"model": "FLUX.2-pro"
}' | jq -r '.data[0].b64_json' | base64 --decode > generated_image.png
import os
import base64
import requests
# Your Foundry resource endpoint (same as curl)
ENDPOINT = (
"https://testdegradeclassic.services.ai.azure.com/"
"providers/blackforestlabs/v1/flux-2-pro?api-version=preview"
)
# The curl used: Authorization: Bearer $AZURE_API_KEY
AZURE_API_KEY = "<apikey>"
payload = {
"prompt": "A photograph of a red fox in an autumn forest",
"width": 1024,
"height": 1024,
"n": 1,
"model": "FLUX.2-pro",
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {AZURE_API_KEY}",
}
resp = requests.post(ENDPOINT, headers=headers, json=payload, timeout=180)
resp.raise_for_status()
data = resp.json()
b64_img = data["data"][0]["b64_json"] # same jq path: .data[0].b64_json
img_bytes = base64.b64decode(b64_img)
out_path = "generated_image.png"
with open(out_path, "wb") as f:
f.write(img_bytes)
print(f"Saved: {out_path}")
Please let us know if it works at your side too.
Thank you.