{"record":{"id":"dcad73b92f37bf05","repo":"microsoft/semantic-kernel","slug":"provide-either-image-paths-or-image-files-and","errorCode":null,"errorMessage":"Provide either 'image_paths' or 'image_files', and only one.","messagePattern":"Provide either 'image_paths' or 'image_files', and only one\\.","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py","lineNumber":212,"sourceCode":"\n            ```python\n            with open(\"./new_images/img_1.png\", \"rb\") as f:\n                results = await service.edit_image(\n                    prompt=\"Make the cat wear a wizard hat\",\n                    image_files=[f],\n                )\n            ```\n        \"\"\"\n        if not settings:\n            settings = OpenAITextToImageExecutionSettings(**kwargs)\n        if not isinstance(settings, OpenAITextToImageExecutionSettings):\n            settings = OpenAITextToImageExecutionSettings.from_prompt_execution_settings(settings)\n        settings.prompt = prompt\n\n        if not settings.prompt:\n            raise ServiceInvalidRequestError(\"Prompt is required.\")\n        if (image_paths is None and image_files is None) or (image_paths is not None and image_files is not None):\n            raise ServiceInvalidRequestError(\"Provide either 'image_paths' or 'image_files', and only one.\")\n\n        images: list[FileTypes] = []\n        if image_paths is not None:\n            images = [Path(p) for p in image_paths]\n        elif image_files is not None:\n            images = list(image_files)\n\n        mask: FileTypes | Omit = omit\n        if mask_path is not None:\n            mask = Path(mask_path)\n        elif mask_file is not None:\n            mask = mask_file\n\n        response: ImagesResponse = await self._send_image_edit_request(\n            image=images,\n            mask=mask,\n            settings=settings,\n        )","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py#L194-L230","documentation":"Raised by edit_image when the image source arguments are inconsistent. It requires exactly one of image_paths or image_files: if both are None (no input images) or both are not None (ambiguous), it throws ServiceInvalidRequestError (subclass of ServiceResponseException).","triggerScenarios":"Calling edit_image with neither image_paths nor image_files, OR passing both at once. The guard is (both None) OR (both not None).","commonSituations":"Caller defaulted both parameters to None and forgot to populate one; a generic wrapper passes both a path list and a file list; refactor left both arguments set.","solutions":["Provide exactly one source: await service.edit_image(prompt='...', image_paths=['./a.png'])","Or use file objects only: await service.edit_image(prompt='...', image_files=[f])","Add a precondition in your wrapper that asserts exactly one of the two is provided"],"exampleFix":"# before (both provided)\nawait service.edit_image(prompt=\"...\", image_paths=[\"./a.png\"], image_files=[f])\n\n# after (exactly one)\nawait service.edit_image(prompt=\"...\", image_paths=[\"./a.png\"])","handlingStrategy":"validation","validationCode":"if (image_paths is None) == (image_files is None):\n    raise ValueError(\"Provide exactly one of image_paths or image_files\")\nawait service.edit_image(prompt=prompt, image_paths=image_paths, image_files=image_files)","typeGuard":"def exactly_one_image_source(\n    image_paths: list[str] | None, image_files: list | None\n) -> bool:\n    return (image_paths is None) ^ (image_files is None)","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInvalidRequestError\n\ntry:\n    res = await service.edit_image(prompt=p, image_paths=paths, image_files=files)\nexcept ServiceInvalidRequestError as e:\n    if \"image_paths\" in str(e):\n        # fix the call to pass exactly one source\n        ...\n    raise","preventionTips":["Enforce exactly-one-of in your wrapper before calling edit_image","Default the unused source to None explicitly","Avoid passing both when refactoring"],"tags":["openai","text-to-image","image-edit","validation","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}