odysseus-dev/odysseus · error · HTTPException

OpenAI endpoint has no api_key stored — edit it in…

Error message

OpenAI endpoint has no api_key stored — edit it in Endpoints settings.

What it means

Guard on the OpenAI inpaint path: the selected endpoint is detected as an OpenAI API base but no api_key is stored on its endpoint record. The /v1/images/edits call cannot authenticate, so the request is rejected with 400, directing the user to add the key in Endpoints settings.

Solutions

  1. Edit the endpoint in Endpoints settings and add its API key.
  2. Create a new endpoint entry with a valid OpenAI API key.
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when the corresponding server-side validation or runtime check at the recorded location rejects the request or operation and returns this error message to the caller.

Common situations: See trigger scenarios.


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/fe1efc8d77a0309e. Report an issue: GitHub.

Appendix: source

Thrown at routes/gallery/gallery_routes.py:1316

                    raise HTTPException(403, "Choose a registered image endpoint")
                base = ep.base_url.rstrip("/")
                api_key = ep.api_key
            finally:
                db.close()

        if not base.endswith("/v1"):
            base += "/v1"

        is_openai = _is_openai_api_base(base)

        if is_openai:
            # OpenAI path: /v1/images/edits with gpt-image-1.
            # Mask convention differs from Stable Diffusion:
            #   SD:     white pixels = regenerate, black = keep
            #   OpenAI: transparent alpha = regenerate, opaque = keep
            # So we convert the incoming PNG mask into an alpha-channel PNG.
            if not api_key:
                raise HTTPException(400, "OpenAI endpoint has no api_key stored — edit it in Endpoints settings.")
            import base64, io
            try:
                from PIL import Image
            except ImportError:
                raise HTTPException(500, "Pillow not installed on server")

            try:
                img_bytes = base64.b64decode(body["image"])
                mask_bytes = base64.b64decode(body["mask"])
                source_png = Image.open(io.BytesIO(img_bytes)).convert("RGBA")
                mask_png = Image.open(io.BytesIO(mask_bytes)).convert("L")  # luminance
                # Build OpenAI mask: RGBA where alpha=255 means keep, 0 means regenerate.
                # SD mask: white (255) = regenerate → alpha 0.  Black (0) = keep → alpha 255.
                # RGB must be white for keep areas; start from fully-white opaque and
                # overwrite alpha so visual contents match the expected semantic.
                alpha = mask_png.point(lambda p: 255 - p)
                oa_mask = Image.new("RGBA", source_png.size, (255, 255, 255, 255))
                oa_mask.putalpha(alpha)

View on GitHub (pinned to f9235ebbf1)