Add materials for "How to Generate Images With the OpenAI API" - #800
Open
realpython-bot wants to merge 1 commit into
Open
Add materials for "How to Generate Images With the OpenAI API"#800realpython-bot wants to merge 1 commit into
realpython-bot wants to merge 1 commit into
Conversation
Sample code for the tutorial on generating images with the OpenAI API using the GPT Image models. Replaces the DALL-E workflow in openai-dalle/, which no longer runs since OpenAI retired dall-e-2 and dall-e-3 on May 12, 2026 along with the image variations endpoint. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sample code for the upcoming tutorial How to Generate Images With the OpenAI API (CMS post 2285).
This replaces the workflow in
openai-dalle/, which no longer runs: OpenAI retireddall-e-2anddall-e-3on May 12, 2026 and removed the image variations endpoint at the same time. Calls to those models now return a400, and/v1/images/variationsreturns a404.Contents
create_png.pycreate.pyconvert.pyedit.pyNotes for reviewers
gpt-image-2, not just adapted on paper.create.py,convert.py, andedit.pyare byte-identical to the corresponding code blocks in the tutorial.convert.pycarries over fromopenai-dalle/unchanged — the response shape for saved JSON is the same.edit.pyreplacesvary.py. The variations endpoint is gone, so editing with a prompt is the closest equivalent.response_formatparameter and no URL option, so the decode step is now required rather than optional.images.edit()needs a(filename, bytes)tuple. Passing raw decoded bytes the wayvary.pydid fails with an unsupported-mimetype error, since the API infers the file type from the filename.openai-dalle/is left in place — say the word if you'd like it removed or marked deprecated in a follow-up.🤖 Generated with Claude Code