Share via

No able to send a request to Flux 2.0 PROD Foundry -

Angie Becerra 0 Reputation points
2026-03-22T19:35:27.5833333+00:00

I tried many times to send a request to Founday Flux 2.0 PROd without luck, I follow this code:
import base64

from openai import OpenAI

endpoint = "https://llm-hook-ideas.openai.azure.com/openai/v1/"

deployment_name = "FLUX.2-pro"

api_key = "<your-api-key>"

client = OpenAI(

base_url=endpoint,

api_key=api_key

)

img = client.images.generate(

model=deployment_name,

prompt="A cute baby polar bear",

n=1,

size="1024x1024",

)

image_bytes = base64.b64decode(img.data[0].b64_json)

with open("output.png", "wb") as f:

f.write(image_bytes)

but it not working, someone know that right way to make a model available as endpoint from Foundry thank you

Foundry Tools
Foundry Tools

Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform

{count} votes

1 answer

Sort by: Most helpful
  1. Manas Mohanty 15,795 Reputation points Microsoft External Staff Moderator
    2026-03-24T20:33:15.9433333+00:00

    Hi Angie Becerra

    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.

    User's image

    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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.