#Debugging API/GenerateText2Image - 400: Bad Request

8 messages · Page 1 of 1 (latest)

modern merlin
#

Hello,

I've been trying to debug the text to image endpoint I'm not doing anything too complex just trying to use a couple of Control Net images. I've been using the dev tools inspector to look at the payload using the UI and as far as I can tell i'm matching everything and encoding my images properly etc, I still can't figure out what i'm doing wrong. Is there any way to see what params in the api schema are required? If anything it might be how I'm sending Control Net images. it seems to work when I remove all the Control Net related params.

When observing the payload in the browser, I see the numeric values as strings but I've tried sending them as integers/decimals and strings and still get a 400 error. I've also tried sending the control net images with the data URI prefix and only the encoded image strings with no success.

Here's some of my details:

Request URL: http://myswarmserver/API/GenerateText2Image
Request Headers: 
{
  'Connection': 'Keep-Alive', 
  'Content-Type': 'application/json', 
  'X-Session-ID': '35a6d8633c2b08bdd3f604b544476ef2270e0f8e',
  'Keep-Alive': 'timeout=7200'
}

the payload (apologies for the param order):

{
    "session_id": "35a6d8633c2b08bdd3f604b544476ef2270e0f8e",
    "refinermethod": "PostApply",
    "seed": -1,
    "refinerupscalemethod": "pixel-lanczos",
    "sampler": "euler",
    "controlnetpreprocessor": "CannyEdgePreprocessor",
    "controlnettwostrength": 0.75,
    "height": 478,
    "controlnettwopreprocessor": "CannyEdgePreprocessor",
    "cfgscale": 1,
    "automaticvae": true,
    "controlnettwoimageinput": "data:image/png;base64,...",
    "scheduler": "simple",
    "refinerupscale": 3,
    "controlnetstart": 0.2,
    "controlnettwoend": 0.3,
    "controlnetend": 0.8,
    "model": "Flux/flux1-dev-fp8",
    "controlnetimageinput": "data:image/png;base64,...",
    "controlnetstrength": 0.62,
    "controlnetmodel": "Flux/diffusion_pytorch_model-fp8",
    "controlnettwomodel": "Flux/diffusion_pytorch_model-fp8",
    "refinercontrolpercentage": 0.2,
    "width": 815,
    "refinervae": "Flux/ae",
    "refinercfgscale": 1,
    "refinermodel": "Flux/flux1-dev-fp8",
    "extra_metadata": {
        "controlnettwoimageinput_resolution": "815x478",
        "controlnetimageinput_filename": "image_a.png",
        "controlnetimageinput_resolution": "815x478",
        "controlnettwoimageinput_filename": "image_b.png"
    },
    "prompt": "A photograph of a building\n",
    "steps": 30,
    "aspectratio": "Custom",
    "controlnettwostart": 0
}

and just for completeness this very simple payload is working (uses strings for numeric values):

{
  "session_id": "35a6d8633c2b08bdd3f604b544476ef2270e0f8e",
  "prompt": "A photograph of a building\n",
  "images": "1",
  "model": "Flux/flux1-dev-fp8",
  "cfgscale": "1",
  "width": str(width),
  "height": str(height)
}

Thanks in advance for any guidance or tips in debugging.

pure cipher
modern merlin
# pure cipher look in your server logs, it should be telling you you're missing the required i...

After including "images" : "1" to my payload I'm still getting a 400 error.

All I see in the logs is:
Creating new session 'local' for 127.0.0.1

Using the UI I see:
Creating new session 'local' for 127.0.0.1
User local requested 1 image with model 'Flux/flux1-dev-fp8.safetensors'

I'll keep trying to do a more tests with a minimal request with Control Net I assume the only params needed for a single ControlNet are:
controlnetpreprocessor
controlnetmodel
controlnetstrength
controlnetstart
controlnetend
controlnetpreviewonly
controlnetuniontype

pure cipher
wary gyroBOT
#

Hey, it looks like you need help with SwarmUI. If so, here's what to do:

First, hit CTRL+F and search to see if anybody else has already asked the same thing, and check if it's in the Troubleshooting Doc.

