← All @molecule/* packages · App templates
@molecule/api-ai-image-generation-pipelineUtility · ai-image-generation-pipeline · API (Node) · v1.0.1 · Apache-2.0
Style + variations + prompt enhancement pipeline
npm install @molecule/api-ai-image-generation-pipeline@molecule/api-ai-image-generation-pipeline is a utility package for the API (Node) side (ai-image-generation-pipeline).
import { runImageGeneration, enhancePrompt } from '@molecule/api-ai-image-generation-pipeline'
const enhanced = await enhancePrompt({ prompt: 'a cat' })
const result = await runImageGeneration({
prompt: enhanced.text,
size: '1024x1024',
stylePromptModifier: 'photorealistic, golden hour lighting',
model: 'reverie-xl-v3',
provider: 'openai',
})
if (result.status === 'succeeded') console.log(result.imageUrl)Works with: @molecule/api-ai, @molecule/api-ai-image-generation
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
@molecule/api-ai-image-generation-pipeline — high-level pipeline
wrapping @molecule/api-ai-image-generation (vendor abstraction) with
style application, brand-model mapping, base64-to-data-URL
normalization, and chat-driven prompt enhancement.
Extracted from the ai-image-generator flagship. Use it when you need end-to-end "user types prompt → image" semantics with graceful fallback when no provider is bonded.
import { runImageGeneration, enhancePrompt } from '@molecule/api-ai-image-generation-pipeline'
const enhanced = await enhancePrompt({ prompt: 'a cat' })
const result = await runImageGeneration({
prompt: enhanced.text,
size: '1024x1024',
stylePromptModifier: 'photorealistic, golden hour lighting',
model: 'reverie-xl-v3',
provider: 'openai',
})
if (result.status === 'succeeded') console.log(result.imageUrl)
utility
npm install @molecule/api-ai-image-generation-pipeline @molecule/api-ai @molecule/api-ai-image-generation
EnhancePromptOptionsOptions accepted by {@link enhancePrompt}.
interface EnhancePromptOptions {
prompt: string
/** AI provider name (e.g. 'anthropic'); falls back to default-bonded provider. */
providerName?: string
/** Override system instructions for the rewrite. */
system?: string
maxTokens?: number
temperature?: number
}
EnhancePromptResultResult returned by {@link enhancePrompt}.
interface EnhancePromptResult {
text: string
enhanced: boolean
}
ImageGenerationOutcomeNormalized outcome returned by {@link runImageGeneration} for all terminal states.
interface ImageGenerationOutcome {
imageUrl: string | null
revisedPrompt: string | null
status: GenerationStatus
error: string | null
}
RunImageGenerationOptionsOptions accepted by {@link runImageGeneration}.
interface RunImageGenerationOptions {
prompt: string
size?: string
style?: string
model?: string
provider?: string
/** Style modifier appended to the prompt before vendor dispatch. */
stylePromptModifier?: string | null
/** Optional brand→vendor model translation; defaults to {@link defaultResolveModel}. */
resolveModel?: (brandModel: string | undefined, provider: string) => string | undefined
}
GenerationStatusUnion of terminal + intermediate image-generation states.
type GenerationStatus = 'succeeded' | 'failed' | 'queued'
applyStyleToPrompt(prompt, modifier)Append a style modifier onto the user-typed prompt.
function applyStyleToPrompt(prompt: string, modifier: string | null | undefined): string
defaultResolveModel(brandModel, provider)Default brand-to-provider model mapper used by the flagship. Override via {@link RunImageGenerationOptions.resolveModel}.
function defaultResolveModel(brandModel: string | undefined, provider: string): string | undefined
enhancePrompt(opts)Expand a short user prompt into a richer one via the bonded chat AI
provider. Returns { enhanced: false, text: prompt } if no provider
is bonded or the stream errors — the endpoint stays contractually 200
so the calling UI flow remains testable without an AI key.
function enhancePrompt(opts: EnhancePromptOptions): Promise<EnhancePromptResult>
runImageGeneration(opts)Dispatch the bonded image-generation provider and normalize output.
Returns status: 'queued' if no provider is bonded (graceful no-op),
status: 'failed' with an error if the provider throws or returns no
image, and status: 'succeeded' with an imageUrl otherwise.
Base64 responses (e.g. gpt-image-1) are normalized to a data: URL.
function runImageGeneration(opts: RunImageGenerationOptions): Promise<ImageGenerationOutcome>
Peer dependencies:
@molecule/api-ai ^1.0.1@molecule/api-ai-image-generation ^1.0.1@molecule/api-ai@molecule/api-ai-image-generationWiring — this package composes TWO different accessor mechanisms:
runImageGeneration() resolves @molecule/api-ai-image-generation, whose
core keeps its OWN singleton: wire it with THAT package's setProvider(...)
(e.g. setProvider(createProvider()) from
@molecule/api-ai-image-generation-openai). A generic
bond('ai-image-generation', …) call is never seen by that core — the
pipeline then returns status: 'queued' forever with no error to debug.enhancePrompt() resolves the registry-based @molecule/api-ai chat bond
(bond('ai', provider) / named providers); with none bonded it returns
{ enhanced: false, text: prompt } instead of failing.status: 'queued' means "no image provider wired" (the graceful no-op path),
NOT "an async job is pending" — nothing retries it. Treat a persistent
'queued' as a wiring bug.