import type { ImageEditRequest, ImageGenerateRequest, ImageProvider, ImageProviderCallContext, ImageProviderInfo, ImageResult, MediaSafetyFinding } from '../types/images.js'; import { ImageProviderError } from './errors.js'; import type { AssetTransformer } from './transform.js'; /** Options for the OpenAI image provider. */ export interface OpenAIImageProviderConfig { /** OpenAI API key. */ apiKey: string; /** API base URL. Defaults to `https://api.openai.com/v1`. */ baseUrl?: string; /** Sent as the `OpenAI-Organization` header. */ organization?: string; /** Sent as the `OpenAI-Project` header. */ project?: string; /** Headers added to every request. */ defaultHeaders?: Record; /** Model used when a request names none. Defaults to `gpt-image-2`. */ defaultModel?: string; /** Largest input image accepted, in bytes. Defaults to 50 MiB. */ maxInputBytes?: number; /** Replaces the global `fetch`. */ fetch?: typeof globalThis.fetch; /** Keeps OpenAI's response on each result as `raw`. Off by default. */ includeRawResponse?: boolean; /** * Converts a neutral mask into OpenAI's alpha-channel semantics. Defaults to the bundled PNG * transformer, which is loaded only when a request actually carries a mask. */ maskTransformer?: AssetTransformer; } /** What OpenAI said about a request its moderation refused. */ export interface OpenAIModerationDetails { /** Whether the prompt or the generated image was refused. */ moderationStage?: 'input' | 'output' | 'unknown'; /** The moderation categories reported. */ categories?: string[]; } /** An error from the OpenAI Image API, with its HTTP status and request id. */ export declare class OpenAIImageProviderError extends ImageProviderError { /** HTTP status. */ readonly status: number; /** OpenAI's request id, for support. */ readonly requestId?: string | undefined; /** OpenAI's error code. */ readonly apiCode?: string | undefined; /** Moderation details, when moderation refused the request. */ readonly moderation?: OpenAIModerationDetails | undefined; /** The same refusal as neutral safety findings. */ readonly safetyFindings?: MediaSafetyFinding[] | undefined; constructor(message: string, /** HTTP status. */ status: number, /** OpenAI's request id, for support. */ requestId?: string | undefined, /** OpenAI's error code. */ apiCode?: string | undefined, /** Moderation details, when moderation refused the request. */ moderation?: OpenAIModerationDetails | undefined, /** The same refusal as neutral safety findings. */ safetyFindings?: MediaSafetyFinding[] | undefined, cause?: unknown); } /** * Hosted OpenAI Image API adapter for generation, reference-based editing, and masked editing. * * OpenAI edits where a mask is fully transparent, which is neither of the neutral polarities a * caller draws in. Masks are converted by an `AssetTransformer` at the input image's exact * dimensions; the PNG codec behind the default transformer is imported on the first masked request, * so an application that never masks never loads it. */ export declare class OpenAIImageProvider implements ImageProvider { private readonly config; /** Provider name, capabilities, and models. */ readonly info: ImageProviderInfo; private readonly baseUrl; private readonly fetchImplementation; private readonly defaultModel; private readonly maxInputBytes; constructor(config: OpenAIImageProviderConfig); /** Generates images from a prompt. */ generate(request: ImageGenerateRequest, context: ImageProviderCallContext): Promise; /** Edits images, optionally within a mask. */ edit(request: ImageEditRequest, context: ImageProviderCallContext): Promise; private assertDirectRequest; private appendAsset; private request; private normalizeResult; }