usingvarclient=newStabilityAIClient(apiKey);// Discover available engines before generating imagesvarengines=awaitclient.V1Engines.ListEnginesAsync();foreach(varengineinengines){Console.WriteLine($"{engine.Id}: {engine.Name} ({engine.Type})");Console.WriteLine($" {engine.Description}");}
usingvarclient=newStabilityAIClient(apiKey);varimages=awaitclient.V1Generation.TextToImageAsync(engineId:"stable-diffusion-v1-6",request:newTextToImageRequestBody(textToImageRequestBodyVariant1:newTextToImageRequestBodyVariant1{TextPrompts=[ new TextPrompt { Text = "A beautiful sunset over mountains, digital art", Weight = 1.0f, }, ],Height=512,Width=512,},generationOptionalParams:newGenerationRequestOptionalParams{Samples=1,}));foreach(varimageinimages){Console.WriteLine($"Seed: {image.Seed}, Finish reason: {image.FinishReason}");// image.Base64 contains the generated image datavarbytes=Convert.FromBase64String(image.Base64!);awaitFile.WriteAllBytesAsync($"output_{image.Seed}.png",bytes);}
Generate with Stable Diffusion 3.5
1 2 3 4 5 6 7 8 9101112131415
usingvarclient=newStabilityAIClient(apiKey);varresponse=awaitclient.Generate.CreateStableImageGenerateSd3Async(contentType:"multipart/form-data",accept:CreateStableImageGenerateSd3Accept.ApplicationJson,request:newCreateStableImageGenerateSd3Request{Prompt="A crisp studio product photo of a ceramic espresso cup on a slate table",Model=CreateStableImageGenerateSd3RequestModel.Sd35Large,AspectRatio=CreateStableImageGenerateSd3RequestAspectRatio.x1_1,OutputFormat=CreateStableImageGenerateSd3RequestOutputFormat.Png,});Console.WriteLine($"Seed: {response.Seed}");Console.WriteLine($"Base64 bytes: {response.Image.Length}");
usingvarclient=newStabilityAIClient(apiKey);// Load the source imagevarinitImageBytes=awaitFile.ReadAllBytesAsync("input.png");varimages=awaitclient.V1Generation.ImageToImageAsync(engineId:"stable-diffusion-v1-6",request:newImageToImageRequestBody{TextPrompts=[ new TextPrompt { Text = "A fantasy castle on a cliff, dramatic lighting", Weight = 1.0f, }, ],InitImage=initImageBytes,InitImagename="input.png",ImageStrength=0.35f,// Lower = closer to original, higher = more creative});foreach(varimageinimages){Console.WriteLine($"Seed: {image.Seed}, Finish reason: {image.FinishReason}");varbytes=Convert.FromBase64String(image.Base64!);awaitFile.WriteAllBytesAsync($"output_{image.Seed}.png",bytes);}
Upscale Image
1 2 3 4 5 6 7 8 9101112131415161718192021
usingvarclient=newStabilityAIClient(apiKey);// Load the image to upscalevarimageBytes=awaitFile.ReadAllBytesAsync("low-res.png");varimages=awaitclient.V1Generation.UpscaleImageAsync(engineId:"esrgan-v1-x2plus",request:newUpscaleImageRequestBody{Image=imageBytes,Imagename="low-res.png",Width=2048,// Only specify width OR height, not both});foreach(varimageinimages){Console.WriteLine($"Seed: {image.Seed}, Finish reason: {image.FinishReason}");varbytes=Convert.FromBase64String(image.Base64!);awaitFile.WriteAllBytesAsync("upscaled.png",bytes);}
usingvarclient=newStabilityAIClient(apiKey);// Load the source image and mask image (must be same dimensions)varinitImageBytes=awaitFile.ReadAllBytesAsync("input.png");varmaskImageBytes=awaitFile.ReadAllBytesAsync("mask.png");varimages=awaitclient.V1Generation.MaskingAsync(engineId:"stable-diffusion-v1-6",request:newMaskingRequestBody{TextPrompts=[ new TextPrompt { Text = "A bright blue sky with fluffy clouds", Weight = 1.0f, }, ],InitImage=initImageBytes,InitImagename="input.png",MaskImage=maskImageBytes,MaskImagename="mask.png",});foreach(varimageinimages){Console.WriteLine($"Seed: {image.Seed}, Finish reason: {image.FinishReason}");varbytes=Convert.FromBase64String(image.Base64!);awaitFile.WriteAllBytesAsync($"masked_{image.Seed}.png",bytes);}
Ecosystem maintenance
This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.
Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.
Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.