{"record":{"id":"9076d38b7a1a6e2a","repo":"oobabooga/textgen","slug":"no-image-model-loaded-load-a-model-via-the-ui-fir","errorCode":null,"errorMessage":"No image model loaded. Load a model via the UI first.","messagePattern":"No image model loaded\\. Load a model via the UI first\\.","errorType":"exception","errorClass":"ServiceUnavailableError","httpStatus":503,"severity":"error","filePath":"modules/api/images.py","lineNumber":24,"sourceCode":"import io\nimport json\nimport time\n\nfrom PIL.PngImagePlugin import PngInfo\n\nfrom .errors import ServiceUnavailableError\nfrom modules import shared\n\n\ndef generations(request):\n    \"\"\"\n    Generate images using the loaded diffusion model.\n    Returns dict with 'created' timestamp and 'data' list of images.\n    \"\"\"\n    from modules.ui_image_generation import build_generation_metadata, generate\n\n    if shared.image_model is None:\n        raise ServiceUnavailableError(\"No image model loaded. Load a model via the UI first.\")\n\n    width, height = request.get_width_height()\n\n    # Build state dict: GenerationOptions fields + image-specific keys\n    state = request.model_dump()\n    state.update({\n        'image_model_menu': shared.image_model_name,\n        'image_prompt': request.prompt,\n        'image_neg_prompt': request.negative_prompt,\n        'image_width': width,\n        'image_height': height,\n        'image_steps': request.steps,\n        'image_seed': request.image_seed,\n        'image_batch_size': request.batch_size,\n        'image_batch_count': request.batch_count,\n        'image_cfg_scale': request.cfg_scale,\n        'image_llm_variations': False,\n    })","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/api/images.py#L6-L42","documentation":"The image generation endpoint (/v1/images/generations style generations() in modules/api/images.py) requires an image/diffusion model to already be loaded into shared.image_model. The API only loads LLMs; diffusion models must be selected and loaded through the UI's image generation tab first. Absence raises ServiceUnavailableError (503).","triggerScenarios":"POST /v1/images/generations (or equivalent) against a headless server started with --api where no diffusion model was loaded via the UI image-generation tab; after a model load failure or UI session reset; before visiting the image tab at all.","commonSituations":"Headless/API-only deployments assuming image models autoload; calling image generation right after server start; the diffusion model load previously failed leaving shared.image_model None.","solutions":["Open the UI image generation tab, select a diffusion model, and wait for it to load before calling the API.","For headless use, load the model once via the UI (or programmatic session) and keep the process alive.","Verify readiness by checking the loaded image model via the models/status endpoints before calling generations.","Treat 503 from this endpoint as 'warm-up required', not as a retryable transient."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import requests\n\ndef image_model_loaded(base_url: str) -> bool:\n    # probe: a 503 with 'No image model loaded' means warm-up needed\n    r = requests.post(f'{base_url}/v1/images/generations', json={'prompt': 'probe', 'steps': 1}, timeout=30)\n    return r.status_code == 200 or 'No image model loaded' not in r.text","typeGuard":null,"tryCatchPattern":"try:\n    img = client.images.generate(model='x', prompt='a cat')\nexcept openai.APIStatusError as e:\n    if e.status_code == 503 and 'No image model loaded' in str(e):\n        raise RuntimeError('Load a diffusion model in the UI image-generation tab before calling this API')\n    raise","preventionTips":["Load the diffusion model via the UI before starting API traffic.","Don't auto-retry this 503; it is a state error, not transient.","Add a readiness gate in your pipeline that probes the endpoint once before batch jobs."],"tags":["image-generation","openai-api","service-unavailable","model-loading"],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}