Table of Contents

Cloud Image AI

TTMSMCPCloudImageAI generates and edits images through a cloud service, and presents OpenAI, Google Gemini, Black Forest Labs, Stability and Reve behind one API. You set APIKey, pick a Service, and call Execute with a prompt; the image comes back as base64 in OnImageGenerated whatever the service returned on the wire. The same Execute takes a reference image — as a stream, a base64 string, or a framework picture — to edit an existing image instead of creating one, and the Images collection turns a single prompt into a multi-reference composition. RemoveBackground and ReplaceBackground cover the two edits that are asked for most often, using the service's dedicated endpoint where one exists and a generated instruction where it does not. Model and CustomOptions reach whatever the individual provider supports beyond that.

Documentation

Start here Use when
Getting started You want one generated image quickly.
User guide You want task-oriented chapters grouped by feature area.
API reference You want exact class, property, method, and event contracts.
Release notes You want the version history for this component.

Key classes

Class Role
TTMSMCPCloudImageAI The component: key, service, model, custom options, generation, background edits, and both result events.
TTMSMCPCustomCloudImageAI The ancestor that holds the whole implementation; derive from it to publish a different property set.
TTMSMCPCloudAIImage One reference image, held as a TMemoryStream and loadable from a framework picture.
TTMSMCPCloudAIImages The Images collection sent along with the prompt when it is not empty.
TTMSMCPCloudBase The HTTP transport ancestor: request logging, progress, cancellation, and the request events.
TTMSMCPCloudBaseRequestResult The request both result events carry: status code, body, headers, and success flag.

Minimal example

procedure TForm1.FormCreate(Sender: TObject);
begin
  { ImageAI is a TTMSMCPCloudImageAI on the form. The key comes from the
    application configuration - never from a literal in the source. }
  ImageAI.APIKey := Config.ReadString('imageai', 'openai_key', '');
  ImageAI.Service := isOpenAI;
  ImageAI.OnImageGenerated := ImageAIImageGenerated;
  ImageAI.OnRequestError := ImageAIRequestError;
end;

procedure TForm1.btnGenerateClick(Sender: TObject);
begin
  { Execute returns straight away; the result arrives in OnImageGenerated. }
  ImageAI.Execute('A photorealistic image of a cat doing yoga.');
end;

procedure TForm1.ImageAIImageGenerated(Sender: TObject;
  ARequestResult: TTMSMCPCloudBaseRequestResult; ABase64Image: string);
var
  Stream: TMemoryStream;
begin
  { Every service hands the image back as base64, whatever it returned on
    the wire, so one decoding path covers all five. }
  Stream := TMemoryStream.Create;
  try
    TTMSMCPUtils.LoadStreamFromBase64(ABase64Image, Stream);
    Stream.SaveToFile(TPath.Combine(FOutputFolder, 'generated.png'));
  finally
    Stream.Free;
  end;
end;

procedure TForm1.ImageAIRequestError(Sender: TObject;
  ARequestResult: TTMSMCPCloudBaseRequestResult);
begin
  memoLog.Lines.Add(Format('Image request failed (%d): %s',
    [ARequestResult.ResponseCode, ARequestResult.ResultString]));
end;

API map

Role Types
Component TTMSMCPCloudImageAI, TTMSMCPCustomCloudImageAI
Service selection TTMSMCPCloudImageAIService
Reference images TTMSMCPCloudAIImage, TTMSMCPCloudAIImages
Result events TTMSMCPCloudImageAIGenerateImageResultEvent, TTMSMCPCloudImageAIErrorEvent
Provider contract ITMSMCPCustomCloudImageAI, ITMSMCPCustomCloudImageAIProperties, ITMSMCPCustomCloudImageAIInstance
Provider registration ITMSMCPCloudImageAIService, ITMSMCPCloudImageAIServiceOpenAI, ITMSMCPCloudImageAIServiceGemini, ITMSMCPCloudImageAIServiceBFL, ITMSMCPCloudImageAIServiceStability, ITMSMCPCloudImageAIServiceReve
Base transport TTMSMCPCloudBase, TTMSMCPCustomCloudBase, TTMSMCPCloudBaseRequest, TTMSMCPCloudBaseRequestResult

Guides

Guide Covers
Generating images Text to image, editing one reference image, several references through the Images collection, background removal and replacement, decoding and saving the result, and handling failures.
Providers and options Choosing a service and the key that belongs to it, model names and their defaults, service-specific CustomOptions, the polling services that answer in several round trips, and request logging.

See Also