If not, open a post in #1255969955808022679.

When making your post, go to your Swarm interface, click Server, then Logs, then the Pastebin button, then Submit. It will generate a link - copy that link, and include it in your #1255969955808022679 post.

Make sure to also describe the problem in your post, and include any relevant information, such as screenshots of the interface or your gen parameters. .

modern merlin
# pure cipher are you sure you're sending to the correct address and all? Swarm server _cannot...

Definitely sending to the right address, was able to make some small progress today but left me more confused about how to send a Control Net payload.

When sending this payload with the image dimensions 486x309 I successfully generate an image with ControlNet you can see here in the logs

{
  "width": 486, 
  "ControlNet Strength": 0.66000000000000003, 
  "ControlNet Start": 0.0, 
  "images": 1, 
  "Refiner Do Tiling": false, 
  "prompt": "A photograph of a building",
  "Refiner Method": "PostApply", 
  "ControlNet Preprocessor": "CannyEdgePreprocessor", 
  "ControlNet Model": "Flux/diffusion_pytorch_model-fp8", 
  "Refiner VAE": "Flux/ae", 
  "ControlNet Image Input": "data:image/png;base64,...", 
  "session_id": "c61f27c30b0d11379bccd0df30027400f6ae28e3", 
  "ControlNet End": 0.80000000000000004, 
  "ControlNet Preview Only": false, 
  "Refiner Control Percentage": 0.20000000000000001, 
  "Refiner CFG Scale": 1.0, 
  "model": "Flux/flux1-dev-fp8", 
  "Refiner Upscale": 3, 
  "height": 309, 
  "Refiner Model": "Flux/flux1-dev-fp8", 
  "Refiner Upscale Method": "pixel-lanczos", 
  "cfgscale": 1.0
}

What's strange is that sending an image of 815x478 as shown in the payload below it doesn't get past creating a session as you can see here in the logs

{
  "width": 815, 
  "ControlNet Strength": 0.66000000000000003, 
  "ControlNet Start": 0.0, 
  "images": 1, 
  "Refiner Do Tiling": false, 
  "prompt": "A photograph of a building", 
  "Refiner Method": "PostApply", 
  "ControlNet Preprocessor": "CannyEdgePreprocessor", 
  "ControlNet Model": "Flux/diffusion_pytorch_model-fp8", 
  "Refiner VAE": "Flux/ae", 
  "ControlNet Image Input": "data:image/png;base64,...", 
  "session_id": "f7186b1795444ba611bbee64c7200bdfc91edb72", 
  "ControlNet End": 0.80000000000000004, 
  "ControlNet Preview Only": false, 
  "Refiner Control Percentage": 0.20000000000000001, 
  "Refiner CFG Scale": 1.0, 
  "model": "Flux/flux1-dev-fp8", 
  "Refiner Upscale": 3, 
  "height": 478, 
  "Refiner Model": "Flux/flux1-dev-fp8", 
  "Refiner Upscale Method": "pixel-lanczos", 
  "cfgscale": 1.0
}

In the successful case (486x309), Isee:

  • Session created successfully
  • Model loaded (Flux/flux1-dev-fp8.safetensors)
  • ControlNet modules loaded
  • AutoencodingEngine loaded
  • Full generation process completed

In the unsuccessful case (815x478), I only see:

  • Session created successfully

Then nothing else - it seems to fail before even attempting to load the model
This suggests the issue is happening very early in the process, before any model loading or generation begins. The fact that the session is created but nothing else happens indicates the problem is likely in the initial request validation on the SwarmUI server side. But I see no errors in the logs. Just a 400 Bad Request error From the ngnix server it's on.

I subsequently tried adding Raw Resolution to the request just to see if something weird with the resolution was happening with Swarm Internals, but that had no effect. Just tinkering around at this point to try and figure out why resolution differences would cause an issue like this. It's likely my nginx server config so i'll give that a go first.

modern merlin
#

I was able to resolve this, it was just how I was handling the headers when sending larger images.

pure cipher
#

ftr check nginx config, i think it defaults to not letting massive uploads