Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

Merge PR #358: default image generation to gpt-image-2

Leggett909b34bbd29c
diff --cc apps/daemon/src/codex/local-provider.ts
index cd7599be,5d1f2013..8a2593ba
--- a/apps/daemon/src/codex/local-provider.ts
+++ b/apps/daemon/src/codex/local-provider.ts
@@@ -1,4 -1,4 +1,5 @@@
import { parse } from '@iarna/toml';
++import { migrateOpenAiImageModel } from '@opencreator/protocol';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
@@@ -116,7 -116,7 +117,7 @@@ async function readJson(path: string, s
}
function imageModel(textModel: string): string {
- return /^gpt-image-/i.test(textModel) ? textModel : 'gpt-image-1';
- return /^gpt-image-/i.test(textModel) ? textModel : 'gpt-image-2';
++ return /^gpt-image-/i.test(textModel) ? migrateOpenAiImageModel(textModel) : 'gpt-image-2';
}
function readRecord(value: unknown): Record<string, TomlValue> | undefined {
diff --cc apps/daemon/src/creator-services/config-store.ts
index b108ceb2,b108ceb2..6618809f
--- a/apps/daemon/src/creator-services/config-store.ts
+++ b/apps/daemon/src/creator-services/config-store.ts
@@@ -3,7 -3,7 +3,7 @@@ import type
CreatorServicesConfigResponse,
CreatorServicesCredentialField
} from '@opencreator/protocol';
--import { createDefaultCreatorServicesConfig } from '@opencreator/protocol';
++import { createDefaultCreatorServicesConfig, migrateOpenAiImageModel } from '@opencreator/protocol';
import { z } from 'zod';
import {
readOpenCreatorConfig,
@@@ -66,6 -66,6 +66,9 @@@ const volcengineAsrSchema = z.object(
baseUrl: boundedString(2048)
}).strict();
const creatorServicesDefaults = createDefaultCreatorServicesConfig();
++const openAiImageSchema = openAiCompatibleSchema.extend({
++ model: boundedString(128).transform(migrateOpenAiImageModel)
++}).strict();
const imageConfigDefault = creatorServicesDefaults.image;
const videoConfigDefault = creatorServicesDefaults.video;
const llmConfigSchema = openAiCompatibleSchema.extend({
@@@ -77,7 -77,7 +80,7 @@@
}));
const imageConfigSchema = z.object({
provider: z.enum(['openai', 'jimeng', 'kling', 'gemini', 'codex-native']),
-- openai: openAiCompatibleSchema,
++ openai: openAiImageSchema,
jimeng: openAiCompatibleSchema,
kling: klingAiSchema,
gemini: openAiCompatibleSchema,
@@@ -85,7 -85,7 +88,7 @@@
}).strict();
const legacyImageConfigSchema = z.object({
provider: z.literal('openai-compatible'),
-- openai: openAiCompatibleSchema
++ openai: openAiImageSchema
}).strict().transform(value => ({
...structuredClone(imageConfigDefault),
provider: 'openai' as const,
diff --cc apps/daemon/src/gateway/model-access.ts
index f6b26308,f6b26308..0f887b1c
--- a/apps/daemon/src/gateway/model-access.ts
+++ b/apps/daemon/src/gateway/model-access.ts
@@@ -2,7 -2,7 +2,7 @@@ import { createHash } from 'node:crypto
import { isIP } from 'node:net';
import { join } from 'node:path';
import { z } from 'zod';
--import { gatewayModelOperations, gatewayModelCompatible, gatewayModelReady, type GatewayModel, type GatewayModelAvailability, type GatewayModelOperation, type PublicErrorFacts } from '@opencreator/protocol';
++import { gatewayModelOperations, gatewayModelCompatible, gatewayModelReady, isRetiredOpenAiImageModel, type GatewayModel, type GatewayModelAvailability, type GatewayModelOperation, type PublicErrorFacts } from '@opencreator/protocol';
import { readPrivateJsonFile, writePrivateJsonFile } from '../config/private-json-file.js';
import { catalogSchema, type GatewayBootstrap } from './client.js';
import { imageModelsSchema, officialCatalogModels, openRouterModelSchema, videoModelsSchema } from './openrouter-model-catalog.js';
@@@ -45,6 -45,6 +45,7 @@@ export function officialModelPolicy(mod
// Account catalog availability does not override OpenCreator's adapter compatibility.
return models.filter(model => model.vendor?.toLowerCase() !== 'anthropic' && !/^claude-/i.test(model.id) && modelAccessGroup(model) !== 'anthropic'
&& !model.id.endsWith(':batch')
++ && !(model.modality === 'image' && isRetiredOpenAiImageModel(model.id))
&& !(model.modality === 'text' && modelAccessGroup(model) === 'openrouter'));
}
diff --cc apps/daemon/src/gateway/model-preferences.ts
index 0ca51b18,0ca51b18..73cb90b1
--- a/apps/daemon/src/gateway/model-preferences.ts
+++ b/apps/daemon/src/gateway/model-preferences.ts
@@@ -1,4 -1,4 +1,4 @@@
--import { gatewayModelCompatible, gatewayModelReady, gatewayModelSupports, type GatewayModel, type GatewayModelPurpose } from '@opencreator/protocol';
++import { gatewayModelCompatible, gatewayModelReady, gatewayModelSupports, migrateOpenAiImageModel, type GatewayModel, type GatewayModelPurpose } from '@opencreator/protocol';
export const modelModalities: GatewayModelPurpose[] = ['text', 'image', 'video', 'speech', 'transcription'];
const historicalDefaults: Record<string, string[]> = {
@@@ -27,7 -27,7 +27,8 @@@ export function resolveModelPreferences
let changed = false;
for (const modality of modelModalities) {
const candidates = compatible.filter(model => gatewayModelSupports(model, modality) && gatewayModelReady(model));
-- const automatic = candidates.find(model => model.id === defaults[modality]) ?? candidates.find(model => model.recommended);
++ const defaultId = modality === 'image' ? migrateOpenAiImageModel(defaults[modality] ?? '') : defaults[modality];
++ const automatic = candidates.find(model => model.id === defaultId) ?? candidates.find(model => model.recommended);
if (automatic) recommended[modality] = automatic.id;
const chosen = compatible.find(model => model.modality === modality && model.id === manual[modality] && model.status !== 'retired');
if (chosen) {
diff --cc apps/daemon/src/image-generation/provider.ts
index 4ad73f24,b92a52b1..e4929a67
--- a/apps/daemon/src/image-generation/provider.ts
+++ b/apps/daemon/src/image-generation/provider.ts
@@@ -4,7 -4,7 +4,7 @@@ import type
ImageGenerationAsset
} from '@opencreator/protocol';
import type { PublicErrorFacts } from '@opencreator/protocol';
--import { imageModelOptions, imageModelPixelSize, imageSizeAspectRatio, publicErrorKindForCode, sanitizePublicErrorFacts } from '@opencreator/protocol';
++import { imageModelOptions, imageModelPixelSize, imageSizeAspectRatio, migrateOpenAiImageModel, publicErrorKindForCode, sanitizePublicErrorFacts } from '@opencreator/protocol';
import {
LocalCodexProviderError,
type LocalCodexProvider
@@@ -222,8 -222,8 +222,9 @@@ async function generateOpenAiImages
const provider = providerOverride
?? (request.provider === 'jimeng' ? config.image.jimeng : config.image.openai);
if (!provider.apiKey.trim()) missingConfig(request.provider);
-- const model = provider.model.trim()
- || (request.provider === 'jimeng' ? 'doubao-seedream-4-0-250828' : 'gpt-image-1');
++ const configuredModel = provider.model.trim()
+ || (request.provider === 'jimeng' ? 'doubao-seedream-4-0-250828' : 'gpt-image-2');
++ const model = !official && request.provider !== 'jimeng' ? migrateOpenAiImageModel(configuredModel) : configuredModel;
const parameters = official ? undefined : manualImageParameters(request, request.provider === 'codex-native' ? 'openai' : request.provider, model);
const endpoint = openAiImageEndpoint(
provider.baseUrl,
diff --cc apps/daemon/test/integration/image-generation-api.test.ts
index acc8837d,fdeff672..7cd5966d
--- a/apps/daemon/test/integration/image-generation-api.test.ts
+++ b/apps/daemon/test/integration/image-generation-api.test.ts
@@@ -49,6 -49,6 +49,22 @@@ describe('image generation API', () =>
if (model === 'gemini-2.5-flash-image') expect(body.generationConfig.imageConfig).not.toHaveProperty('imageSize');
});
++ it.each([false, true])('replaces a saved retired model in outgoing image requests (edit=%s)', async edit => {
++ const config = createDefaultCreatorServicesConfig();
++ config.image.openai = { baseUrl: 'https://images.example.test/v1', apiKey: 'test-key', model: 'gpt-image-1' };
++ const content = Buffer.from('image');
++ const fetchImpl = vi.fn(async (_url: RequestInfo | URL, _init?: RequestInit) => Response.json({ data: [{ b64_json: content.toString('base64') }] }));
++ const generated = await generateImageContents({ prompt: 'A city', provider: 'openai', size: '1024x1024', quality: 'medium', count: 1 }, config,
++ { fetchImpl, ...(edit ? { referenceImages: [{ content, mime: 'image/png' as const }] } : {}) });
++ expect(generated.model).toBe('gpt-image-2');
++ expect(String(fetchImpl.mock.calls[0]?.[0])).toBe(`https://images.example.test/v1/images/${edit ? 'edits' : 'generations'}`);
++ const body = fetchImpl.mock.calls[0]?.[1]?.body;
++ if (edit) {
++ const form = await new Request('http://localhost', { method: 'POST', headers: fetchImpl.mock.calls[0]?.[1]?.headers, body }).formData();
++ expect(form.get('model')).toBe('gpt-image-2');
++ } else expect(JSON.parse(String(body)).model).toBe('gpt-image-2');
++ });
++
it('rejects unsupported model parameters before making a paid request', async () => {
const config = createDefaultCreatorServicesConfig();
config.image.gemini.apiKey = 'test-key';
@@@ -193,7 -193,7 +209,7 @@@
expect(generated.statusCode).toBe(201);
expect(generated.json().result).toMatchObject({
provider: 'codex-native',
-- model: 'gpt-image-1',
++ model: 'gpt-image-2',
images: [{ mime: 'image/png', size: image.length }]
});
expect(String(fetchMock.mock.calls[0]?.[0]))
diff --cc apps/daemon/test/unit/codex-local-provider.test.ts
index 674654e4,f5070b08..1e379eeb
--- a/apps/daemon/test/unit/codex-local-provider.test.ts
+++ b/apps/daemon/test/unit/codex-local-provider.test.ts
@@@ -76,6 -76,6 +76,14 @@@ describe('local Codex provider', () =>
});
});
++ it('migrates a retired image model without modifying the local Codex configuration', async () => {
++ root = await codexHome(['model = "gpt-image-1"']);
++ await expect(readLocalCodexProvider({ codexHome: root, env: { OPENAI_API_KEY: 'local-key' } }))
++ .resolves.toMatchObject({ model: 'gpt-image-2', apiKey: 'local-key' });
++ await expect(readLocalCodexModelConfiguration({ codexHome: root, env: { OPENAI_API_KEY: 'local-key' } }))
++ .resolves.toMatchObject({ provider: { model: 'gpt-image-1' } });
++ });
++
it('supports provider environment keys and configured image models', async () => {
root = await codexHome([
'model = "gpt-image-2"',
diff --cc apps/daemon/test/unit/codex-native-image.test.ts
index d233bbdc,d233bbdc..500d209e
--- a/apps/daemon/test/unit/codex-native-image.test.ts
+++ b/apps/daemon/test/unit/codex-native-image.test.ts
@@@ -163,7 -163,7 +163,7 @@@ describe('Codex authentication dispatc
it('does not require a CLI or probe for the existing API path', async () => {
const checkNativeCapability = vi.fn();
-- await expect(inspectCodexImageRuntime({ codexHome: home, readProvider: async () => ({ baseUrl: 'https://images.example.test/v1', apiKey: 'api-secret', model: 'gpt-image-1' }), checkNativeCapability })).resolves.toMatchObject({ authentication: 'api_key', ready: true, executionMode: 'api' });
++ await expect(inspectCodexImageRuntime({ codexHome: home, readProvider: async () => ({ baseUrl: 'https://images.example.test/v1', apiKey: 'api-secret', model: 'gpt-image-2' }), checkNativeCapability })).resolves.toMatchObject({ authentication: 'api_key', ready: true, executionMode: 'api' });
expect(checkNativeCapability).not.toHaveBeenCalled();
});
diff --cc apps/daemon/test/unit/creator-services-config-store.test.ts
index 0f3cbcf2,0f3cbcf2..acc480a5
--- a/apps/daemon/test/unit/creator-services-config-store.test.ts
+++ b/apps/daemon/test/unit/creator-services-config-store.test.ts
@@@ -16,6 -16,6 +16,25 @@@ import
} from '../../src/creator-services/config-store.js';
describe('CreatorServicesConfigStore', () => {
++ it('migrates saved image settings and persists the replacement while retaining credentials and other models', async () => {
++ const legacy = createDefaultCreatorServicesConfig();
++ legacy.image.openai = { model: 'gpt-image-1', baseUrl: 'https://images.example.test/v1', apiKey: 'image-secret' };
++ legacy.llm.model = 'custom-text';
++ let saved = JSON.stringify(legacy);
++ const store = createCreatorServicesConfigStore({
++ getPassword: async () => saved,
++ setPassword: async value => { saved = value; },
++ deletePassword: async () => undefined
++ });
++ const loaded = await store.read();
++ expect(loaded.image.openai).toEqual({ ...legacy.image.openai, model: 'gpt-image-2' });
++ expect(loaded.llm.model).toBe('custom-text');
++ expect(legacy.image.openai.model).toBe('gpt-image-1');
++ await store.write(legacy);
++ expect(JSON.parse(saved).image.openai.model).toBe('gpt-image-2');
++ expect((await store.read()).image.openai.apiKey).toBe('image-secret');
++ });
++
it('migrates legacy OSS settings and retains a custom region and endpoint across reloads', async () => {
const legacy = createDefaultCreatorServicesConfig();
const { region: _region, endpoint: _endpoint, ...oldOss } = legacy.transcription.aliyun.oss;
@@@ -432,7 -432,7 +451,7 @@@
await expect(store.read()).resolves.toMatchObject({
image: {
provider: 'openai',
-- openai: { baseUrl: 'https://images.example.test/v1', apiKey: 'old-image-key', model: 'gpt-image-1' }
++ openai: { baseUrl: 'https://images.example.test/v1', apiKey: 'old-image-key', model: 'gpt-image-2' }
},
video: {
provider: 'seedance',
diff --cc apps/daemon/test/unit/gateway-chatanywhere.test.ts
index 11f886d5,11f886d5..21336f46
--- a/apps/daemon/test/unit/gateway-chatanywhere.test.ts
+++ b/apps/daemon/test/unit/gateway-chatanywhere.test.ts
@@@ -13,7 -13,7 +13,7 @@@ afterEach(async () => { for (const roo
const domestic = 'https://api.chatanywhere.tech/v1';
const overseas = 'https://api.chatanywhere.org/v1';
const whisper: GatewayModel = { id: 'whisper-1', modality: 'transcription', capabilities: ['transcription_text', 'subtitle_timestamps'] };
--const image: GatewayModel = { id: 'gpt-image-1', modality: 'image', capabilities: ['generate', 'edit'], imageOptions: { maxImages: 1, maxReferences: 16, aspectRatios: ['3:2'], resolutions: ['1K'] } };
++const image: GatewayModel = { id: 'gpt-image-2', modality: 'image', capabilities: ['generate', 'edit'], imageOptions: { maxImages: 1, maxReferences: 16, aspectRatios: ['3:2'], resolutions: ['1K'] } };
async function fixture(fetcher: typeof fetch, baseUrl = domestic, recover?: Parameters<typeof createDirectTransport>[2]) {
const root = await mkdtemp(join(tmpdir(), 'oc-chatanywhere-')); roots.push(root);
return { transport: createDirectTransport(root, fetcher, recover), input: { account: 'a', baseUrl, key: 'private-ca', method: 'POST', contentType: 'application/json', identity: 'one', fingerprint: 'fingerprint', signal: AbortSignal.timeout(5000) } };
diff --cc apps/daemon/test/unit/gateway-model-access.test.ts
index 834c2d8f,834c2d8f..ea971c00
--- a/apps/daemon/test/unit/gateway-model-access.test.ts
+++ b/apps/daemon/test/unit/gateway-model-access.test.ts
@@@ -44,6 -44,6 +44,11 @@@ async function fixture(models: GatewayM
setCatalogIDs(ids: string[]) { catalogIDs = ids; }, setCatalogReply(reply: typeof catalogReply) { catalogReply = reply; } };
}
++it('excludes retired image models even when the supplier advertises them', () => {
++ const models: GatewayModel[] = ['gpt-image-1', 'openai/gpt-image-1', 'gpt-image-2'].map(id => ({ id, modality: 'image', capabilities: ['generate'] }));
++ expect(officialModelPolicy(models).map(model => model.id)).toEqual(['gpt-image-2']);
++});
++
it('retains unsupported Anthropic, router and batch filtering', () => {
expect(modelAccessGroup(text('~openai/gpt-6-sol'))).toBe('openai');
expect(modelAccessGroup(text('openai/gpt-oss-20b'))).toBe('openai-oss');
diff --cc apps/daemon/test/unit/gateway-model-preferences.test.ts
index 5950a820,5950a820..7e8bfd22
--- a/apps/daemon/test/unit/gateway-model-preferences.test.ts
+++ b/apps/daemon/test/unit/gateway-model-preferences.test.ts
@@@ -4,6 -4,6 +4,13 @@@ import { migrateModelPreferences, resol
const text = (id: string): GatewayModel => ({ id, modality: 'text', capabilities: ['responses', 'chat', 'tools'], status: 'ready' });
++it('removes retired image selections and follows the replacement for an old default', () => {
++ const models: GatewayModel[] = ['gpt-image-1', 'gpt-image-2'].map(id => ({ id, modality: 'image', capabilities: ['generate'] }));
++ expect(resolveModelPreferences(models, { image: 'gpt-image-1' }, { image: 'gpt-image-1' }))
++ .toMatchObject({ models: [models[1]], selected: { image: 'gpt-image-2' }, manual: {}, changed: true });
++ expect(resolveModelPreferences([models[0]!], { image: 'gpt-image-1' }, {}).selected).not.toHaveProperty('image');
++});
++
it('migrates old automatic defaults and merges duplicate purposes while retaining distinct manual choices', () => {
expect(migrateModelPreferences({ text: 'gpt-4o-mini', textProcessing: 'chat-only', subtitle: 'whisper-1', image: 'gpt-image-1' }, { text: 'gpt-6.1-sol' })).toEqual({});
expect(migrateModelPreferences({ text: 'gpt-5.4', image: 'my-image', transcription: 'plain-asr', subtitle: 'my-timestamp-asr' }, {}))
diff --cc apps/daemon/test/unit/gateway-proxy.test.ts
index 99910bfa,99910bfa..30514db1
--- a/apps/daemon/test/unit/gateway-proxy.test.ts
+++ b/apps/daemon/test/unit/gateway-proxy.test.ts
@@@ -93,17 -93,17 +93,17 @@@ it.each([400, 402, 404, 422, 429, 500,
it('forwards Creator text, image, speech and subtitles through the gateway with native image parameters', async () => {
const app = Fastify();
const models = [...bootstrap.models,
-- { id: 'gpt-image-1', modality: 'image' as const, capabilities: ['generate', 'edit'], imageOptions: { maxImages: 1, maxReferences: 1, aspectRatios: ['3:2'], resolutions: ['1K'] } },
++ { id: 'gpt-image-2', modality: 'image' as const, capabilities: ['generate', 'edit'], imageOptions: { maxImages: 1, maxReferences: 1, aspectRatios: ['3:2'], resolutions: ['1K'] } },
{ id: 'tts-1', modality: 'speech' as const, capabilities: ['speech'], voices: ['alloy'] },
{ id: 'whisper-1', modality: 'transcription' as const, capabilities: ['transcription_text', 'subtitle_timestamps'] }];
const credentials = { accountId: bootstrap.account.id, transport: 'gateway' as const, modelKey: 'device-access-token', keyVersion: 'device-v1', bindingVersion: bootstrap.bindingVersion,
-- baseUrl: bootstrap.baseUrl, models, defaults: { text: 'gpt-4o-mini', image: 'gpt-image-1', speech: 'tts-1', transcription: 'whisper-1' } };
++ baseUrl: bootstrap.baseUrl, models, defaults: { text: 'gpt-4o-mini', image: 'gpt-image-2', speech: 'tts-1', transcription: 'whisper-1' } };
const fetcher = vi.fn<typeof fetch>(async (url, options) => {
expect(String(url)).toMatch(/^https:\/\/gateway\.example\/v1\//);
expect(new Headers(options?.headers).get('authorization')).toBe('Bearer device-access-token');
expect(new Headers(options?.headers).get('idempotency-key')).toBeTruthy();
if (String(url).endsWith('/images/generations')) {
-- expect(JSON.parse(String(options?.body))).toMatchObject({ model: 'gpt-image-1', size: '1536x1024', n: 1 });
++ expect(JSON.parse(String(options?.body))).toMatchObject({ model: 'gpt-image-2', size: '1536x1024', n: 1 });
expect(String(options?.body)).not.toContain('aspect_ratio');
expect(new Headers(options?.headers).get('prefer')).toBe('respond-async');
return Response.json({ requestId: 'ocreq_gateway_image', state: 'submitting' }, { status: 202 });
@@@ -125,7 -125,7 +125,7 @@@
expect(config.llm.apiKey).not.toBe('device-access-token');
for (const [operation, payload, extra, status] of [
['responses', { model: 'gpt-4o-mini', input: 'Hello' }, {}, 200],
-- ['images/generations', { model: 'gpt-image-1', prompt: 'Circle', aspect_ratio: '3:2', resolution: '1K' }, { prefer: 'respond-async' }, 202],
++ ['images/generations', { model: 'gpt-image-2', prompt: 'Circle', aspect_ratio: '3:2', resolution: '1K' }, { prefer: 'respond-async' }, 202],
['audio/speech', { model: 'tts-1', input: 'Hello', voice: 'alloy' }, {}, 200]
] as const) {
const result = await app.inject({ method: 'POST', url: `/internal/krillin-llm/gateway/v1/${operation}`, headers: { Authorization: `Bearer ${config.llm.apiKey}`, ...extra }, payload });
diff --cc apps/daemon/test/unit/image-generation-codex-native.test.ts
index 44448c10,44448c10..f96c2776
--- a/apps/daemon/test/unit/image-generation-codex-native.test.ts
+++ b/apps/daemon/test/unit/image-generation-codex-native.test.ts
@@@ -44,11 -44,11 +44,12 @@@ describe('codex-native provider dispatc
}
});
-- expect(result).toMatchObject({ model: 'gpt-image-1' });
++ expect(result).toMatchObject({ model: 'gpt-image-2' });
expect(result.contents[0]).toMatchObject({ content: png, mime: 'image/png' });
expect(fetchImpl).toHaveBeenCalledWith(
new URL('https://forward.example.test/v1/images/generations'),
expect.objectContaining({
++ body: expect.stringContaining('"model":"gpt-image-2"'),
headers: expect.objectContaining({ Authorization: 'Bearer local-codex-secret' })
})
);
diff --cc docs/development/codex-image-generation.md
index 3642451a,785f3019..0d3d260b
--- a/docs/development/codex-image-generation.md
+++ b/docs/development/codex-image-generation.md
@@@ -5,7 -5,7 +5,8 @@@
## API Key 模式
- 保留现有配置的 Base URL、API Key 和图片模型,调用 `/images/generations` 或带参考图的 `/images/edits`。
- - 文本模型不是图片模型时,保持原有 `gpt-image-1` 默认值。
+ - 文本模型不是图片模型时,使用默认值 `gpt-image-2`。
++- 已保存的 `gpt-image-1`(包括旧快照和 mini 变体)会迁移到 `gpt-image-2`,不再用于新生成;官方服务目录也会排除这些旧模型。`gpt-image-1.5` 和其他模型配置不受这次迁移影响,历史图片和生成记录保持原样。
- 接口必须支持图片生成。设置状态检查只检查本地配置,不会发送收费的生成请求。
## ChatGPT 登录模式
diff --cc packages/protocol/src/gateway-account.ts
index 820c62cb,820c62cb..6a81a4b8
--- a/packages/protocol/src/gateway-account.ts
+++ b/packages/protocol/src/gateway-account.ts
@@@ -1,3 -1,3 +1,5 @@@
++import { isRetiredOpenAiImageModel } from './image-model-options.js';
++
export type ServiceSource = 'manual' | 'gateway';
export const gatewayModelOperations = ['responses', 'chat/completions', 'images/generations', 'images/edits', 'audio/speech', 'audio/transcriptions', 'video/jobs'] as const;
export type GatewayModelOperation = typeof gatewayModelOperations[number];
@@@ -47,12 -47,12 +49,15 @@@ export function gatewayModelSupports(mo
return model.modality === purpose && (purpose !== 'text' || model.capabilities.includes('responses'));
}
export function gatewayModelCompatible(model: GatewayModel): boolean {
++ if (model.modality === 'image' && isRetiredOpenAiImageModel(model.id)) return false;
if (model.vendor?.toLowerCase() === 'anthropic' || /^(?:anthropic\/|claude-)/i.test(model.id)) return false;
if (model.modality === 'text') return model.capabilities.includes('responses') && model.capabilities.includes('chat');
if (model.modality === 'transcription') return model.capabilities.includes('subtitle_timestamps');
return true;
}
--export function gatewayModelReady(model: GatewayModel): boolean { return !model.status || model.status === 'ready'; }
++export function gatewayModelReady(model: GatewayModel): boolean {
++ return !(model.modality === 'image' && isRetiredOpenAiImageModel(model.id)) && (!model.status || model.status === 'ready');
++}
export type GatewayConnectionDiagnostics = {
path: string;
reason: 'timeout' | 'network' | 'http' | 'invalid_response';
diff --cc packages/protocol/src/image-model-options.test.ts
index 00000000,00000000..2188eead
new file mode 100644
--- /dev/null
+++ b/packages/protocol/src/image-model-options.test.ts
@@@ -1,0 -1,0 +1,22 @@@
++import { expect, it } from 'vitest';
++import { gatewayModelCompatible, gatewayModelReady, type GatewayModel } from './gateway-account.js';
++import { imageModelOptions, migrateOpenAiImageModel } from './image-model-options.js';
++
++it.each(['gpt-image-1', 'gpt-image-1-mini', 'gpt-image-1-2025-04-15', 'openai/gpt-image-1', '88api/gpt-image-1', ' GPT-IMAGE-1 '])(
++ 'retires %s from manual controls and official model selection', id => {
++ expect(imageModelOptions('openai', id)).toEqual({});
++ const model: GatewayModel = { id, modality: 'image', capabilities: ['generate'], status: 'ready' };
++ expect(gatewayModelCompatible(model)).toBe(false);
++ expect(gatewayModelReady(model)).toBe(false);
++ expect(migrateOpenAiImageModel(id)).toBe(id.includes('/') ? `${id.split('/')[0]}/gpt-image-2` : 'gpt-image-2');
++ }
++);
++
++it.each(['gpt-image-2', 'gpt-image-1.5', 'custom-image', 'chatgpt-image-latest'])(
++ 'preserves the independently configured model %s', id => {
++ expect(migrateOpenAiImageModel(id)).toBe(id);
++ const model: GatewayModel = { id, modality: 'image', capabilities: ['generate'] };
++ expect(gatewayModelCompatible(model)).toBe(true);
++ expect(gatewayModelReady(model)).toBe(true);
++ }
++);
diff --cc packages/protocol/src/image-model-options.ts
index 9913f2af,9913f2af..7fb0f4c1
--- a/packages/protocol/src/image-model-options.ts
+++ b/packages/protocol/src/image-model-options.ts
@@@ -10,6 -10,6 +10,16 @@@ const standardRatios = ['1:1', '3:2', '
const geminiRatios = [...standardRatios, '21:9'];
const wideGeminiRatios = [...geminiRatios, '1:4', '4:1', '1:8', '8:1'];
++export function isRetiredOpenAiImageModel(model: string): boolean {
++ return /(?:^|\/)gpt-image-1(?:$|-)/i.test(model.trim());
++}
++
++export function migrateOpenAiImageModel(model: string): string {
++ if (!isRetiredOpenAiImageModel(model)) return model;
++ const id = model.trim();
++ return `${id.slice(0, id.lastIndexOf('/') + 1)}gpt-image-2`;
++}
++
/** Manual provider contracts. Official services must use their own catalog metadata.
* Sources: ai.google.dev/gemini-api/docs/image-generation, openai/openai-openapi,
* volcengine.com/docs/82379/1541523, app.klingai.com/global/dev/document-api.
@@@ -34,7 -34,7 +44,7 @@@ export function imageModelOptions(provi
if (provider === 'openai') {
const qualities = ['low', 'medium', 'high', ...(/^gpt-image-2\.5-(?:sunburst|flare)/.test(id) ? ['xhigh', 'max'] : []), 'auto'];
if (/^gpt-image-2(?:$|[.-])/.test(id)) return { aspectRatios: standardRatios, resolutions: ['1K', '2K'], qualities };
-- if (/^gpt-image-1(?:$|[.-])/.test(id) || id === 'chatgpt-image-latest') return { aspectRatios: ['1:1', '3:2', '2:3'], qualities };
++ if (/^gpt-image-1\.5(?:$|-)/.test(id) || id === 'chatgpt-image-latest') return { aspectRatios: ['1:1', '3:2', '2:3'], qualities };
}
return {};
}
diff --cc runtime/krillinai/config/config.go
index 186e3727,14d300bd..86e63679
--- a/runtime/krillinai/config/config.go
+++ b/runtime/krillinai/config/config.go
@@@ -4,6 -4,6 +4,7 @@@ import
"errors"
"fmt"
"krillin-ai/log"
++ pkgimage "krillin-ai/pkg/image"
"net/url"
"os"
"path/filepath"
@@@ -315,6 -315,6 +316,7 @@@ func LoadConfig() bool
log.GetLogger().Error("加载配置文件失败", zap.Error(err))
return false
}
++ Conf.Image.Openai.Model = pkgimage.MigrateOpenAIImageModel(Conf.Image.Openai.Model)
return true
}
}
diff --cc runtime/krillinai/config/config_test.go
index 40e1f59f,8a1dd16e..2aafae9b
--- a/runtime/krillinai/config/config_test.go
+++ b/runtime/krillinai/config/config_test.go
@@@ -1,6 -1,6 +1,28 @@@
package config
--import "testing"
++import (
++ "os"
++ "path/filepath"
++ "testing"
++)
++
++func TestLoadConfigMigratesRetiredImageModel(t *testing.T) {
++ original := Conf
++ t.Cleanup(func() { Conf = original })
++ t.Chdir(t.TempDir())
++ if err := os.Mkdir("config", 0700); err != nil {
++ t.Fatal(err)
++ }
++ if err := os.WriteFile(filepath.Join("config", "config.toml"), []byte("[image.openai]\nmodel = 'gpt-image-1'\napi_key = 'image-secret'\n"), 0600); err != nil {
++ t.Fatal(err)
++ }
++ if !LoadConfig() {
++ t.Fatal("LoadConfig() failed")
++ }
++ if Conf.Image.Openai.Model != "gpt-image-2" || Conf.Image.Openai.ApiKey != "image-secret" {
++ t.Fatal("image model migration did not retain credentials and replace the retired model")
++ }
++}
func TestDefaultImageConfig(t *testing.T) {
if Conf.Image.Provider != "openai-compatible" {
diff --cc runtime/krillinai/pkg/image/openai_compatible.go
index 7eb96240,7eb96240..cbd4f353
--- a/runtime/krillinai/pkg/image/openai_compatible.go
+++ b/runtime/krillinai/pkg/image/openai_compatible.go
@@@ -12,6 -12,6 +12,16 @@@ import
const defaultOpenAIImageBaseURL = "https://api.openai.com/v1"
++func MigrateOpenAIImageModel(model string) string {
++ id := strings.TrimSpace(model)
++ prefix := strings.LastIndex(id, "/") + 1
++ slug := strings.ToLower(id[prefix:])
++ if slug == "gpt-image-1" || strings.HasPrefix(slug, "gpt-image-1-") {
++ return id[:prefix] + "gpt-image-2"
++ }
++ return model
++}
++
type GenerateRequest struct {
Prompt string
Size string
@@@ -36,7 -36,7 +46,7 @@@ func NewOpenAICompatibleClient(baseURL
return &OpenAICompatibleClient{
baseURL: strings.TrimRight(baseURL, "/"),
apiKey: apiKey,
-- model: model,
++ model: MigrateOpenAIImageModel(model),
httpClient: http.DefaultClient,
}
}
@@@ -51,7 -51,7 +61,8 @@@ func (c *OpenAICompatibleClient) Genera
"prompt": req.Prompt,
"size": size,
}
-- if !strings.HasPrefix(c.model, "gpt-image-") {
++ slug := c.model[strings.LastIndex(c.model, "/")+1:]
++ if !strings.HasPrefix(strings.ToLower(slug), "gpt-image-") {
body["response_format"] = "b64_json"
}
data, err := json.Marshal(body)
diff --cc runtime/krillinai/pkg/image/openai_compatible_test.go
index 8a7d0007,8a7d0007..5984e666
--- a/runtime/krillinai/pkg/image/openai_compatible_test.go
+++ b/runtime/krillinai/pkg/image/openai_compatible_test.go
@@@ -60,7 -60,7 +60,7 @@@ func TestOpenAICompatibleGenerateOmitsR
}))
defer server.Close()
-- client := NewOpenAICompatibleClient(server.URL, "test-key", "gpt-image-1")
++ client := NewOpenAICompatibleClient(server.URL, "test-key", "gpt-image-2")
_, err := client.Generate(context.Background(), GenerateRequest{Prompt: "cover"})
if err != nil {
t.Fatalf("Generate() error = %v", err)
@@@ -76,7 -76,7 +76,7 @@@ func TestOpenAICompatibleGenerateAccept
}))
defer server.Close()
-- client := NewOpenAICompatibleClient(server.URL, "test-key", "gpt-image-1")
++ client := NewOpenAICompatibleClient(server.URL, "test-key", "gpt-image-2")
out, err := client.Generate(context.Background(), GenerateRequest{Prompt: "cover"})
if err != nil {
t.Fatalf("Generate() error = %v", err)
@@@ -92,9 -92,9 +92,40 @@@ func TestOpenAICompatibleGenerateReturn
}))
defer server.Close()
-- client := NewOpenAICompatibleClient(server.URL, "test-key", "gpt-image-1")
++ client := NewOpenAICompatibleClient(server.URL, "test-key", "gpt-image-2")
_, err := client.Generate(context.Background(), GenerateRequest{Prompt: "cover"})
if err == nil {
t.Fatalf("Generate() error = nil, want error")
}
}
++
++func TestOpenAICompatibleGenerateMigratesRetiredModels(t *testing.T) {
++ for _, tc := range []struct{ model, want string }{
++ {"gpt-image-1", "gpt-image-2"},
++ {"gpt-image-1-mini", "gpt-image-2"},
++ {" GPT-IMAGE-1-2025-04-15 ", "gpt-image-2"},
++ {"openai/gpt-image-1", "openai/gpt-image-2"},
++ {"gpt-image-1.5", "gpt-image-1.5"},
++ } {
++ t.Run(tc.model, func(t *testing.T) {
++ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
++ var body map[string]any
++ if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
++ t.Fatal(err)
++ }
++ if body["model"] != tc.want {
++ t.Errorf("model = %v, want %s", body["model"], tc.want)
++ }
++ if _, ok := body["response_format"]; ok {
++ t.Error("GPT image requests must omit response_format")
++ }
++ _, _ = w.Write([]byte(`{"data":[{"b64_json":"abc123"}]}`))
++ }))
++ defer server.Close()
++ client := NewOpenAICompatibleClient(server.URL, "test-key", tc.model)
++ if _, err := client.Generate(context.Background(), GenerateRequest{Prompt: "cover"}); err != nil {
++ t.Fatal(err)
++ }
++ })
++ }
++}