Title: Image generation | OpenAI API URL Source: https://platform.openai.com/docs/guides/image-generation Published Time: Wed, 04 Mar 2026 01:30:52 GMT Markdown Content: Image generation | OpenAI API =============== Image 13: OpenAI Developers (https://platform.openai.com/) Home (https://platform.openai.com/) API (https://platform.openai.com/api) Docs Guides and concepts for the OpenAI API (https://platform.openai.com/api/docs)API reference Endpoints, parameters, and responses (https://platform.openai.com/api/reference/overview) Codex (https://platform.openai.com/codex) ChatGPT (https://platform.openai.com/chatgpt) Apps SDK Build apps to extend ChatGPT (https://platform.openai.com/apps-sdk)Commerce Build commerce flows in ChatGPT (https://platform.openai.com/commerce) Learn (https://platform.openai.com/resources) Resources Assets for developers building with OpenAI (https://platform.openai.com/resources)Cookbook Notebook examples for building with OpenAI models (https://platform.openai.com/cookbook)Blog Learnings and experiences from developers (https://platform.openai.com/blog) API Dashboard (https://platform.openai.com/login) Search the API docs ------------------- Close Clear Primary navigation API API Reference Codex ChatGPT Learn Clear ### Get started - Overview (https://platform.openai.com/api/docs) - Quickstart (https://platform.openai.com/api/docs/quickstart) - Models (https://platform.openai.com/api/docs/models) - Pricing (https://platform.openai.com/api/docs/pricing) - Libraries (https://platform.openai.com/api/docs/libraries) - Latest: GPT-5.2 (https://platform.openai.com/api/docs/guides/latest-model) ### Core concepts - Text generation (https://platform.openai.com/api/docs/guides/text) - Code generation (https://platform.openai.com/api/docs/guides/code-generation) - Images and vision (https://platform.openai.com/api/docs/guides/images-vision) - Audio and speech (https://platform.openai.com/api/docs/guides/audio) - Structured output (https://platform.openai.com/api/docs/guides/structured-outputs) - Function calling (https://platform.openai.com/api/docs/guides/function-calling) - Responses API (https://platform.openai.com/api/docs/guides/migrate-to-responses) ### Agents - Overview (https://platform.openai.com/api/docs/guides/agents) - Build agents - Agent Builder (https://platform.openai.com/api/docs/guides/agent-builder) - Node reference (https://platform.openai.com/api/docs/guides/node-reference) - Safety in building agents (https://platform.openai.com/api/docs/guides/agent-builder-safety) - Agents SDK (https://platform.openai.com/api/docs/guides/agents-sdk) - Deploy in your product - ChatKit (https://platform.openai.com/api/docs/guides/chatkit) - Custom theming (https://platform.openai.com/api/docs/guides/chatkit-themes) - Widgets (https://platform.openai.com/api/docs/guides/chatkit-widgets) - Actions (https://platform.openai.com/api/docs/guides/chatkit-actions) - Advanced integration (https://platform.openai.com/api/docs/guides/custom-chatkit) - Optimize - Agent evals (https://platform.openai.com/api/docs/guides/agent-evals) - Trace grading (https://platform.openai.com/api/docs/guides/trace-grading) - Voice agents (https://platform.openai.com/api/docs/guides/voice-agents) ### Tools - Using tools (https://platform.openai.com/api/docs/guides/tools) - Connectors and MCP (https://platform.openai.com/api/docs/guides/tools-connectors-mcp) - Skills (https://platform.openai.com/api/docs/guides/tools-skills) - Shell (https://platform.openai.com/api/docs/guides/tools-shell) - Web search (https://platform.openai.com/api/docs/guides/tools-web-search) - Code interpreter (https://platform.openai.com/api/docs/guides/tools-code-interpreter) - File search and retrieval - File search (https://platform.openai.com/api/docs/guides/tools-file-search) - Retrieval (https://platform.openai.com/api/docs/guides/retrieval) - More tools - Image generation (https://platform.openai.com/api/docs/guides/tools-image-generation) - Computer use (https://platform.openai.com/api/docs/guides/tools-computer-use) - Local shell tool (https://platform.openai.com/api/docs/guides/tools-local-shell) - Apply patch (https://platform.openai.com/api/docs/guides/tools-apply-patch) ### Run and scale - Conversation state (https://platform.openai.com/api/docs/guides/conversation-state) - Background mode (https://platform.openai.com/api/docs/guides/background) - Streaming (https://platform.openai.com/api/docs/guides/streaming-responses) - WebSocket mode (https://platform.openai.com/api/docs/guides/websocket-mode) - Webhooks (https://platform.openai.com/api/docs/guides/webhooks) - File inputs (https://platform.openai.com/api/docs/guides/file-inputs) - Context management - Compaction (https://platform.openai.com/api/docs/guides/compaction) - Counting tokens (https://platform.openai.com/api/docs/guides/token-counting) - Prompt caching (https://platform.openai.com/api/docs/guides/prompt-caching) - Prompting - Overview (https://platform.openai.com/api/docs/guides/prompting) - Prompt engineering (https://platform.openai.com/api/docs/guides/prompt-engineering) - Reasoning - Reasoning models (https://platform.openai.com/api/docs/guides/reasoning) - Reasoning best practices (https://platform.openai.com/api/docs/guides/reasoning-best-practices) ### Evaluation - Getting started (https://platform.openai.com/api/docs/guides/evaluation-getting-started) - Working with evals (https://platform.openai.com/api/docs/guides/evals) - Prompt optimizer (https://platform.openai.com/api/docs/guides/prompt-optimizer) - External models (https://platform.openai.com/api/docs/guides/external-models) - Best practices (https://platform.openai.com/api/docs/guides/evaluation-best-practices) ### Realtime API - Overview (https://platform.openai.com/api/docs/guides/realtime) - Connect - WebRTC (https://platform.openai.com/api/docs/guides/realtime-webrtc) - WebSocket (https://platform.openai.com/api/docs/guides/realtime-websocket) - SIP (https://platform.openai.com/api/docs/guides/realtime-sip) - Usage - Using realtime models (https://platform.openai.com/api/docs/guides/realtime-models-prompting) - Managing conversations (https://platform.openai.com/api/docs/guides/realtime-conversations) - Webhooks and server-side controls (https://platform.openai.com/api/docs/guides/realtime-server-controls) - Managing costs (https://platform.openai.com/api/docs/guides/realtime-costs) - Realtime transcription (https://platform.openai.com/api/docs/guides/realtime-transcription) - Voice agents (https://openai.github.io/openai-agents-js/guides/voice-agents/quickstart/) ### Model optimization - Optimization cycle (https://platform.openai.com/api/docs/guides/model-optimization) - Fine-tuning - Supervised fine-tuning (https://platform.openai.com/api/docs/guides/supervised-fine-tuning) - Vision fine-tuning (https://platform.openai.com/api/docs/guides/vision-fine-tuning) - Direct preference optimization (https://platform.openai.com/api/docs/guides/direct-preference-optimization) - Reinforcement fine-tuning (https://platform.openai.com/api/docs/guides/reinforcement-fine-tuning) - RFT use cases (https://platform.openai.com/api/docs/guides/rft-use-cases) - Best practices (https://platform.openai.com/api/docs/guides/fine-tuning-best-practices) - Graders (https://platform.openai.com/api/docs/guides/graders) ### Specialized models - Image generation (https://platform.openai.com/api/docs/guides/image-generation) - Video generation (https://platform.openai.com/api/docs/guides/video-generation) - Text to speech (https://platform.openai.com/api/docs/guides/text-to-speech) - Speech to text (https://platform.openai.com/api/docs/guides/speech-to-text) - Deep research (https://platform.openai.com/api/docs/guides/deep-research) - Embeddings (https://platform.openai.com/api/docs/guides/embeddings) - Moderation (https://platform.openai.com/api/docs/guides/moderation) ### Going live - Production best practices (https://platform.openai.com/api/docs/guides/production-best-practices) - Latency optimization - Overview (https://platform.openai.com/api/docs/guides/latency-optimization) - Predicted Outputs (https://platform.openai.com/api/docs/guides/predicted-outputs) - Priority processing (https://platform.openai.com/api/docs/guides/priority-processing) - Cost optimization - Overview (https://platform.openai.com/api/docs/guides/cost-optimization) - Batch (https://platform.openai.com/api/docs/guides/batch) - Flex processing (https://platform.openai.com/api/docs/guides/flex-processing) - Accuracy optimization (https://platform.openai.com/api/docs/guides/optimizing-llm-accuracy) - Safety - Safety best practices (https://platform.openai.com/api/docs/guides/safety-best-practices) - Safety checks (https://platform.openai.com/api/docs/guides/safety-checks) - Cybersecurity checks (https://platform.openai.com/api/docs/guides/safety-checks/cybersecurity) - Under 18 API Guidance (https://platform.openai.com/api/docs/guides/safety-checks/under-18-api-guidance) ### Legacy APIs - Assistants API - Migration guide (https://platform.openai.com/api/docs/assistants/migration) - Deep dive (https://platform.openai.com/api/docs/assistants/deep-dive) - Tools (https://platform.openai.com/api/docs/assistants/tools) ### Resources - Terms and policies (https://openai.com/policies) - Changelog (https://platform.openai.com/api/docs/changelog) - Your data (https://platform.openai.com/api/docs/guides/your-data) - Permissions (https://platform.openai.com/api/docs/guides/rbac) - Rate limits (https://platform.openai.com/api/docs/guides/rate-limits) - Deprecations (https://platform.openai.com/api/docs/deprecations) - MCP for deep research (https://platform.openai.com/api/docs/mcp) - Developer mode (https://platform.openai.com/api/docs/guides/developer-mode) - ChatGPT Actions - Introduction (https://platform.openai.com/api/docs/actions/introduction) - Getting started (https://platform.openai.com/api/docs/actions/getting-started) - Actions library (https://platform.openai.com/api/docs/actions/actions-library) - Authentication (https://platform.openai.com/api/docs/actions/authentication) - Production (https://platform.openai.com/api/docs/actions/production) - Data retrieval (https://platform.openai.com/api/docs/actions/data-retrieval) - Sending files (https://platform.openai.com/api/docs/actions/sending-files) ### Getting Started - Overview (https://platform.openai.com/codex) - Quickstart (https://platform.openai.com/codex/quickstart) - Explore (https://platform.openai.com/codex/explore) - Pricing (https://platform.openai.com/codex/pricing) - Concepts - Prompting (https://platform.openai.com/codex/prompting) - Customization (https://platform.openai.com/codex/concepts/customization) - Multi-agents (https://platform.openai.com/codex/concepts/multi-agents) - Workflows (https://platform.openai.com/codex/workflows) - Models (https://platform.openai.com/codex/models) - Cyber Safety (https://platform.openai.com/codex/concepts/cyber-safety) ### Using Codex - App - Overview (https://platform.openai.com/codex/app) - Features (https://platform.openai.com/codex/app/features) - Settings (https://platform.openai.com/codex/app/settings) - Review (https://platform.openai.com/codex/app/review) - Automations (https://platform.openai.com/codex/app/automations) - Worktrees (https://platform.openai.com/codex/app/worktrees) - Local Environments (https://platform.openai.com/codex/app/local-environments) - Commands (https://platform.openai.com/codex/app/commands) - Troubleshooting (https://platform.openai.com/codex/app/troubleshooting) - IDE Extension - Overview (https://platform.openai.com/codex/ide) - Features (https://platform.openai.com/codex/ide/features) - Settings (https://platform.openai.com/codex/ide/settings) - IDE Commands (https://platform.openai.com/codex/ide/commands) - Slash commands (https://platform.openai.com/codex/ide/slash-commands) - CLI - Overview (https://platform.openai.com/codex/cli) - Features (https://platform.openai.com/codex/cli/features) - Command Line Options (https://platform.openai.com/codex/cli/reference) - Slash commands (https://platform.openai.com/codex/cli/slash-commands) - Web - Overview (https://platform.openai.com/codex/cloud) - Environments (https://platform.openai.com/codex/cloud/environments) - Internet Access (https://platform.openai.com/codex/cloud/internet-access) - Integrations - GitHub (https://platform.openai.com/codex/integrations/github) - Slack (https://platform.openai.com/codex/integrations/slack) - Linear (https://platform.openai.com/codex/integrations/linear) ### Configuration - Config File - Config Basics (https://platform.openai.com/codex/config-basic) - Advanced Config (https://platform.openai.com/codex/config-advanced) - Config Reference (https://platform.openai.com/codex/config-reference) - Sample Config (https://platform.openai.com/codex/config-sample) - Rules (https://platform.openai.com/codex/rules) - AGENTS.md (https://platform.openai.com/codex/guides/agents-md) - MCP (https://platform.openai.com/codex/mcp) - Skills (https://platform.openai.com/codex/skills) - Multi-agents (https://platform.openai.com/codex/multi-agent) ### Administration - Authentication (https://platform.openai.com/codex/auth) - Security (https://platform.openai.com/codex/security) - Enterprise - Admin Setup (https://platform.openai.com/codex/enterprise/admin-setup) - Governance (https://platform.openai.com/codex/enterprise/governance) - Managed configuration (https://platform.openai.com/codex/enterprise/managed-configuration) - Windows (https://platform.openai.com/codex/windows) ### Automation - Non-interactive Mode (https://platform.openai.com/codex/noninteractive) - Codex SDK (https://platform.openai.com/codex/sdk) - App Server (https://platform.openai.com/codex/app-server) - MCP Server (https://platform.openai.com/codex/guides/agents-sdk) - GitHub Action (https://platform.openai.com/codex/github-action) ### Learn - Videos (https://platform.openai.com/codex/videos) - Blog - Building frontend UIs with Codex and Figma (https://platform.openai.com/blog/building-frontend-uis-with-codex-and-figma) - Run long horizon tasks with Codex (https://platform.openai.com/blog/run-long-horizon-tasks-with-codex) - View all (https://platform.openai.com/blog/topic/codex) - Cookbooks - Codex Prompting Guide (https://platform.openai.com/cookbook/examples/gpt-5/codex_prompting_guide) - Long horizon tasks with Codex (https://platform.openai.com/cookbook/examples/codex/long_horizon_tasks) - View all (https://platform.openai.com/cookbook/topic/codex) - Building AI Teams (https://platform.openai.com/codex/guides/build-ai-native-engineering-team) ### Community - Ambassadors (https://platform.openai.com/codex/ambassadors) - Meetups (https://platform.openai.com/codex/community/meetups) ### Releases - Changelog (https://platform.openai.com/codex/changelog) - Feature Maturity (https://platform.openai.com/codex/feature-maturity) - Open Source (https://platform.openai.com/codex/open-source) Apps SDK Commerce - Home (https://platform.openai.com/apps-sdk) - Quickstart (https://platform.openai.com/apps-sdk/quickstart) ### Core Concepts - MCP Apps in ChatGPT (https://platform.openai.com/apps-sdk/mcp-apps-in-chatgpt) - MCP Server (https://platform.openai.com/apps-sdk/concepts/mcp-server) - UX principles (https://platform.openai.com/apps-sdk/concepts/ux-principles) - UI guidelines (https://platform.openai.com/apps-sdk/concepts/ui-guidelines) ### Plan - Research use cases (https://platform.openai.com/apps-sdk/plan/use-case) - Define tools (https://platform.openai.com/apps-sdk/plan/tools) - Design components (https://platform.openai.com/apps-sdk/plan/components) ### Build - Set up your server (https://platform.openai.com/apps-sdk/build/mcp-server) - Build your ChatGPT UI (https://platform.openai.com/apps-sdk/build/chatgpt-ui) - Authenticate users (https://platform.openai.com/apps-sdk/build/auth) - Manage state (https://platform.openai.com/apps-sdk/build/state-management) - Monetize your app (https://platform.openai.com/apps-sdk/build/monetization) - Examples (https://platform.openai.com/apps-sdk/build/examples) ### Deploy - Deploy your app (https://platform.openai.com/apps-sdk/deploy) - Connect from ChatGPT (https://platform.openai.com/apps-sdk/deploy/connect-chatgpt) - Test your integration (https://platform.openai.com/apps-sdk/deploy/testing) - Submit your app (https://platform.openai.com/apps-sdk/deploy/submission) ### Guides - Optimize Metadata (https://platform.openai.com/apps-sdk/guides/optimize-metadata) - Security & Privacy (https://platform.openai.com/apps-sdk/guides/security-privacy) - Troubleshooting (https://platform.openai.com/apps-sdk/deploy/troubleshooting) ### Resources - Changelog (https://platform.openai.com/apps-sdk/changelog) - App submission guidelines (https://platform.openai.com/apps-sdk/app-submission-guidelines) - Reference (https://platform.openai.com/apps-sdk/reference) - Home (https://platform.openai.com/commerce) ### Guides - Get started (https://platform.openai.com/commerce/guides/get-started) - Key concepts (https://platform.openai.com/commerce/guides/key-concepts) - Production readiness (https://platform.openai.com/commerce/guides/production) ### Commerce specs - Agentic Checkout (https://platform.openai.com/commerce/specs/checkout) - Delegated Payment (https://platform.openai.com/commerce/specs/payment) ### Product feeds - Overview (https://platform.openai.com/commerce/product-feeds) - Onboarding (https://platform.openai.com/commerce/product-feeds/onboarding) - Feed spec (https://platform.openai.com/commerce/product-feeds/spec) - Best practices (https://platform.openai.com/commerce/product-feeds/best-practices) Resources Cookbook Blog - Home (https://platform.openai.com/resources) - Docs MCP (https://platform.openai.com/resources/docs-mcp) ### Categories - Code (https://platform.openai.com/resources/code) - Cookbooks (https://platform.openai.com/cookbook) - Guides (https://platform.openai.com/resources/guides) - Videos (https://platform.openai.com/resources/videos) ### Topics - Agents (https://platform.openai.com/resources/agents) - Audio & Voice (https://platform.openai.com/resources/audio) - Computer use (https://platform.openai.com/resources/cua) - Codex (https://platform.openai.com/resources/codex) - Evals (https://platform.openai.com/resources/evals) - gpt-oss (https://platform.openai.com/resources/gpt-oss) - Fine-tuning (https://platform.openai.com/resources/fine-tuning) - Image generation (https://platform.openai.com/resources/imagegen) - Scaling (https://platform.openai.com/resources/scaling) - Tools (https://platform.openai.com/resources/tools) - Video generation (https://platform.openai.com/resources/videogen) - Home (https://platform.openai.com/cookbook) ### Topics - Agents (https://platform.openai.com/cookbook/topic/agents) - Evals (https://platform.openai.com/cookbook/topic/evals) - Multimodal (https://platform.openai.com/cookbook/topic/multimodal) - Text (https://platform.openai.com/cookbook/topic/text) - Guardrails (https://platform.openai.com/cookbook/topic/guardrails) - Optimization (https://platform.openai.com/cookbook/topic/optimization) - ChatGPT (https://platform.openai.com/cookbook/topic/chatgpt) - Codex (https://platform.openai.com/cookbook/topic/codex) - gpt-oss (https://platform.openai.com/cookbook/topic/gpt-oss) ### Contribute - Cookbook on GitHub (https://github.com/openai/openai-cookbook) - All posts (https://platform.openai.com/blog) ### Recent - Building frontend UIs with Codex and Figma (https://platform.openai.com/blog/building-frontend-uis-with-codex-and-figma) - Run long horizon tasks with Codex (https://platform.openai.com/blog/run-long-horizon-tasks-with-codex) - Shell + Skills + Compaction: Tips for long-running agents that do real work (https://platform.openai.com/blog/skills-shell-tips) - 15 lessons learned building ChatGPT Apps (https://platform.openai.com/blog/15-lessons-building-chatgpt-apps) - Testing Agent Skills Systematically with Evals (https://platform.openai.com/blog/eval-skills) ### Topics - General (https://platform.openai.com/blog/topic/general) - API (https://platform.openai.com/blog/topic/api) - Apps SDK (https://platform.openai.com/blog/topic/apps-sdk) - Audio (https://platform.openai.com/blog/topic/audio) - Codex (https://platform.openai.com/blog/topic/codex) API Dashboard (https://platform.openai.com/login) Search ⌘ K ### Get started - Overview (https://platform.openai.com/api/docs) - Quickstart (https://platform.openai.com/api/docs/quickstart) - Models (https://platform.openai.com/api/docs/models) - Pricing (https://platform.openai.com/api/docs/pricing) - Libraries (https://platform.openai.com/api/docs/libraries) - Latest: GPT-5.2 (https://platform.openai.com/api/docs/guides/latest-model) ### Core concepts - Text generation (https://platform.openai.com/api/docs/guides/text) - Code generation (https://platform.openai.com/api/docs/guides/code-generation) - Images and vision (https://platform.openai.com/api/docs/guides/images-vision) - Audio and speech (https://platform.openai.com/api/docs/guides/audio) - Structured output (https://platform.openai.com/api/docs/guides/structured-outputs) - Function calling (https://platform.openai.com/api/docs/guides/function-calling) - Responses API (https://platform.openai.com/api/docs/guides/migrate-to-responses) ### Agents - Overview (https://platform.openai.com/api/docs/guides/agents) - Build agents - Agent Builder (https://platform.openai.com/api/docs/guides/agent-builder) - Node reference (https://platform.openai.com/api/docs/guides/node-reference) - Safety in building agents (https://platform.openai.com/api/docs/guides/agent-builder-safety) - Agents SDK (https://platform.openai.com/api/docs/guides/agents-sdk) - Deploy in your product - ChatKit (https://platform.openai.com/api/docs/guides/chatkit) - Custom theming (https://platform.openai.com/api/docs/guides/chatkit-themes) - Widgets (https://platform.openai.com/api/docs/guides/chatkit-widgets) - Actions (https://platform.openai.com/api/docs/guides/chatkit-actions) - Advanced integration (https://platform.openai.com/api/docs/guides/custom-chatkit) - Optimize - Agent evals (https://platform.openai.com/api/docs/guides/agent-evals) - Trace grading (https://platform.openai.com/api/docs/guides/trace-grading) - Voice agents (https://platform.openai.com/api/docs/guides/voice-agents) ### Tools - Using tools (https://platform.openai.com/api/docs/guides/tools) - Connectors and MCP (https://platform.openai.com/api/docs/guides/tools-connectors-mcp) - Skills (https://platform.openai.com/api/docs/guides/tools-skills) - Shell (https://platform.openai.com/api/docs/guides/tools-shell) - Web search (https://platform.openai.com/api/docs/guides/tools-web-search) - Code interpreter (https://platform.openai.com/api/docs/guides/tools-code-interpreter) - File search and retrieval - File search (https://platform.openai.com/api/docs/guides/tools-file-search) - Retrieval (https://platform.openai.com/api/docs/guides/retrieval) - More tools - Image generation (https://platform.openai.com/api/docs/guides/tools-image-generation) - Computer use (https://platform.openai.com/api/docs/guides/tools-computer-use) - Local shell tool (https://platform.openai.com/api/docs/guides/tools-local-shell) - Apply patch (https://platform.openai.com/api/docs/guides/tools-apply-patch) ### Run and scale - Conversation state (https://platform.openai.com/api/docs/guides/conversation-state) - Background mode (https://platform.openai.com/api/docs/guides/background) - Streaming (https://platform.openai.com/api/docs/guides/streaming-responses) - WebSocket mode (https://platform.openai.com/api/docs/guides/websocket-mode) - Webhooks (https://platform.openai.com/api/docs/guides/webhooks) - File inputs (https://platform.openai.com/api/docs/guides/file-inputs) - Context management - Compaction (https://platform.openai.com/api/docs/guides/compaction) - Counting tokens (https://platform.openai.com/api/docs/guides/token-counting) - Prompt caching (https://platform.openai.com/api/docs/guides/prompt-caching) - Prompting - Overview (https://platform.openai.com/api/docs/guides/prompting) - Prompt engineering (https://platform.openai.com/api/docs/guides/prompt-engineering) - Reasoning - Reasoning models (https://platform.openai.com/api/docs/guides/reasoning) - Reasoning best practices (https://platform.openai.com/api/docs/guides/reasoning-best-practices) ### Evaluation - Getting started (https://platform.openai.com/api/docs/guides/evaluation-getting-started) - Working with evals (https://platform.openai.com/api/docs/guides/evals) - Prompt optimizer (https://platform.openai.com/api/docs/guides/prompt-optimizer) - External models (https://platform.openai.com/api/docs/guides/external-models) - Best practices (https://platform.openai.com/api/docs/guides/evaluation-best-practices) ### Realtime API - Overview (https://platform.openai.com/api/docs/guides/realtime) - Connect - WebRTC (https://platform.openai.com/api/docs/guides/realtime-webrtc) - WebSocket (https://platform.openai.com/api/docs/guides/realtime-websocket) - SIP (https://platform.openai.com/api/docs/guides/realtime-sip) - Usage - Using realtime models (https://platform.openai.com/api/docs/guides/realtime-models-prompting) - Managing conversations (https://platform.openai.com/api/docs/guides/realtime-conversations) - Webhooks and server-side controls (https://platform.openai.com/api/docs/guides/realtime-server-controls) - Managing costs (https://platform.openai.com/api/docs/guides/realtime-costs) - Realtime transcription (https://platform.openai.com/api/docs/guides/realtime-transcription) - Voice agents (https://openai.github.io/openai-agents-js/guides/voice-agents/quickstart/) ### Model optimization - Optimization cycle (https://platform.openai.com/api/docs/guides/model-optimization) - Fine-tuning - Supervised fine-tuning (https://platform.openai.com/api/docs/guides/supervised-fine-tuning) - Vision fine-tuning (https://platform.openai.com/api/docs/guides/vision-fine-tuning) - Direct preference optimization (https://platform.openai.com/api/docs/guides/direct-preference-optimization) - Reinforcement fine-tuning (https://platform.openai.com/api/docs/guides/reinforcement-fine-tuning) - RFT use cases (https://platform.openai.com/api/docs/guides/rft-use-cases) - Best practices (https://platform.openai.com/api/docs/guides/fine-tuning-best-practices) - Graders (https://platform.openai.com/api/docs/guides/graders) ### Specialized models - Image generation (https://platform.openai.com/api/docs/guides/image-generation) - Video generation (https://platform.openai.com/api/docs/guides/video-generation) - Text to speech (https://platform.openai.com/api/docs/guides/text-to-speech) - Speech to text (https://platform.openai.com/api/docs/guides/speech-to-text) - Deep research (https://platform.openai.com/api/docs/guides/deep-research) - Embeddings (https://platform.openai.com/api/docs/guides/embeddings) - Moderation (https://platform.openai.com/api/docs/guides/moderation) ### Going live - Production best practices (https://platform.openai.com/api/docs/guides/production-best-practices) - Latency optimization - Overview (https://platform.openai.com/api/docs/guides/latency-optimization) - Predicted Outputs (https://platform.openai.com/api/docs/guides/predicted-outputs) - Priority processing (https://platform.openai.com/api/docs/guides/priority-processing) - Cost optimization - Overview (https://platform.openai.com/api/docs/guides/cost-optimization) - Batch (https://platform.openai.com/api/docs/guides/batch) - Flex processing (https://platform.openai.com/api/docs/guides/flex-processing) - Accuracy optimization (https://platform.openai.com/api/docs/guides/optimizing-llm-accuracy) - Safety - Safety best practices (https://platform.openai.com/api/docs/guides/safety-best-practices) - Safety checks (https://platform.openai.com/api/docs/guides/safety-checks) - Cybersecurity checks (https://platform.openai.com/api/docs/guides/safety-checks/cybersecurity) - Under 18 API Guidance (https://platform.openai.com/api/docs/guides/safety-checks/under-18-api-guidance) ### Legacy APIs - Assistants API - Migration guide (https://platform.openai.com/api/docs/assistants/migration) - Deep dive (https://platform.openai.com/api/docs/assistants/deep-dive) - Tools (https://platform.openai.com/api/docs/assistants/tools) ### Resources - Terms and policies (https://openai.com/policies) - Changelog (https://platform.openai.com/api/docs/changelog) - Your data (https://platform.openai.com/api/docs/guides/your-data) - Permissions (https://platform.openai.com/api/docs/guides/rbac) - Rate limits (https://platform.openai.com/api/docs/guides/rate-limits) - Deprecations (https://platform.openai.com/api/docs/deprecations) - MCP for deep research (https://platform.openai.com/api/docs/mcp) - Developer mode (https://platform.openai.com/api/docs/guides/developer-mode) - ChatGPT Actions - Introduction (https://platform.openai.com/api/docs/actions/introduction) - Getting started (https://platform.openai.com/api/docs/actions/getting-started) - Actions library (https://platform.openai.com/api/docs/actions/actions-library) - Authentication (https://platform.openai.com/api/docs/actions/authentication) - Production (https://platform.openai.com/api/docs/actions/production) - Data retrieval (https://platform.openai.com/api/docs/actions/data-retrieval) - Sending files (https://platform.openai.com/api/docs/actions/sending-files) GPT-Image - Overview (https://platform.openai.com/docs/guides/image-generation#overview) - Generate Images (https://platform.openai.com/docs/guides/image-generation#generate-images) - Edit Images (https://platform.openai.com/docs/guides/image-generation#edit-images) - Customize Image Output (https://platform.openai.com/docs/guides/image-generation#customize-image-output) - Limitations (https://platform.openai.com/docs/guides/image-generation#limitations) - Cost and latency (https://platform.openai.com/docs/guides/image-generation#cost-and-latency) Image Generation cookbook Try out image generation and edits (https://platform.openai.com/cookbook/examples/generate_images_with_gpt_image) Copy Page More page actions GPT-Image Copy Page More page actions Image generation ================ Learn how to generate or edit images. Explore Image 14 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=sci-fi-hangar)Image 15 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=mechanical-bouquet)Image 16 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=mechanical-watch)Image 17 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=botanical-perfume)Image 18 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=lavender-sunrise)Image 19 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=winter-wolf-portrait)Image 20 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=desert-sunrise-portrait)Image 21 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=chess-set)Image 22 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=underwater-ballerina)Image 23 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=album-cover)Image 24 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=abstract-orbit)Image 25 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=alien)Image 26 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=icons)Image 27 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=3d-city)Image 28 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=ink-wash-temple)Image 29 (https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=cliffside-portrait)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=chameleon-macro)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=clay-garden-scene)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=coral-reef)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=alien-rock)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=clay-figurine)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=furniture)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=cafe-friends)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=ceramic-mug)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=hiking-poster)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=floorplan)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=mountain-bike)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=barista-ad)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=interior-design)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=garden-portrait)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=paper-sculpture-city)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=colorize)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=game-design)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=sprites)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=cosmic-ballet)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=chocolate)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=wedding-portrait)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=street-cafe)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=paper-cut-forest)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=buildings-sprite)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=rooftop-garden)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=thunderstorm)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=solar-roof)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=spacecraft-dashboard)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=daytime)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=animation)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=mountain-map)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=isometric-icons)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=patterns)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=landscape)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=glass-speaker)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=robot-toy)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=bottle)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=construction-crew)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=whales-poster)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=neon)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=kids-storybook)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=sneakers)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=school-lab)[](https://platform.openai.com/api/docs/guides/image-generation?gallery=open&galleryItem=kyoto-poster) Overview -------- The OpenAI API lets you generate and edit images from text prompts, using GPT Image or DALL·E models. You can access image generation capabilities through two APIs: ### Image API The Image API (https://platform.openai.com/api/docs/api-reference/images) provides three endpoints, each with distinct capabilities: - Generations: Generate images (https://platform.openai.com/docs/guides/image-generation#generate-images) from scratch based on a text prompt - Edits: Modify existing images (https://platform.openai.com/docs/guides/image-generation#edit-images) using a new prompt, either partially or entirely - Variations: Generate variations (https://platform.openai.com/docs/guides/image-generation#image-variations) of an existing image (available with DALL·E 2 only) This API supports GPT Image models (gpt-image-1.5, gpt-image-1, and gpt-image-1-mini) as well as dall-e-2 and dall-e-3. ### Responses API The Responses API (https://platform.openai.com/api/docs/api-reference/responses/create#responses-create-tools) allows you to generate images as part of conversations or multi-step flows. It supports image generation as a built-in tool (https://platform.openai.com/api/docs/guides/tools?api-mode=responses), and accepts image inputs and outputs within context. Compared to the Image API, it adds: - Multi-turn editing: Iteratively make high fidelity edits to images with prompting - Flexible inputs: Accept image File (https://platform.openai.com/api/docs/api-reference/files) IDs as input images, not just bytes The image generation tool in responses uses GPT Image models (gpt-image-1.5, gpt-image-1, and gpt-image-1-mini). When using gpt-image-1.5 and chatgpt-image-latest with the Responses API, you can optionally set the action parameter, detailed below. For a list of mainline models that support calling this tool, refer to the supported models (https://platform.openai.com/docs/guides/image-generation#supported-models) below. ### Choosing the right API - If you only need to generate or edit a single image from one prompt, the Image API is your best choice. - If you want to build conversational, editable image experiences with GPT Image, go with the Responses API. Both APIs let you customize output (https://platform.openai.com/docs/guides/image-generation#customize-image-output) — adjust quality, size, format, compression, and enable transparent backgrounds. DALL·E 2 is our oldest image generation model and therefore has significant limitations. For a better experience, we recommend using GPT Image (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image). DALL·E 3 is our previous generation model and has some limitations. For a better experience, we recommend using GPT Image (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image). ### Model comparison Our latest and most advanced model for image generation is gpt-image-1.5, a natively multimodal language model, part of the GPT Image family. GPT Image models include gpt-image-1.5 (state of the art), gpt-image-1, and gpt-image-1-mini. They share the same API surface, with gpt-image-1.5 offering the best overall quality. We recommend using gpt-image-1.5 for the best experience, but if you are looking for a more cost-effective option and image quality isn’t a priority, you can use gpt-image-1-mini. You can also use specialized image generation models—DALL·E 2 and DALL·E 3—with the Image API, but please note these models are now deprecated and we will stop supporting them on 05/12, 2026. | Model | Endpoints | Use case | | --- | --- | --- | | DALL·E 2 | Image API: Generations, Edits, Variations | Lower cost, concurrent requests, inpainting (image editing with a mask) | | DALL·E 3 | Image API: Generations only | Higher image quality than DALL·E 2, support for larger resolutions | | GPT Image | Image API: Generations, Edits – Responses API (as part of the image generation tool) | Superior instruction following, text rendering, detailed editing, real-world knowledge | This guide focuses on GPT Image, but you can also switch to the docs for DALL·E 2 (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=dall-e-2) and DALL·E 3 (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=dall-e-3). To ensure this model is used responsibly, you may need to complete the API Organization Verification (https://help.openai.com/en/articles/10910291-api-organization-verification) from your developer console (https://platform.openai.com/settings/organization/general) before using GPT Image models, including gpt-image-1.5, gpt-image-1, and gpt-image-1-mini. This guide focuses on DALL·E 2, but you can also switch to the docs for GPT Image (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image) and DALL·E 3 (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=dall-e-3). This guide focuses on DALL·E 3, but you can also switch to the docs for GPT Image (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image) and DALL·E 2 (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=dall-e-2). Image 30: A beige coffee mug on a wooden table Generate Images --------------- You can use the image generation endpoint (https://platform.openai.com/api/docs/api-reference/images/create) to create images based on text prompts, or the image generation tool (https://platform.openai.com/api/docs/guides/tools?api-mode=responses) in the Responses API to generate images as part of a conversation. To learn more about customizing the output (size, quality, format, transparency), refer to the customize image output (https://platform.openai.com/docs/guides/image-generation#customize-image-output) section below. You can set the n parameter to generate multiple images at once in a single request (by default, the API returns a single image). Responses API Image API Responses API Generate an image python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import OpenAI from "openai"; const openai = new OpenAI(); const response = await openai.responses.create({ model: "gpt-5", input: "Generate an image of gray tabby cat hugging an otter with an orange scarf", tools: [{type: "image_generation"}], }); // Save the image to a file const imageData = response.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData.length > 0) { const imageBase64 = imageData[0]; const fs = await import("fs"); fs.writeFileSync("otter.png", Buffer.from(imageBase64, "base64")); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 from openai import OpenAI import base64 client = OpenAI() response = client.responses.create( model="gpt-5", input="Generate an image of gray tabby cat hugging an otter with an orange scarf", tools=[{"type": "image_generation"}], ) # Save the image to a file image_data = [ output.result for output in response.output if output.type == "image_generation_call" ] if image_data: image_base64 = image_data[0] with open("otter.png", "wb") as f: f.write(base64.b64decode(image_base64)) Image API Generate an image python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import OpenAI from "openai"; import fs from "fs"; const openai = new OpenAI(); const prompt = ` A children's book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter. `; const result = await openai.images.generate({ model: "gpt-image-1", prompt, }); // Save the image to a file const image_base64 = result.data[0].b64_json; const image_bytes = Buffer.from(image_base64, "base64"); fs.writeFileSync("otter.png", image_bytes); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 from openai import OpenAI import base64 client = OpenAI() prompt = """ A children's book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter. """ result = client.images.generate( model="gpt-image-1", prompt=prompt ) image_base64 = result.data[0].b64_json image_bytes = base64.b64decode(image_base64) # Save the image to a file with open("otter.png", "wb") as f: f.write(image_bytes) 1 2 3 4 5 6 7 curl -X POST "https://api.openai.com/v1/images/generations" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-type: application/json" \ -d '{ "model": "gpt-image-1", "prompt": "A childrens book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter." }' | jq -r '.data[0].b64_json' | base64 --decode > otter.png ### Multi-turn image generation With the Responses API, you can build multi-turn conversations involving image generation either by providing image generation calls outputs within context (you can also just use the image ID), or by using the previous_response_id parameter (https://platform.openai.com/api/docs/guides/conversation-state?api-mode=responses#openai-apis-for-conversation-state). This makes it easy to iterate on images across multiple turns—refining prompts, applying new instructions, and evolving the visual output as the conversation progresses. ### Generate vs Edit With the Responses API you can choose whether to generate a new image or edit one already in the conversation. The optional action parameter (supported on gpt-image-1.5 and chatgpt-image-latest) controls this behavior: keep action: "auto" to let the model decide (recommended), set action: "generate" to always create a new image, or set action: "edit" to force editing (requires an image in context). Force image creation with action python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import OpenAI from "openai"; const openai = new OpenAI(); const response = await openai.responses.create({ model: "gpt-5", input: "Generate an image of gray tabby cat hugging an otter with an orange scarf", tools: [{type: "image_generation", action: "generate"}], }); // Save the image to a file const imageData = response.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData.length > 0) { const imageBase64 = imageData[0]; const fs = await import("fs"); fs.writeFileSync("otter.png", Buffer.from(imageBase64, "base64")); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 from openai import OpenAI import base64 client = OpenAI() response = client.responses.create( model="gpt-5", input="Generate an image of gray tabby cat hugging an otter with an orange scarf", tools=[{"type": "image_generation", "action": "generate"}], ) # Save the image to a file image_data = [ output.result for output in response.output if output.type == "image_generation_call" ] if image_data: image_base64 = image_data[0] with open("otter.png", "wb") as f: f.write(base64.b64decode(image_base64)) If you force edit without providing an image in context, the call will return an error. Leave action at auto to have the model decide when to generate or edit. When action is set to auto, the image_generation_call result includes an action field so you can see whether the model generated a new image or edited one already in context: 1 2 3 4 5 6 7 8 9 10 11 12 { "id": "ig_123...", "type": "image_generation_call", "status": "completed", "background": "opaque", "output_format": "jpeg", "quality": "medium", "result": "/9j/4...", "revised_prompt": "...", "size": "1024x1024", "action": "generate" } Using previous response ID Using image ID Using previous response ID Multi-turn image generation python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 import OpenAI from "openai"; const openai = new OpenAI(); const response = await openai.responses.create({ model: "gpt-5", input: "Generate an image of gray tabby cat hugging an otter with an orange scarf", tools: [{ type: "image_generation" }], }); const imageData = response.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData.length > 0) { const imageBase64 = imageData[0]; const fs = await import("fs"); fs.writeFileSync("cat_and_otter.png", Buffer.from(imageBase64, "base64")); } // Follow up const response_fwup = await openai.responses.create({ model: "gpt-5", previous_response_id: response.id, input: "Now make it look realistic", tools: [{ type: "image_generation" }], }); const imageData_fwup = response_fwup.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData_fwup.length > 0) { const imageBase64 = imageData_fwup[0]; const fs = await import("fs"); fs.writeFileSync( "cat_and_otter_realistic.png", Buffer.from(imageBase64, "base64") ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 from openai import OpenAI import base64 client = OpenAI() response = client.responses.create( model="gpt-5", input="Generate an image of gray tabby cat hugging an otter with an orange scarf", tools=[{"type": "image_generation"}], ) image_data = [ output.result for output in response.output if output.type == "image_generation_call" ] if image_data: image_base64 = image_data[0] with open("cat_and_otter.png", "wb") as f: f.write(base64.b64decode(image_base64)) # Follow up response_fwup = client.responses.create( model="gpt-5", previous_response_id=response.id, input="Now make it look realistic", tools=[{"type": "image_generation"}], ) image_data_fwup = [ output.result for output in response_fwup.output if output.type == "image_generation_call" ] if image_data_fwup: image_base64 = image_data_fwup[0] with open("cat_and_otter_realistic.png", "wb") as f: f.write(base64.b64decode(image_base64)) Using image ID Multi-turn image generation python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 import OpenAI from "openai"; const openai = new OpenAI(); const response = await openai.responses.create({ model: "gpt-5", input: "Generate an image of gray tabby cat hugging an otter with an orange scarf", tools: [{ type: "image_generation" }], }); const imageGenerationCalls = response.output.filter( (output) => output.type === "image_generation_call" ); const imageData = imageGenerationCalls.map((output) => output.result); if (imageData.length > 0) { const imageBase64 = imageData[0]; const fs = await import("fs"); fs.writeFileSync("cat_and_otter.png", Buffer.from(imageBase64, "base64")); } // Follow up const response_fwup = await openai.responses.create({ model: "gpt-5", input: [ { role: "user", content: [{ type: "input_text", text: "Now make it look realistic" }], }, { type: "image_generation_call", id: imageGenerationCalls[0].id, }, ], tools: [{ type: "image_generation" }], }); const imageData_fwup = response_fwup.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData_fwup.length > 0) { const imageBase64 = imageData_fwup[0]; const fs = await import("fs"); fs.writeFileSync( "cat_and_otter_realistic.png", Buffer.from(imageBase64, "base64") ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 import openai import base64 response = openai.responses.create( model="gpt-5", input="Generate an image of gray tabby cat hugging an otter with an orange scarf", tools=[{"type": "image_generation"}], ) image_generation_calls = [ output for output in response.output if output.type == "image_generation_call" ] image_data = [output.result for output in image_generation_calls] if image_data: image_base64 = image_data[0] with open("cat_and_otter.png", "wb") as f: f.write(base64.b64decode(image_base64)) # Follow up response_fwup = openai.responses.create( model="gpt-5", input=[ { "role": "user", "content": [{"type": "input_text", "text": "Now make it look realistic"}], }, { "type": "image_generation_call", "id": image_generation_calls[0].id, }, ], tools=[{"type": "image_generation"}], ) image_data_fwup = [ output.result for output in response_fwup.output if output.type == "image_generation_call" ] if image_data_fwup: image_base64 = image_data_fwup[0] with open("cat_and_otter_realistic.png", "wb") as f: f.write(base64.b64decode(image_base64)) #### Result “Generate an image of gray tabby cat hugging an otter with an orange scarf”Image 31: A cat and an otter “Now make it look realistic”Image 32: A cat and an otter ### Streaming The Responses API and Image API support streaming image generation. This allows you to stream partial images as they are generated, providing a more interactive experience. You can adjust the partial_images parameter to receive 0-3 partial images. - If you set partial_images to 0, you will only receive the final image. - For values larger than zero, you may not receive the full number of partial images you requested if the full image is generated more quickly. Responses API Image API Responses API Stream an image python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import OpenAI from "openai"; import fs from "fs"; const openai = new OpenAI(); const stream = await openai.responses.create({ model: "gpt-4.1", input: "Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape", stream: true, tools: [{ type: "image_generation", partial_images: 2 }], }); for await (const event of stream) { if (event.type === "response.image_generation_call.partial_image") { const idx = event.partial_image_index; const imageBase64 = event.partial_image_b64; const imageBuffer = Buffer.from(imageBase64, "base64"); fs.writeFileSync(`river${idx}.png`, imageBuffer); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 from openai import OpenAI import base64 client = OpenAI() stream = client.responses.create( model="gpt-4.1", input="Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape", stream=True, tools=[{"type": "image_generation", "partial_images": 2}], ) for event in stream: if event.type == "response.image_generation_call.partial_image": idx = event.partial_image_index image_base64 = event.partial_image_b64 image_bytes = base64.b64decode(image_base64) with open(f"river{idx}.png", "wb") as f: f.write(image_bytes) Image API Stream an image python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import fs from "fs"; import OpenAI from "openai"; const openai = new OpenAI(); const prompt = "Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape"; const stream = await openai.images.generate({ prompt: prompt, model: "gpt-image-1", stream: true, partial_images: 2, }); for await (const event of stream) { if (event.type === "image_generation.partial_image") { const idx = event.partial_image_index; const imageBase64 = event.b64_json; const imageBuffer = Buffer.from(imageBase64, "base64"); fs.writeFileSync(`river${idx}.png`, imageBuffer); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 from openai import OpenAI import base64 client = OpenAI() stream = client.images.generate( prompt="Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape", model="gpt-image-1", stream=True, partial_images=2, ) for event in stream: if event.type == "image_generation.partial_image": idx = event.partial_image_index image_base64 = event.b64_json image_bytes = base64.b64decode(image_base64) with open(f"river{idx}.png", "wb") as f: f.write(image_bytes) #### Result | Partial 1 | Partial 2 | Final image | | --- | --- | --- | | Image 33: 1st partial | Image 34: 2nd partial | Image 35: 3rd partial | Prompt: Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape ### Revised prompt When using the image generation tool in the Responses API, the mainline model (e.g. gpt-4.1) will automatically revise your prompt for improved performance. You can access the revised prompt in the revised_prompt field of the image generation call: 1 2 3 4 5 6 7 { "id": "ig_123", "type": "image_generation_call", "status": "completed", "revised_prompt": "A gray tabby cat hugging an otter. The otter is wearing an orange scarf. Both animals are cute and friendly, depicted in a warm, heartwarming style.", "result": "..." } You can use the image generation endpoint (https://platform.openai.com/api/docs/api-reference/images/create) to create images based on text prompts. To learn more about customizing the output (size, quality, format, transparency), refer to the customize image output (https://platform.openai.com/docs/guides/image-generation#customize-image-output) section below. You can set the n parameter to generate multiple images at once in a single request (by default, the API returns a single image). Generate an image python 1 2 3 4 5 6 7 8 9 10 import OpenAI from "openai"; const openai = new OpenAI(); const result = await openai.images.generate({ model: "dall-e-3", prompt: "a white siamese cat", size: "1024x1024", }); console.log(result.data[0].url); 1 2 3 4 5 6 7 8 9 10 11 12 from openai import OpenAI client = OpenAI() result = client.images.generate( model="dall-e-2", prompt="a white siamese cat", size="1024x1024", quality="standard", n=1, ) print(result.data[0].url) 1 2 3 4 5 6 7 8 9 curl https://api.openai.com/v1/images/generations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "dall-e-2", "prompt": "a white siamese cat", "n": 1, "size": "1024x1024" }' You can use the image generation endpoint (https://platform.openai.com/api/docs/api-reference/images/create) to create images based on text prompts. To learn more about customizing the output (size, quality, format, transparency), refer to the customize image output (https://platform.openai.com/docs/guides/image-generation#customize-image-output) section below. Generate an image python 1 2 3 4 5 6 7 8 9 10 import OpenAI from "openai"; const openai = new OpenAI(); const result = await openai.images.generate({ model: "dall-e-3", prompt: "a white siamese cat", size: "1024x1024", }); console.log(result.data[0].url); 1 2 3 4 5 6 7 8 9 10 from openai import OpenAI client = OpenAI() result = client.images.generate( model="dall-e-3", prompt="a white siamese cat", size="1024x1024" ) print(result.data[0].url) 1 2 3 4 5 6 7 8 curl https://api.openai.com/v1/images/generations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "dall-e-3", "prompt": "a white siamese cat", "size": "1024x1024" }' ### Prompting tips When you use DALL·E 3, OpenAI automatically rewrites your prompt for safety reasons and to add more detail. You can’t disable this feature, but you can get outputs closer to your requested image by adding the following to your prompt: I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS: The updated prompt is visible in the revised_prompt field of the data response object. Edit Images ----------- The image edits (https://platform.openai.com/api/docs/api-reference/images/createEdit) endpoint lets you: - Edit existing images - Generate new images using other images as a reference - Edit parts of an image by uploading an image and mask indicating which areas should be replaced (a process known as inpainting) ### Create a new image using image references You can use one or more images as a reference to generate a new image. In this example, we’ll use 4 input images to generate a new image of a gift basket containing the items in the reference images. Image 36: Body Lotion (https://cdn.openai.com/API/docs/images/body-lotion.png)Image 37: Soap (https://cdn.openai.com/API/docs/images/soap.png)Image 38: Incense Kit (https://cdn.openai.com/API/docs/images/incense-kit.png)Image 39: Bath Bomb (https://cdn.openai.com/API/docs/images/bath-bomb.png) Image 40: Bath Gift Set Responses API Image API Responses API With the Responses API, you can provide input images in 3 different ways: - By providing a fully qualified URL - By providing an image as a Base64-encoded data URL - By providing a file ID (created with the Files API (https://platform.openai.com/api/docs/api-reference/files)) Create a File Edit an image python 1 2 3 4 5 6 7 8 9 10 from openai import OpenAI client = OpenAI() def create_file(file_path): with open(file_path, "rb") as file_content: result = client.files.create( file=file_content, purpose="vision", ) return result.id 1 2 3 4 5 6 7 8 9 10 11 12 13 import fs from "fs"; import OpenAI from "openai"; const openai = new OpenAI(); async function createFile(filePath) { const fileContent = fs.createReadStream(filePath); const result = await openai.files.create({ file: fileContent, purpose: "vision", }); return result.id; } Create a base64 encoded image Edit an image python 1 2 3 4 def encode_image(file_path): with open(file_path, "rb") as f: base64_image = base64.b64encode(f.read()).decode("utf-8") return base64_image 1 2 3 4 function encodeImage(filePath) { const base64Image = fs.readFileSync(filePath, "base64"); return base64Image; } Edit an image python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 from openai import OpenAI import base64 client = OpenAI() prompt = """Generate a photorealistic image of a gift basket on a white background labeled 'Relax & Unwind' with a ribbon and handwriting-like font, containing all the items in the reference pictures.""" base64_image1 = encode_image("body-lotion.png") base64_image2 = encode_image("soap.png") file_id1 = create_file("body-lotion.png") file_id2 = create_file("incense-kit.png") response = client.responses.create( model="gpt-4.1", input=[ { "role": "user", "content": [ {"type": "input_text", "text": prompt}, { "type": "input_image", "image_url": f"data:image/jpeg;base64,{base64_image1}", }, { "type": "input_image", "image_url": f"data:image/jpeg;base64,{base64_image2}", }, { "type": "input_image", "file_id": file_id1, }, { "type": "input_image", "file_id": file_id2, } ], } ], tools=[{"type": "image_generation"}], ) image_generation_calls = [ output for output in response.output if output.type == "image_generation_call" ] image_data = [output.result for output in image_generation_calls] if image_data: image_base64 = image_data[0] with open("gift-basket.png", "wb") as f: f.write(base64.b64decode(image_base64)) else: print(response.output.content) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 import fs from "fs"; import OpenAI from "openai"; const openai = new OpenAI(); const prompt = `Generate a photorealistic image of a gift basket on a white background labeled 'Relax & Unwind' with a ribbon and handwriting-like font, containing all the items in the reference pictures.`; const base64Image1 = encodeImage("body-lotion.png"); const base64Image2 = encodeImage("soap.png"); const fileId1 = await createFile("body-lotion.png"); const fileId2 = await createFile("incense-kit.png"); const response = await openai.responses.create({ model: "gpt-4.1", input: [ { role: "user", content: [ { type: "input_text", text: prompt }, { type: "input_image", image_url: `data:image/jpeg;base64,${base64Image1}`, }, { type: "input_image", image_url: `data:image/jpeg;base64,${base64Image2}`, }, { type: "input_image", file_id: fileId1, }, { type: "input_image", file_id: fileId2, }, ], }, ], tools: [{type: "image_generation"}], }); const imageData = response.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData.length > 0) { const imageBase64 = imageData[0]; const fs = await import("fs"); fs.writeFileSync("gift-basket.png", Buffer.from(imageBase64, "base64")); } else { console.log(response.output.content); } Image API Edit an image python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 import base64 from openai import OpenAI client = OpenAI() prompt = """ Generate a photorealistic image of a gift basket on a white background labeled 'Relax & Unwind' with a ribbon and handwriting-like font, containing all the items in the reference pictures. """ result = client.images.edit( model="gpt-image-1", image=[ open("body-lotion.png", "rb"), open("bath-bomb.png", "rb"), open("incense-kit.png", "rb"), open("soap.png", "rb"), ], prompt=prompt ) image_base64 = result.data[0].b64_json image_bytes = base64.b64decode(image_base64) # Save the image to a file with open("gift-basket.png", "wb") as f: f.write(image_bytes) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 import fs from "fs"; import OpenAI, { toFile } from "openai"; const client = new OpenAI(); const prompt = ` Generate a photorealistic image of a gift basket on a white background labeled 'Relax & Unwind' with a ribbon and handwriting-like font, containing all the items in the reference pictures. `; const imageFiles = [ "bath-bomb.png", "body-lotion.png", "incense-kit.png", "soap.png", ]; const images = await Promise.all( imageFiles.map(async (file) => await toFile(fs.createReadStream(file), null, { type: "image/png", }) ), ); const response = await client.images.edit({ model: "gpt-image-1", image: images, prompt, }); // Save the image to a file const image_base64 = response.data[0].b64_json; const image_bytes = Buffer.from(image_base64, "base64"); fs.writeFileSync("basket.png", image_bytes); 1 2 3 4 5 6 7 8 9 10 curl -s -D >(grep -i x-request-id >&2) \ -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) \ -X POST "https://api.openai.com/v1/images/edits" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -F "model=gpt-image-1" \ -F "image[]=@body-lotion.png" \ -F "image[]=@bath-bomb.png" \ -F "image[]=@incense-kit.png" \ -F "image[]=@soap.png" \ -F 'prompt=Generate a photorealistic image of a gift basket on a white background labeled "Relax & Unwind" with a ribbon and handwriting-like font, containing all the items in the reference pictures' ### Edit an image using a mask (inpainting) You can provide a mask to indicate which part of the image should be edited. When using a mask with GPT Image, additional instructions are sent to the model to help guide the editing process accordingly. Unlike with DALL·E 2, masking with GPT Image is entirely prompt-based. This means the model uses the mask as guidance, but may not follow its exact shape with complete precision. If you provide multiple input images, the mask will be applied to the first image. Responses API Image API Responses API Edit an image with a mask python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 from openai import OpenAI client = OpenAI() fileId = create_file("sunlit_lounge.png") maskId = create_file("mask.png") response = client.responses.create( model="gpt-4o", input=[ { "role": "user", "content": [ { "type": "input_text", "text": "generate an image of the same sunlit indoor lounge area with a pool but the pool should contain a flamingo", }, { "type": "input_image", "file_id": fileId, } ], }, ], tools=[ { "type": "image_generation", "quality": "high", "input_image_mask": { "file_id": maskId, } }, ], ) image_data = [ output.result for output in response.output if output.type == "image_generation_call" ] if image_data: image_base64 = image_data[0] with open("lounge.png", "wb") as f: f.write(base64.b64decode(image_base64)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 import OpenAI from "openai"; const openai = new OpenAI(); const fileId = await createFile("sunlit_lounge.png"); const maskId = await createFile("mask.png"); const response = await openai.responses.create({ model: "gpt-4o", input: [ { role: "user", content: [ { type: "input_text", text: "generate an image of the same sunlit indoor lounge area with a pool but the pool should contain a flamingo", }, { type: "input_image", file_id: fileId, } ], }, ], tools: [ { type: "image_generation", quality: "high", input_image_mask: { file_id: maskId, } }, ], }); const imageData = response.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData.length > 0) { const imageBase64 = imageData[0]; const fs = await import("fs"); fs.writeFileSync("lounge.png", Buffer.from(imageBase64, "base64")); } Image API Edit an image with a mask python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 from openai import OpenAI client = OpenAI() result = client.images.edit( model="gpt-image-1", image=open("sunlit_lounge.png", "rb"), mask=open("mask.png", "rb"), prompt="A sunlit indoor lounge area with a pool containing a flamingo" ) image_base64 = result.data[0].b64_json image_bytes = base64.b64decode(image_base64) # Save the image to a file with open("composition.png", "wb") as f: f.write(image_bytes) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import fs from "fs"; import OpenAI, { toFile } from "openai"; const client = new OpenAI(); const rsp = await client.images.edit({ model: "gpt-image-1", image: await toFile(fs.createReadStream("sunlit_lounge.png"), null, { type: "image/png", }), mask: await toFile(fs.createReadStream("mask.png"), null, { type: "image/png", }), prompt: "A sunlit indoor lounge area with a pool containing a flamingo", }); // Save the image to a file const image_base64 = rsp.data[0].b64_json; const image_bytes = Buffer.from(image_base64, "base64"); fs.writeFileSync("lounge.png", image_bytes); 1 2 3 4 5 6 7 8 curl -s -D >(grep -i x-request-id >&2) \ -o >(jq -r '.data[0].b64_json' | base64 --decode > lounge.png) \ -X POST "https://api.openai.com/v1/images/edits" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -F "model=gpt-image-1" \ -F "mask=@mask.png" \ -F "image[]=@sunlit_lounge.png" \ -F 'prompt=A sunlit indoor lounge area with a pool containing a flamingo' | Image | Mask | Output | | --- | --- | --- | | Image 41: A pink room with a pool | Image 42: A mask in part of the pool | Image 43: The original pool with an inflatable flamigo replacing the mask | Prompt: a sunlit indoor lounge area with a pool containing a flamingo #### Mask requirements The image to edit and mask must be of the same format and size (less than 50MB in size). The mask image must also contain an alpha channel. If you’re using an image editing tool to create the mask, make sure to save the mask with an alpha channel. Add an alpha channel to a black and white mask You can modify a black and white image programmatically to add an alpha channel. Add an alpha channel to a black and white mask python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 from PIL import Image from io import BytesIO # 1. Load your black & white mask as a grayscale image mask = Image.open(img_path_mask).convert("L") # 2. Convert it to RGBA so it has space for an alpha channel mask_rgba = mask.convert("RGBA") # 3. Then use the mask itself to fill that alpha channel mask_rgba.putalpha(mask) # 4. Convert the mask into bytes buf = BytesIO() mask_rgba.save(buf, format="PNG") mask_bytes = buf.getvalue() # 5. Save the resulting file img_path_mask_alpha = "mask_alpha.png" with open(img_path_mask_alpha, "wb") as f: f.write(mask_bytes) The Image Edits (https://platform.openai.com/api/docs/api-reference/images/createEdit) endpoint lets you edit parts of an image by uploading an image and mask indicating which areas should be replaced. This process is also known as inpainting. You can provide a mask to indicate where the image should be edited. The transparent areas of the mask will be replaced, while the filled areas will be left unchanged. You should use the prompt to describe the full new image, not just the erased area. Edit an image python 1 2 3 4 5 6 7 8 9 10 11 import OpenAI from "openai"; const openai = new OpenAI(); const result = await openai.images.generate({ model: "dall-e-2", prompt: "a white siamese cat", n: 1, size: "1024x1024", }); console.log(result.data[0].url); 1 2 3 4 5 6 7 8 9 10 11 12 13 from openai import OpenAI client = OpenAI() result = client.images.edit( model="dall-e-2", image=open("sunlit_lounge.png", "rb"), mask=open("mask.png", "rb"), prompt="A sunlit indoor lounge area with a pool containing a flamingo", n=1, size="1024x1024", ) print(result.data[0].url) 1 2 3 4 5 6 7 8 curl https://api.openai.com/v1/images/edits \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -F model="dall-e-2" \ -F image="@sunlit_lounge.png" \ -F mask="@mask.png" \ -F prompt="A sunlit indoor lounge area with a pool containing a flamingo" \ -F n=1 \ -F size="1024x1024" | Image | Mask | Output | | --- | --- | --- | | Image 44: A pink room with a pool | Image 45: A mask in part of the pool | Image 46: The original pool with an inflatable flamigo replacing the mask | Prompt: a sunlit indoor lounge area with a pool containing a flamingo #### Mask requirements The mask must be a square PNG image and less than 4MB in size. The mask image must also contain an alpha channel. If you’re using an image editing tool to create the mask, make sure to save the mask with an alpha channel. Add an alpha channel to a black and white mask You can modify a black and white image programmatically to add an alpha channel. Add an alpha channel to a black and white mask python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 from PIL import Image from io import BytesIO # 1. Load your black & white mask as a grayscale image mask = Image.open(img_path_mask).convert("L") # 2. Convert it to RGBA so it has space for an alpha channel mask_rgba = mask.convert("RGBA") # 3. Then use the mask itself to fill that alpha channel mask_rgba.putalpha(mask) # 4. Convert the mask into bytes buf = BytesIO() mask_rgba.save(buf, format="PNG") mask_bytes = buf.getvalue() # 5. Save the resulting file img_path_mask_alpha = "mask_alpha.png" with open(img_path_mask_alpha, "wb") as f: f.write(mask_bytes) The Image Edits endpoint is not available for DALL·E 3. If you would like to edit images, we recommend using our newest model, GPT Image (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image). ### Image Variations Available for DALL·E 2 only, the image variations (https://platform.openai.com/api/docs/api-reference/images/createVariation) endpoint allows you to generate a variation of a given image. Generate an image variation python 1 2 3 4 5 6 7 8 9 10 11 import OpenAI from "openai"; const openai = new OpenAI(); const result = await openai.images.createVariation({ model: "dall-e-2", image: fs.createReadStream("corgi_and_cat_paw.png"), n: 1, size: "1024x1024" }); console.log(result.data[0].url); 1 2 3 4 5 6 7 8 9 10 11 from openai import OpenAI client = OpenAI() result = client.images.create_variation( model="dall-e-2", image=open("corgi_and_cat_paw.png", "rb"), n=1, size="1024x1024" ) print(result.data[0].url) 1 2 3 4 5 6 curl https://api.openai.com/v1/images/variations \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -F model="dall-e-2" \ -F image="@corgi_and_cat_paw.png" \ -F n=1 \ -F size="1024x1024" | Image | Output | | --- | --- | | Image 47: A cat and a dog | Image 48: A similar cat and dog | Similar to the edits endpoint, the input image must be a square PNG image less than 4MB in size. ### Input fidelity GPT Image models (gpt-image-1.5, gpt-image-1, and gpt-image-1-mini) support high input fidelity, which allows you to better preserve details from the input images in the output. This is especially useful when using images that contain elements like faces or logos that require accurate preservation in the generated image. You can provide multiple input images that will all be preserved with high fidelity, but keep in mind that if using gpt-image-1 or gpt-image-1-mini, the first image will be preserved with richer textures and finer details, so if you include elements such as faces, consider placing them in the first image. If you are using gpt-image-1.5, the first 5 input images will be preserved with higher fidelity. To enable high input fidelity, set the input_fidelity parameter to high. The default value is low. Responses API Image API Responses API Generate an image with high input fidelity python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import fs from "fs"; import OpenAI from "openai"; const openai = new OpenAI(); const response = await openai.responses.create({ model: "gpt-4.1", input: [ { role: "user", content: [ { type: "input_text", text: "Add the logo to the woman's top, as if stamped into the fabric." }, { type: "input_image", image_url: "https://cdn.openai.com/API/docs/images/woman_futuristic.jpg", }, { type: "input_image", image_url: "https://cdn.openai.com/API/docs/images/brain_logo.png", }, ], }, ], tools: [{type: "image_generation", input_fidelity: "high", action: "edit"}], }); // Extract the edited image const imageBase64 = response.output.find( (o) => o.type === "image_generation_call" )?.result; if (imageBase64) { const imageBuffer = Buffer.from(imageBase64, "base64"); fs.writeFileSync("woman_with_logo.png", imageBuffer); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 from openai import OpenAI import base64 client = OpenAI() response = client.responses.create( model="gpt-4.1", input=[ { "role": "user", "content": [ {"type": "input_text", "text": "Add the logo to the woman's top, as if stamped into the fabric."}, { "type": "input_image", "image_url": "https://cdn.openai.com/API/docs/images/woman_futuristic.jpg", }, { "type": "input_image", "image_url": "https://cdn.openai.com/API/docs/images/brain_logo.png", }, ], } ], tools=[{"type": "image_generation", "input_fidelity": "high", "action": "edit"}], ) # Extract the edited image image_data = [ output.result for output in response.output if output.type == "image_generation_call" ] if image_data: image_base64 = image_data[0] with open("woman_with_logo.png", "wb") as f: f.write(base64.b64decode(image_base64)) Image API Generate an image with high input fidelity python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import fs from "fs"; import OpenAI from "openai"; const openai = new OpenAI(); const prompt = "Add the logo to the woman's top, as if stamped into the fabric."; const result = await openai.images.edit({ model: "gpt-image-1", image: [ fs.createReadStream("woman.jpg"), fs.createReadStream("logo.png") ], prompt, input_fidelity: "high" }); // Save the image to a file const image_base64 = result.data[0].b64_json; const image_bytes = Buffer.from(image_base64, "base64"); fs.writeFileSync("woman_with_logo.png", image_bytes); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from openai import OpenAI import base64 client = OpenAI() result = client.images.edit( model="gpt-image-1", image=[open("woman.jpg", "rb"), open("logo.png", "rb")], prompt="Add the logo to the woman's top, as if stamped into the fabric.", input_fidelity="high" ) image_base64 = result.data[0].b64_json image_bytes = base64.b64decode(image_base64) # Save the image to a file with open("woman_with_logo.png", "wb") as f: f.write(image_bytes) | Input 1 | Input 2 | Output | | --- | --- | --- | | Image 49: A woman | Image 50: A brain logo | Image 51: The woman with a brain logo on her top | Prompt: Add the logo to the woman’s top, as if stamped into the fabric. Keep in mind that when using high input fidelity, more image input tokens will be used per request. To understand the costs implications, refer to our vision costs (https://platform.openai.com/api/docs/guides/images-vision?api-mode=responses#calculating-costs) section. Customize Image Output ---------------------- You can configure the following output options: - Size: Image dimensions (e.g., 1024x1024, 1024x1536) - Quality: Rendering quality (e.g. low, medium, high) - Format: File output format - Compression: Compression level (0-100%) for JPEG and WebP formats - Background: Transparent or opaque size, quality, and background support the auto option, where the model will automatically select the best option based on the prompt. - Size: Image dimensions (e.g., 1024x1024, 1024x1536) - Quality: Rendering quality (e.g. standard) - Format: url (default), b64_json - Size: Image dimensions (e.g., 1024x1024, 1024x1536) - Quality: Rendering quality (e.g. standard) - Format: url (default), b64_json ### Size and quality options Square images with standard quality are the fastest to generate. The default size is 1024x1024 pixels. Available sizes* 1024x1024 (square) - 1536x1024 (landscape) - 1024x1536 (portrait) - auto (default) Quality options- low - medium - high - auto (default) Available sizes- 256x256 - 512x512 - 1024x1024 (default) Quality options- standard (default) Available sizes* 1024x1024 (square) - 1024x1792 (portrait) - 1792x1024 (landscape) - auto (default) Quality options- standard (default) - hd ### Output format The Image API returns base64-encoded image data. The default format is png, but you can also request jpeg or webp. If using jpeg or webp, you can also specify the output_compression parameter to control the compression level (0-100%). For example, output_compression=50 will compress the image by 50%. Using jpeg is faster than png, so you should prioritize this format if latency is a concern. The default Image API output when using DALL·E 2 is a url pointing to the hosted image. You can also request the response_format as b64_json for a base64-encoded image. The default Image API output when using DALL·E 3 is a url pointing to the hosted image. You can also request the response_format as b64_json for a base64-encoded image. ### Transparency GPT Image models (gpt-image-1.5, gpt-image-1, and gpt-image-1-mini) support transparent backgrounds. To enable transparency, set the background parameter to transparent. It is only supported with the png and webp output formats. Transparency works best when setting the quality to medium or high. Responses API Image API Responses API Generate an image with a transparent background python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 import openai import base64 response = openai.responses.create( model="gpt-5", input="Draw a 2D pixel art style sprite sheet of a tabby gray cat", tools=[ { "type": "image_generation", "background": "transparent", "quality": "high", } ], ) image_data = [ output.result for output in response.output if output.type == "image_generation_call" ] if image_data: image_base64 = image_data[0] with open("sprite.png", "wb") as f: f.write(base64.b64decode(image_base64)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 import fs from "fs"; import OpenAI from "openai"; const client = new OpenAI(); const response = await client.responses.create({ model: "gpt-5", input: "Draw a 2D pixel art style sprite sheet of a tabby gray cat", tools: [ { type: "image_generation", background: "transparent", quality: "high", }, ], }); const imageData = response.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result); if (imageData.length > 0) { const imageBase64 = imageData[0]; const imageBuffer = Buffer.from(imageBase64, "base64"); fs.writeFileSync("sprite.png", imageBuffer); } Image API Generate an image with a transparent background python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import OpenAI from "openai"; import fs from "fs"; const openai = new OpenAI(); const result = await openai.images.generate({ model: "gpt-image-1", prompt: "Draw a 2D pixel art style sprite sheet of a tabby gray cat", size: "1024x1024", background: "transparent", quality: "high", }); // Save the image to a file const image_base64 = result.data[0].b64_json; const image_bytes = Buffer.from(image_base64, "base64"); fs.writeFileSync("sprite.png", image_bytes); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from openai import OpenAI import base64 client = OpenAI() result = client.images.generate( model="gpt-image-1", prompt="Draw a 2D pixel art style sprite sheet of a tabby gray cat", size="1024x1024", background="transparent", quality="high", ) image_base64 = result.json()["data"][0]["b64_json"] image_bytes = base64.b64decode(image_base64) # Save the image to a file with open("sprite.png", "wb") as f: f.write(image_bytes) 1 2 3 4 5 6 7 8 9 curl -X POST "https://api.openai.com/v1/images" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-type: application/json" \ -d '{ "prompt": "Draw a 2D pixel art style sprite sheet of a tabby gray cat", "quality": "high", "size": "1024x1024", "background": "transparent" }' | jq -r 'data[0].b64_json' | base64 --decode > sprite.png Limitations ----------- GPT Image models (gpt-image-1.5, gpt-image-1, and gpt-image-1-mini) are powerful and versatile image generation models, but they still have some limitations to be aware of: - Latency: Complex prompts may take up to 2 minutes to process. - Text Rendering: Although significantly improved over the DALL·E series, the model can still struggle with precise text placement and clarity. - Consistency: While capable of producing consistent imagery, the model may occasionally struggle to maintain visual consistency for recurring characters or brand elements across multiple generations. - Composition Control: Despite improved instruction following, the model may have difficulty placing elements precisely in structured or layout-sensitive compositions. ### Content Moderation All prompts and generated images are filtered in accordance with our content policy (https://openai.com/policies/usage-policies/). For image generation using GPT Image models (gpt-image-1.5, gpt-image-1, and gpt-image-1-mini), you can control moderation strictness with the moderation parameter. This parameter supports two values: - auto (default): Standard filtering that seeks to limit creating certain categories of potentially age-inappropriate content. - low: Less restrictive filtering. ### Supported models When using image generation in the Responses API, most modern models starting with gpt-4o and newer should support the image generation tool. Check the model detail page for your model (https://platform.openai.com/api/docs/models) to confirm if your desired model can use the image generation tool. DALL·E 2 is our first image generation model and therefore has significant limitations: - Text Rendering: The model struggles with rendering legible text. - Instruction Following: The model has trouble following instructions. - Realism: The model is not able to generate realistic images. For a better experience, we recommend using GPT Image (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image) for image generation. DALL·E 3 is an improvement over DALL·E 2 but still has some limitations: - Text Rendering: The model struggles with rendering legible text. - Instruction Following: The model has trouble following precise instructions. - Photorealism: The model is not able to generate highly photorealistic images. For a better experience, we recommend using GPT Image (https://platform.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image) for image generation. Cost and latency ---------------- This model generates images by first producing specialized image tokens. Both latency and eventual cost are proportional to the number of tokens required to render an image—larger image sizes and higher quality settings result in more tokens. The number of tokens generated depends on image dimensions and quality: | Quality | Square (1024×1024) | Portrait (1024×1536) | Landscape (1536×1024) | | --- | --- | --- | --- | | Low | 272 tokens | 408 tokens | 400 tokens | | Medium | 1056 tokens | 1584 tokens | 1568 tokens | | High | 4160 tokens | 6240 tokens | 6208 tokens | Note that you will also need to account for input tokens (https://platform.openai.com/api/docs/guides/images-vision?api-mode=responses#calculating-costs): text tokens for the prompt and image tokens for the input images if editing images. If you are using high input fidelity, the number of input tokens will be higher. Refer to our pricing page (https://platform.openai.com/api/docs/pricing#image-generation) for more information about price per text and image tokens. So the final cost is the sum of: - input text tokens - input image tokens if using the edits endpoint - image output tokens ### Partial images cost If you want to stream image generation (https://platform.openai.com/docs/guides/image-generation#streaming) using the partial_images parameter, each partial image will incur an additional 100 image output tokens. Cost for DALL·E 2 is fixed can be calculated by image generated depending on the size. You can find the pricing details on the pricing page (https://platform.openai.com/api/docs/pricing#image-generation). Cost for DALL·E 3 is fixed can be calculated by image generated depending on the size and image quality. You can find the pricing details on the pricing page (https://platform.openai.com/api/docs/pricing#image-generation).