Share via

Flux2-pro deployed in Foundry shows timeout error

Angel Sevillano 0 Reputation points Microsoft Employee
2026-02-11T15:48:43.76+00:00

Hi,

I'm trying to edit pictures, removing the background. The same code worked last week but now it shows the error {'error': {'code': 'Timeout', 'message': 'The operation was timeout.'}}, status: 408, with images larger than 170 Kb, but last week the same code worked.

Any idea what's happening?

import base64
import requests
from azure.identity import AzureCliCredential
FLUX2_PRO_ENDPOINT = "https://<resource-name>.services.ai.azure.com/providers/blackforestlabs/v1/flux-2-pro?api-version=preview"
image_path = "<image-path.jpg"

credential = AzureCliCredential()
def get_token():
    return credential.get_token("https://cognitiveservices.azure.com/.default")

def get_headers():
    token = get_token()
    return { "Authorization": f"Bearer {token.token}" }

def image_to_base64(image_path):
    """Convertir imagen a base64"""
    with open(image_path, "rb") as f:
        return base64.b64encode(f.read()).decode("utf-8")


PROMPT_WHITE_BG = "remove background and set the background pure white, do not modify the main subject in any way, keep the same position, scale and pose, keep all details of the subject, only change the background to pure white #FFFFFF, keep natural contact shadows where the subject meets the ground, maintain identical camera angle, framing and perspective."

data = {
        "prompt": PROMPT_WHITE_BG,
        "input_image": image_to_base64(image_path),  # Base64 encoded image
        "width": 1024,
        "height": 800,
        "n": 1,
        "model": "FLUX.2-pro"
}

response = requests.post(FLUX2_PRO_ENDPOINT, headers=get_headers(), json=data)
print(response.json())
Azure AI services
Azure AI services

A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.

{count} votes

4 answers

Sort by: Most helpful
  1. Angel Sevillano 0 Reputation points Microsoft Employee
    2026-02-23T15:59:27.6966667+00:00

    Hi,

    Following a suggestion from a member of the Microsoft support team, I tested the process using the model deployed in the US Data Zone instead of Global Standard, and without resizing the images, all of them were processed successfully with no timeout errors.Regards,

    Angel

    0 comments No comments

  2. Angel Sevillano 0 Reputation points Microsoft Employee
    2026-02-16T12:46:07.25+00:00

    hi,

    Thank you for the detailed answer, awesome!!

    I found a workaround: resizing the images to 1792 px or limiting them to 2 MP works for almost all images, and for the remaining ones that still hit a timeout error, resizing them to 1024 px works.

    Thanks!


  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. SRILAKSHMI C 14,900 Reputation points Microsoft External Staff Moderator
    2026-02-12T11:33:36.3166667+00:00

    Hello Angel Sevillano,

    Welcome to Microsoft Q&A and Thank you for sharing the details and code snippet.

    Since the same code was working last week and now returns a 408 Timeout error only for images larger than ~170 KB, this likely points to a service-side processing or latency issue rather than a problem in your implementation.

    Below are the most relevant things to check and try:

    Image Size and Base64 Payload

    When sending images as Base64:

    • Base64 increases the payload size by ~33%.

    A 170 KB image becomes ~225 KB in the request body.

    Larger images significantly increase preprocessing time for diffusion-based models like FLUX.2-pro.

    If larger images now time out, this could indicate:

    Increased backend latency

    Stricter request processing limits

    Higher regional load

    Recommendation:

    Resize images before encoding (e.g., max 1024x1024).

    Compress images (quality=85, optimize=True) before converting to Base64.

    Test with smaller output resolution (e.g., 768x768) to confirm if this is compute-related.

    If smaller images work consistently, this confirms a processing timeout rather than a code issue.

    Increase Client Request Timeout

    Your current requests.post() call does not specify a timeout. While the service may still enforce limits, increasing the client timeout ensures your client isn’t closing early.

    Example:

    response = requests.post(
        FLUX2_PRO_ENDPOINT,
        headers=get_headers(),
        json=data,
        timeout=120  # 2 minutes
    )
    

    You can test with 120–180 seconds.

    Deployment Request Timeout Setting

    If this model is deployed through Foundry with configurable deployment settings, verify whether a request timeout is set.

    You can increase:

    request_settings:
      request_timeout_ms: 300000
    

    (5 minutes)

    If the timeout is happening at the deployment layer, this may resolve it.

    Service Health Check

    Since this worked last week:

    Check Azure Service Health for any incidents affecting:

    Azure AI Foundry

      BlackForestLabs provider
      
         Your specific region
         
    

    Latency increases due to regional capacity changes can cause previously working workloads to start timing out.

    Quota or Throttling

    Ensure your subscription has not:

    Reached quota limits

    Hit throttling thresholds

    Experienced reduced regional capacity

    Even without explicit 429 errors, backend capacity pressure can manifest as timeouts.

    Monitor Performance

    Use:

    • Azure Monitor
    • Diagnostic logs
    • Correlation ID from failed requests

    Likely Root Cause

    Given that:

    The same code worked previously

    Smaller images still work

    Only larger payloads fail

    This strongly suggests either:

    Increased model latency under load

    Reduced processing timeout window

    Regional capacity change

    Backend behavior change in preview API

    Since you are using a preview API version, changes in limits or backend behavior can occur without explicit announcements.

    Suggested Diagnostic Test

    Try Same image, Resize to 512x512, Keep same prompt.

    If it succeeds → confirms compute timeout rather than payload rejection.

    If resizing and timeout adjustments do not resolve the issue, this may require escalation to check backend latency or capacity for FLUX.2-pro in your region.

    Please refer this

    I Hope this helps. Do let me know if you have any further queries.

    Thank you!

    0 comments No comments

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.