Skip to content

🤯 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.

💄 style: add `step-image-edit-2` support (#14329)

Zhijie He8b8b0f057938
diff --git a/packages/model-bank/src/aiModels/stepfun.ts b/packages/model-bank/src/aiModels/stepfun.ts
index 920a3d409ba..31363282063 100644
--- a/packages/model-bank/src/aiModels/stepfun.ts
+++ b/packages/model-bank/src/aiModels/stepfun.ts
@@ -342,14 +342,39 @@ const stepfunChatModels: AIChatModelCard[] = [
];
const stepfunImageModels: AIImageModelCard[] = [
- // https://platform.stepfun.com/docs/llm/image
+ {
+ description:
+ 'A lightweight editing model from Stepfun’s latest iteration that supports both text-to-image generation and image editing within a single model. Despite having fewer than 6 billion parameters, it achieves state-of-the-art performance at its scale, rivaling open-source models in the 12B–20B parameter range across tiers. Each editing task takes only 1–2 seconds, redefining the experience of real-time interactive image editing.',
+ displayName: 'Step Image Edit 2',
+ enabled: true,
+ id: 'step-image-edit-2',
+ parameters: {
+ cfg: { default: 1, max: 10, min: 1, step: 0.1 },
+ imageUrl: { default: null },
+ prompt: {
+ default: '',
+ },
+ seed: { default: null },
+ size: {
+ default: '1024x1024',
+ enum: ['1024x1024', '768x1360', '896x1184', '1360x768', '1184x896'],
+ },
+ steps: { default: 8, max: 50, min: 1 },
+ },
+ pricing: {
+ currency: 'CNY',
+ units: [{ name: 'imageGeneration', rate: 0.02, strategy: 'fixed', unit: 'image' }],
+ },
+ releasedAt: '2026-04-28',
+ type: 'image',
+ },
{
description:
'A new-generation StepFun image model focused on image generation, producing high-quality images from text prompts. It delivers more realistic texture and stronger Chinese/English text rendering.',
displayName: 'Step 2X Large',
- enabled: true,
id: 'step-2x-large',
parameters: {
+ cfg: { default: 7.5, max: 10, min: 1, step: 0.1 },
prompt: {
default: '',
},
@@ -374,6 +399,8 @@ const stepfunImageModels: AIImageModelCard[] = [
enabled: true,
id: 'step-1x-medium',
parameters: {
+ cfg: { default: 7.5, max: 10, min: 1, step: 0.1 },
+ imageUrl: { default: null },
prompt: {
default: '',
},
@@ -398,6 +425,7 @@ const stepfunImageModels: AIImageModelCard[] = [
enabled: true,
id: 'step-1x-edit',
parameters: {
+ cfg: { default: 6, max: 10, min: 1, step: 0.1 },
imageUrl: { default: null },
prompt: {
default: '',
diff --git a/packages/model-runtime/src/providers/stepfun/createImage.ts b/packages/model-runtime/src/providers/stepfun/createImage.ts
new file mode 100644
index 00000000000..d909a4b7121
--- /dev/null
+++ b/packages/model-runtime/src/providers/stepfun/createImage.ts
@@ -0,0 +1,105 @@
+import createDebug from 'debug';
+
+import type { CreateImageOptions } from '../../core/openaiCompatibleFactory';
+import type { CreateImagePayload, CreateImageResponse } from '../../types/image';
+import { AgentRuntimeError } from '../../utils/createError';
+
+const log = createDebug('lobe-image:stepfun');
+
+interface StepfunImageDataItem {
+ b64_json?: string;
+ finish_reason?: string;
+ seed?: number;
+ url?: string;
+}
+
+interface StepfunImageResponse {
+ created?: number;
+ data?: StepfunImageDataItem[];
+ id?: string;
+}
+
+export async function createStepfunImage(
+ payload: CreateImagePayload,
+ options: CreateImageOptions,
+): Promise<CreateImageResponse> {
+ const { apiKey, baseURL, provider } = options;
+ const { model, params } = payload;
+ const { cfg, imageUrl, prompt, seed, size, steps } = params;
+
+ try {
+ let endpoint = imageUrl ? 'edits' : 'generations';
+
+ const body: Record<string, any> = {
+ model,
+ n: 1, // Only supports generating 1 image at a time
+ prompt,
+ response_format: 'url',
+ ...(cfg !== undefined ? { cfg_scale: cfg } : {}),
+ ...(seed !== undefined ? { seed } : {}),
+ ...(size !== undefined ? { size } : {}),
+ ...(steps !== undefined ? { steps } : {}),
+ ...(model === 'step-image-edit-2' ? { text_mode: true } : {}),
+ };
+
+ if (imageUrl) {
+ if (model === 'step-1x-medium') {
+ // For step-1x-medium, endpoint is "image2image" and the imageUrl should be passed as "source_url" in the body
+ endpoint = 'image2image';
+ body.source_url = imageUrl;
+ body.source_weight = 0.5;
+ } else {
+ // For other models, the imageUrl should be passed as "image" in the body
+ body.image = imageUrl;
+ }
+ }
+
+ log('Calling Stepfun image API: %s with body: %O', endpoint, body);
+
+ const res = await fetch(`${baseURL}/images/${endpoint}`, {
+ method: 'POST',
+ headers: {
+ 'Authorization': `Bearer ${apiKey}`,
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(body),
+ });
+
+ if (!res.ok) {
+ let errBody: any = undefined;
+ try {
+ errBody = await res.json();
+ } catch {
+ // ignore
+ }
+ throw new Error(
+ `Stepfun image API error: ${res.status} ${res.statusText} ${
+ errBody ? JSON.stringify(errBody) : ''
+ }`,
+ );
+ }
+
+ const data: StepfunImageResponse = await res.json();
+ log('Stepfun image response: %O', data);
+
+ if (!data || !Array.isArray(data.data) || data.data.length === 0) {
+ throw new Error('No image data returned from Stepfun');
+ }
+
+ const first = data.data[0];
+ if (!first) throw new Error('Empty image item');
+
+ if (first.url) {
+ return { imageUrl: first.url };
+ }
+
+ throw new Error('Unsupported image response format from Stepfun');
+ } catch (error) {
+ log('Error creating Stepfun image: %O', error);
+ throw AgentRuntimeError.createImage({
+ error: error as any,
+ errorType: 'ProviderBizError',
+ provider,
+ });
+ }
+}
diff --git a/packages/model-runtime/src/providers/stepfun/index.ts b/packages/model-runtime/src/providers/stepfun/index.ts
index fcb87aaefd0..4890a656051 100644
--- a/packages/model-runtime/src/providers/stepfun/index.ts
+++ b/packages/model-runtime/src/providers/stepfun/index.ts
@@ -3,6 +3,7 @@ import { ModelProvider } from 'model-bank';
import type { OpenAICompatibleFactoryOptions } from '../../core/openaiCompatibleFactory';
import { createOpenAICompatibleRuntime } from '../../core/openaiCompatibleFactory';
+import { createStepfunImage } from './createImage';
export interface StepfunModelCard {
id: string;
@@ -36,6 +37,7 @@ export const params = {
debug: {
chatCompletion: () => process.env.DEBUG_STEPFUN_CHAT_COMPLETION === '1',
},
+ createImage: createStepfunImage,
models: async ({ client }) => {
const { LOBE_DEFAULT_MODEL_LIST } = await import('model-bank');