🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat: add gpt-image-2 to LobeHub-hosted card (#14039)
YuTengjing16f2b97de219
diff --git a/locales/en-US/home.json b/locales/en-US/home.jsonindex 8c9962b0689..8c26595f358 100644--- a/locales/en-US/home.json+++ b/locales/en-US/home.json@@ -10,7 +10,7 @@"starter.deepResearch": "Deep Research","starter.developing": "Coming soon","starter.image": "Image",- "starter.imageGeneration": "Image Generation",+ "starter.imageGeneration": "GPT Image 2","starter.videoGeneration": "Seedance 2.0","starter.write": "Write"}diff --git a/locales/zh-CN/home.json b/locales/zh-CN/home.jsonindex bea7d229115..665bb1de0b6 100644--- a/locales/zh-CN/home.json+++ b/locales/zh-CN/home.json@@ -10,7 +10,7 @@"starter.deepResearch": "探究","starter.developing": "正在开发中","starter.image": "绘画",- "starter.imageGeneration": "图像生成",+ "starter.imageGeneration": "GPT Image 2","starter.videoGeneration": "Seedance 2.0","starter.write": "写作"}diff --git a/packages/model-bank/src/aiModels/lobehub/image.ts b/packages/model-bank/src/aiModels/lobehub/image.tsindex f308a24351b..901183f2aed 100644--- a/packages/model-bank/src/aiModels/lobehub/image.ts+++ b/packages/model-bank/src/aiModels/lobehub/image.ts@@ -2,6 +2,7 @@ import type { AIImageModelCard } from '../../types/aiModel';import { huanyuanImageParamsSchema, qwenEditParamsSchema, qwenImageParamsSchema } from '../fal';import {gptImage1Schema,+ gptImage2Schema,imagenBaseParameters,nanoBanana2Parameters,nanoBananaParameters,@@ -99,6 +100,28 @@ export const lobehubImageModels: AIImageModelCard[] = [releasedAt: '2025-08-15',type: 'image',},+ {+ description:+ "OpenAI's next-generation multimodal image model with native reasoning, up to 4K resolution, near-perfect text rendering, and high-fidelity multilingual support.",+ displayName: 'GPT Image 2',+ enabled: true,+ id: 'gpt-image-2',+ parameters: gptImage2Schema,+ pricing: {+ // Medium quality at 1024x1024: ~1767 output tokens * $30/M = $0.053 per image.+ // Source: https://developers.openai.com/api/docs/guides/image-generation#calculating-costs+ approximatePricePerImage: 0.053,+ units: [+ { name: 'textInput', rate: 5, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textInput_cacheRead', rate: 1.25, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'imageInput', rate: 8, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'imageInput_cacheRead', rate: 2, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'imageOutput', rate: 30, strategy: 'fixed', unit: 'millionTokens' },+ ],+ },+ releasedAt: '2026-04-21',+ type: 'image',+ },{description:'An enhanced GPT Image 1 model with 4× faster generation, more precise editing, and improved text rendering.',diff --git a/packages/model-bank/src/aiModels/lobehub/utils.ts b/packages/model-bank/src/aiModels/lobehub/utils.tsindex b11be6e5ca7..0f2c8ab5773 100644--- a/packages/model-bank/src/aiModels/lobehub/utils.ts+++ b/packages/model-bank/src/aiModels/lobehub/utils.ts@@ -73,10 +73,32 @@ export const nanoBanana2Parameters: ModelParamsSchema = {};export const gptImage1Schema = {- imageUrls: { default: [], maxCount: 1, maxFileSize: 5 },+ imageUrls: { default: [], maxCount: 1, maxFileSize: 5 * 1024 * 1024 },prompt: { default: '' },size: {default: 'auto',enum: ['auto', '1024x1024', '1536x1024', '1024x1536'],},};++// gpt-image-2 accepts any resolution satisfying: max edge ≤ 3840px, both edges+// multiples of 16px, aspect ratio ≤ 3:1, pixels between 655,360 and 8,294,400.+// Until the schema/UI supports free-form W×H input, we expose the official+// "Popular sizes" list from https://developers.openai.com/docs/guides/image-generation.+export const gptImage2Schema = {+ imageUrls: { default: [], maxCount: 1, maxFileSize: 5 * 1024 * 1024 },+ prompt: { default: '' },+ size: {+ default: 'auto',+ enum: [+ 'auto',+ '1024x1024',+ '1536x1024',+ '1024x1536',+ '2048x2048',+ '2048x1152',+ '3840x2160',+ '2160x3840',+ ],+ },+};diff --git a/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.ts b/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.tsindex 9ff6c137748..df7315ee419 100644--- a/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.ts+++ b/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.ts@@ -54,7 +54,7 @@ async function generateByImageMode(// According to official docs, if there are multiple images, pass an array; if only one, pass a single FileuserInput.image = imageFiles.length === 1 ? imageFiles[0] : imageFiles;} catch (error) {- throw new Error(`Failed to convert image URLs to File objects: ${error}`);+ throw new Error(`Failed to convert image URLs to File objects: ${error}`, { cause: error });}} else {delete userInput.image;@@ -64,13 +64,18 @@ async function generateByImageMode(delete userInput.size;}+ // gpt-image-2 dropped input_fidelity ("output is already high fidelity by default").+ // https://developers.openai.com/cookbook/examples/multimodal/image-gen-models-prompting-guide+ // Match the gpt-image-1 family (including dated snapshots like+ // `gpt-image-1-2025-04-15` and the `.5` variant), but exclude the mini tier.+ const isGptImage1Family = /^gpt-image-1(?:$|[-.])/.test(model);+ const supportsInputFidelity = isImageEdit && isGptImage1Family && !model.includes('mini');+const defaultInput = {n: 1,...(model.includes('dall-e') ? { response_format: 'b64_json' } : {}),// https://platform.openai.com/docs/api-reference/images/createEdit#images_createedit-input_fidelity- ...(isImageEdit && model.includes('gpt-image-') && !model.includes('mini')- ? { input_fidelity: 'high' }- : {}),+ ...(supportsInputFidelity ? { input_fidelity: 'high' } : {}),};const options = cleanObject({@@ -180,7 +185,7 @@ async function generateByChatModel(});log('Successfully processed image URL for chat input');} catch (error) {- throw new Error(`Failed to process image URL: ${error}`);+ throw new Error(`Failed to process image URL: ${error}`, { cause: error });}}diff --git a/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts b/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.tsindex 18e81fb3433..dcbf8660e93 100644--- a/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts+++ b/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts@@ -1530,6 +1530,61 @@ describe('LobeOpenAICompatibleFactory', () => {imageUrl: 'data:image/png;base64,gpt-image-edited-base64',});});++ it('should NOT send input_fidelity for gpt-image-2 (unsupported param)', async () => {+ const mockResponse = {+ data: [{ b64_json: 'gpt-image-2-edited-base64' }],+ };++ const mockFile = new File(['content'], 'test-image.jpg', { type: 'image/jpeg' });++ vi.mocked(openaiHelpers.convertImageUrlToFile).mockResolvedValue(mockFile);+ vi.spyOn(instance['client'].images, 'edit').mockResolvedValue(mockResponse as any);++ const payload = {+ model: 'gpt-image-2',+ params: {+ imageUrl: 'https://example.com/image.jpg',+ prompt: 'Edit this image with gpt-image-2',+ },+ };++ await (instance as any).createImage(payload);++ const editArgs = vi.mocked(instance['client'].images.edit).mock.calls[0][0];+ expect(editArgs).not.toHaveProperty('input_fidelity');+ expect(editArgs).toMatchObject({+ model: 'gpt-image-2',+ n: 1,+ });+ });++ it.each([+ ['gpt-image-1.5', true],+ ['gpt-image-1-2026-01-15', true], // dated snapshot alias+ ['gpt-image-1.5-2026-03-01', true], // dated snapshot alias for the .5 variant+ ['gpt-image-1-mini', false], // mini tier explicitly excluded+ ['gpt-image-2', false], // gpt-image-2 dropped the param+ ['gpt-image-2-2026-04-21', false], // gpt-image-2 snapshot alias+ ])('should %s include input_fidelity for %s', async (model, shouldInclude) => {+ const mockResponse = { data: [{ b64_json: 'edited' }] };+ const mockFile = new File(['content'], 'test.jpg', { type: 'image/jpeg' });++ vi.mocked(openaiHelpers.convertImageUrlToFile).mockResolvedValue(mockFile);+ vi.spyOn(instance['client'].images, 'edit').mockResolvedValue(mockResponse as any);++ await (instance as any).createImage({+ model,+ params: { imageUrl: 'https://example.com/image.jpg', prompt: 'Edit' },+ });++ const editArgs = vi.mocked(instance['client'].images.edit).mock.calls[0][0];+ if (shouldInclude) {+ expect(editArgs).toMatchObject({ input_fidelity: 'high' });+ } else {+ expect(editArgs).not.toHaveProperty('input_fidelity');+ }+ });});describe('error handling', () => {diff --git a/src/locales/default/home.ts b/src/locales/default/home.tsindex b8dfb802fa0..b467c83555e 100644--- a/src/locales/default/home.ts+++ b/src/locales/default/home.ts@@ -11,7 +11,7 @@ export default {'starter.deepResearch': 'Deep Research','starter.developing': 'Coming soon','starter.image': 'Image',- 'starter.imageGeneration': 'Image Generation',+ 'starter.imageGeneration': 'GPT Image 2','starter.videoGeneration': 'Seedance 2.0','starter.write': 'Write',};diff --git a/src/routes/(main)/home/features/InputArea/StarterList.tsx b/src/routes/(main)/home/features/InputArea/StarterList.tsxindex 1797079857f..857e2a90add 100644--- a/src/routes/(main)/home/features/InputArea/StarterList.tsx+++ b/src/routes/(main)/home/features/InputArea/StarterList.tsx@@ -1,9 +1,10 @@import { BUILTIN_AGENT_SLUGS } from '@lobechat/builtin-agents';+import { Jimeng } from '@lobehub/icons';import { type ButtonProps } from '@lobehub/ui';import { Button, Center, Tooltip } from '@lobehub/ui';import { GroupBotSquareIcon } from '@lobehub/ui/icons';import { createStaticStyles, cssVar, cx } from 'antd-style';-import { BotIcon, ImageIcon, PenLineIcon, VideoIcon } from 'lucide-react';+import { BotIcon, ImageIcon, PenLineIcon } from 'lucide-react';import { memo, useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -77,13 +78,14 @@ const StarterList = memo(() => {titleKey: 'starter.write',},{+ hot: true,icon: ImageIcon,key: 'image',titleKey: 'starter.imageGeneration',},{hot: true,- icon: VideoIcon,+ icon: Jimeng.Color,key: 'video',titleKey: 'starter.videoGeneration',},@@ -105,7 +107,7 @@ const StarterList = memo(() => {}if (key === 'image') {- navigate('/image');+ navigate('/image?model=gpt-image-2');return;}