Skip to content

Comments

feat: Add ModelsLab image generation provider#3296

Open
adhikjoshi wants to merge 1 commit intosimstudioai:mainfrom
adhikjoshi:feat/modelslab-image-generation
Open

feat: Add ModelsLab image generation provider#3296
adhikjoshi wants to merge 1 commit intosimstudioai:mainfrom
adhikjoshi:feat/modelslab-image-generation

Conversation

@adhikjoshi
Copy link

Summary

Adds ModelsLab as a new image generation provider to sim's Image Generator block, alongside the existing OpenAI providers (DALL-E 3, GPT Image).

What this PR adds

New Provider: ModelsLab

Five popular models available out of the box:

  • Flux (Schnell) — fast, high-quality default
  • Juggernaut XL — photorealistic portraits
  • RealVisXL v5 — realistic photography style
  • DreamShaper XL — artistic/creative
  • Stable Diffusion XL — general purpose

How it works

The Image Generator block now has a Provider dropdown (OpenAI | ModelsLab). Selecting ModelsLab shows:

  • Model picker (Flux, Juggernaut XL, etc.)
  • Size presets (512×512 to 1344×768)
  • Optional negative prompt
  • ModelsLab API key field

Files changed (6)

File Change
tools/image/modelslab.ts Client-side tool definition
tools/image/types.ts Shared request/response types
tools/image/index.ts Tool exports
app/api/tools/image/generate/route.ts Server-side handler with async polling
blocks/blocks/image_generator.ts Added provider selector + ModelsLab options
tools/registry.ts Registered image_modelslab tool

Architecture follows existing patterns

  • Server-side route mirrors the /api/tools/video pattern for long-running generation
  • Polls /api/v6/images/fetch/{id} every 5s until completion (max 200s timeout)
  • Image URL fetched and base64-encoded via the existing /api/tools/image proxy

Usage example

Provider:         ModelsLab
Model:            Flux (Schnell)
Prompt:           a futuristic cityscape at sunset, ultra detailed
Size:             1024x1024
Negative Prompt:  blurry, low quality, watermark
API Key:          [ModelsLab API key from modelslab.com]

ModelsLab

Checklist

  • TypeScript compiles without errors
  • Biome lint passes
  • Follows existing video/TTS block provider-selector pattern
  • Server-side route handles both sync and async ModelsLab responses
  • Backward compatible — existing OpenAI blocks unchanged (provider defaults to openai)

- Add ModelsLab as new image generation provider (alongside OpenAI)
- Support Flux, Juggernaut XL, RealVisXL, DreamShaper XL, SDXL models
- Server-side route handles async polling for image generation
- Restructure image_generator block with provider selector
- Add conditional model/options based on provider selection
@vercel
Copy link

vercel bot commented Feb 22, 2026

@adhikjoshi is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 22, 2026

Greptile Summary

Adds ModelsLab as a new image generation provider alongside OpenAI, enabling access to Flux, Juggernaut XL, RealVisXL, DreamShaper, and Stable Diffusion XL models. The implementation follows established patterns from the video generation feature, including a new API route with async polling, provider-based conditional UI in the Image Generator block, and proper separation of tool definitions and types.

Major changes:

  • New image_modelslab tool with correct user-only visibility for API keys
  • Provider selector dropdown in Image Generator block with conditional field rendering
  • Server-side /api/tools/image/generate route that polls ModelsLab API until completion (max 200s)
  • Size parsing logic converts dropdown values (e.g. "1024x768") to width/height parameters
  • Backward compatible - existing OpenAI blocks default to openai provider

Confidence Score: 4/5

  • This PR is safe to merge with minor considerations
  • The implementation follows established patterns from video generation, correctly uses user-only visibility for API keys per custom instructions, and maintains backward compatibility. The code is well-structured with proper error handling and validation. Score reduced to 4 due to the extensive conditional logic in the block config which increases complexity.
  • Pay close attention to apps/sim/blocks/blocks/image_generator.ts due to complex nested conditional logic

Important Files Changed

Filename Overview
apps/sim/tools/image/modelslab.ts ModelsLab tool definition with correct visibility settings and comprehensive parameter descriptions
apps/sim/blocks/blocks/image_generator.ts Provider selector and ModelsLab integration with conditional UI - extensive changes to support multi-provider workflow
apps/sim/app/api/tools/image/generate/route.ts New API route for ModelsLab image generation with async polling - mirrors video generation pattern

Sequence Diagram

sequenceDiagram
    participant User
    participant Block as Image Generator Block
    participant Tool as image_modelslab Tool
    participant Route as /api/tools/image/generate
    participant ML as ModelsLab API
    participant Proxy as /api/tools/image

    User->>Block: Select ModelsLab provider
    Block->>Block: Show ModelsLab options (model, size, negativePrompt)
    User->>Block: Configure & execute
    Block->>Tool: Call with params (provider, apiKey, model, prompt, width, height)
    Tool->>Route: POST request body
    Route->>Route: Validate params & auth
    Route->>ML: POST /api/v6/images/text2img
    ML-->>Route: status: "processing", id: jobId
    
    loop Poll every 5s (max 40 attempts)
        Route->>ML: POST /api/v6/images/fetch/{jobId}
        ML-->>Route: status: "processing"
    end
    
    ML-->>Route: status: "success", output: [imageUrl]
    Route->>Proxy: GET with imageUrl param
    Proxy-->>Route: image binary
    Route->>Route: Convert to base64
    Route-->>Tool: { imageUrl, imageFile, model, provider }
    Tool-->>Block: Success response
    Block-->>User: Display generated image
Loading

Last reviewed commit: 9645e69

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant