Skip to content

Python: New Feature: gpt-image-1 support #12500

@ymuichiro

Description

@ymuichiro

name: Python: gpt-image-1 support
about:

AzureTextToImage does not support gpt-image-1. The AzureTextToImage implementation in Semantic Kernel does not support the gpt-image-1 deployment. It currently assumes a DALL·E 3-compatible interface that returns a URL, which gpt-image-1 does not provide.

Below is a minimal code example:

async def image_sample() -> None:
    kernel = sk.Kernel()
    service_id: str = "image"
    kernel.add_service(
        AzureTextToImage(
            service_id=service_id,
            deployment_name="gpt-image-1",
            endpoint=AZURE_OPENAI_IMAGE_ENDPOINT,
            api_key=AZURE_OPENAI_IMAGE_API_KEY,
        )
    )

    service: AzureTextToImage = kernel.get_service(service_id=service_id)
    settings = service.get_prompt_execution_settings_class()(service_id=service.service_id)

    if isinstance(settings, OpenAITextToImageExecutionSettings):
        settings.prompt = "sky"
        settings.size = ImageSize(width=1024, height=1024)
        settings.quality = "low"

    if isinstance(service, AzureTextToImage):
        r = await service.generate_image(settings=settings)

        print(r)


if __name__ == "__main__":
    asyncio.run(image_sample())

Problems Identified

  1. Outdated openai-python versionThe SDK version is outdated and needs to be updated for gpt-image-1 compatibility. See: openai/openai-python@cc2c1fc
  2. Assumption of URL-based responses. The current implementation assumes a response format that includes an image url, which is not the case for gpt-image-1. See:
    raise ServiceResponseException("Failed to generate image.")

Suggested Fix

  • Add response handling logic that distinguishes between url (DALL·E 3) and b64_json (gpt-image-1).
  • Consider explicitly supporting gpt-image-1 via a new class or branching logic within AzureTextToImage.
  • (OPTIONAL) Update openai-python dependency to the latest version.

I have confirmed that even without updating the openai-python SDK, image generation with gpt-image-1 works correctly as long as you do not need to specify the latest properties#. Therefore, the only essential modification required is to handle the response format appropriately#.


Metadata

Metadata

Assignees

Labels

ai connectorAnything related to AI connectorspythonPull requests for the Python Semantic Kernel

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions