Guide · Amazon Bedrock · Amazon Nova
MCP Server Amazon Nova Canvas — image generation, inpainting, and background removal
Amazon Nova Canvas is an image generation and editing model available through Amazon Bedrock that supports six distinct task types: text-to-image, image variation, inpainting, outpainting, background removal, and color-guided generation. Nova Canvas does not use the Converse API — it uses InvokeModelCommand from @aws-sdk/client-bedrock-runtime with a JSON request body, and returns base64-encoded PNG images in a JSON response. Three aspects trip up MCP server authors new to Nova Canvas: the request body must be JSON-serialized to a string and then encoded as a Uint8Array before passing to InvokeModelCommand; cfgScale range is 1.1–10.0, not the 0–1 range common in diffusion model APIs; and image dimensions must exactly match one of Nova Canvas's supported sizes — passing an arbitrary width and height returns a ValidationException before any generation occurs. This guide covers all six task types with complete TypeScript examples, the correct request structure, response decoding, and production gotchas for each operation. For text generation and reasoning see Nova Pro; for multimodal analysis see Nova Lite.
TL;DR
Model ID: amazon.nova-canvas-v1:0. Use InvokeModelCommand (not Converse). Encode the JSON request body as a Uint8Array. Set accept: "application/json" and contentType: "application/json". Decode the response body from bytes to JSON, then base64-decode each image. cfgScale: 1.1–10.0. Dimensions must match supported sizes exactly.
Client setup and request format
Nova Canvas uses InvokeModelCommand, not ConverseCommand. The request body is a JSON object serialized to a string and encoded as bytes. The response body is similarly bytes that must be decoded to JSON, then each image extracted as a base64 string:
import {
BedrockRuntimeClient,
InvokeModelCommand,
} from "@aws-sdk/client-bedrock-runtime";
const client = new BedrockRuntimeClient({ region: "us-east-1" });
const MODEL_ID = "amazon.nova-canvas-v1:0";
// Note: Nova Canvas does NOT support cross-region inference profile IDs
// (us.amazon.nova-canvas-v1:0 is not valid — use the bare model ID)
async function invokeCanvas(requestBody: object): Promise {
const response = await client.send(new InvokeModelCommand({
modelId: MODEL_ID,
contentType: "application/json",
accept: "application/json",
body: new TextEncoder().encode(JSON.stringify(requestBody)),
}));
const responseJson = JSON.parse(new TextDecoder().decode(response.body));
if (responseJson.error) {
throw new Error(`Nova Canvas error: ${responseJson.error}`);
}
// Response contains an images array; each element is a base64 PNG string
return (responseJson.images as string[]);
}
// Helper to save a base64 image to disk
import * as fs from "fs";
function saveBase64Image(base64: string, outputPath: string): void {
fs.writeFileSync(outputPath, Buffer.from(base64, "base64"));
}
Supported image dimensions
Nova Canvas requires dimensions from a fixed set of supported sizes. Passing arbitrary dimensions raises a ValidationException. Common supported sizes include:
// Supported square sizes
// 512×512, 768×768, 1024×1024
// Supported landscape sizes (width × height)
// 1024×512, 1280×720, 1280×768, 1152×896, 1216×832, 1344×768, 1536×640
// Supported portrait sizes (width × height)
// 512×1024, 768×1280, 768×1152, 832×1216, 768×1344, 640×1536
const SUPPORTED_SIZES = [
{ width: 1024, height: 1024 }, // Most common for general use
{ width: 1280, height: 720 }, // 16:9 landscape
{ width: 768, height: 1344 }, // 9:16 portrait
{ width: 1024, height: 512 }, // 2:1 banner
] as const;
TEXT_IMAGE: text-to-image generation
The most common task type generates an image from a text prompt. The request specifies taskType: "TEXT_IMAGE", a textToImageParams block with the prompt and optional negative prompt, and an imageGenerationConfig block with dimensions, cfgScale, and seed:
interface TextToImageRequest {
taskType: "TEXT_IMAGE";
textToImageParams: {
text: string; // positive prompt, max 1024 characters
negativeText?: string; // what to avoid, max 1024 characters
};
imageGenerationConfig: {
width: number;
height: number;
cfgScale: number; // 1.1–10.0 (higher = more prompt-adherent, less creative)
seed?: number; // 0–858993459, omit for random
numberOfImages?: number; // 1–5 (default 1)
quality?: "standard" | "premium"; // premium costs more, higher quality
};
}
async function generateImage(
prompt: string,
options: {
negativePrompt?: string;
width?: number;
height?: number;
cfgScale?: number;
quality?: "standard" | "premium";
} = {}
): Promise {
const {
negativePrompt,
width = 1024,
height = 1024,
cfgScale = 7.0,
quality = "standard",
} = options;
const request: TextToImageRequest = {
taskType: "TEXT_IMAGE",
textToImageParams: {
text: prompt,
...(negativePrompt ? { negativeText: negativePrompt } : {}),
},
imageGenerationConfig: {
width,
height,
cfgScale,
numberOfImages: 1,
quality,
},
};
const images = await invokeCanvas(request);
return Buffer.from(images[0], "base64");
}
// MCP tool
server.tool(
"generate_image",
{
prompt: z.string().max(1024),
negativePrompt: z.string().max(1024).optional(),
width: z.number().int().optional().default(1024),
height: z.number().int().optional().default(1024),
quality: z.enum(["standard", "premium"]).optional().default("standard"),
},
async ({ prompt, negativePrompt, width, height, quality }) => {
const imageBuffer = await generateImage(prompt, { negativePrompt, width, height, quality });
// Return as base64-encoded data URL for the calling agent
return {
content: [{
type: "text",
text: `data:image/png;base64,${imageBuffer.toString("base64")}`,
}],
};
}
);
The cfgScale parameter controls adherence to the prompt versus creative freedom. Values near 1.1 produce more varied, creative results; values near 10.0 produce images that closely follow the literal prompt. For product photography with specific requirements, 7.0–8.5 is a good starting range. For stylized art generation, 4.0–6.0 gives more creative interpretation.
BACKGROUND_REMOVAL
Background removal isolates the subject of an image against a transparent background. The output is a PNG with an alpha channel. No text prompt is required — Nova Canvas uses computer vision to identify the foreground subject:
interface BackgroundRemovalRequest {
taskType: "BACKGROUND_REMOVAL";
backgroundRemovalParams: {
image: string; // base64-encoded source image (JPEG or PNG)
};
}
async function removeBackground(imageBuffer: Buffer): Promise {
const request: BackgroundRemovalRequest = {
taskType: "BACKGROUND_REMOVAL",
backgroundRemovalParams: {
image: imageBuffer.toString("base64"),
},
};
const images = await invokeCanvas(request);
return Buffer.from(images[0], "base64");
}
server.tool(
"remove_background",
{
imageBase64: z.string().describe("Base64-encoded JPEG or PNG image"),
},
async ({ imageBase64 }) => {
const sourceBuffer = Buffer.from(imageBase64, "base64");
const resultBuffer = await removeBackground(sourceBuffer);
return {
content: [{
type: "text",
text: `data:image/png;base64,${resultBuffer.toString("base64")}`,
}],
};
}
);
Background removal works best on images with a clearly defined subject — portraits, product photos on plain backgrounds, and objects against contrasting surfaces. Images with complex backgrounds or transparent/glass subjects may produce imperfect masks. The output is always PNG regardless of the input format, since PNG supports the alpha channel required for transparency.
Unlike text-to-image, background removal does not use an imageGenerationConfig block. The output dimensions match the input image dimensions — no resizing occurs.
COLOR_GUIDED_GENERATION
Color-guided generation produces images that adhere to a specified palette of hex colors. This is useful for brand-consistent image generation where the color scheme must match a style guide:
interface ColorGuidedRequest {
taskType: "COLOR_GUIDED_GENERATION";
colorGuidedGenerationParams: {
text: string;
negativeText?: string;
referenceImage?: string; // optional base64 reference image
colors: string[]; // array of hex color strings, e.g. ["#1A1A2E", "#16213E"]
};
imageGenerationConfig: {
width: number;
height: number;
cfgScale: number;
seed?: number;
numberOfImages?: number;
quality?: "standard" | "premium";
};
}
async function generateColorGuided(
prompt: string,
colors: string[], // hex values like "#FF5733"
width = 1024,
height = 1024,
): Promise {
if (colors.length === 0 || colors.length > 10) {
throw new Error("colors array must have 1–10 hex color values");
}
// Validate hex format
const hexPattern = /^#[0-9A-Fa-f]{6}$/;
for (const color of colors) {
if (!hexPattern.test(color)) {
throw new Error(`Invalid hex color: ${color} — must be #RRGGBB format`);
}
}
const request: ColorGuidedRequest = {
taskType: "COLOR_GUIDED_GENERATION",
colorGuidedGenerationParams: { text: prompt, colors },
imageGenerationConfig: { width, height, cfgScale: 6.5, numberOfImages: 1 },
};
const images = await invokeCanvas(request);
return Buffer.from(images[0], "base64");
}
Colors must be provided as exact #RRGGBB hex strings — shorthand hex (#RGB) and named colors ("blue") are not accepted. Nova Canvas interprets the colors as a palette to draw from rather than strict per-pixel constraints; the generated image will reflect the dominant hues but won't match exact pixel values.
INPAINTING and OUTPAINTING
Inpainting replaces a masked region of an existing image with AI-generated content. Outpainting extends an existing image beyond its borders. Both require a source image and a mask:
interface InpaintingRequest {
taskType: "INPAINTING";
inPaintingParams: {
text: string; // what to generate inside the mask
negativeText?: string;
image: string; // base64 source image
maskPrompt?: string; // text description of the region to inpaint
maskImage?: string; // base64 black/white mask (white = replace)
};
imageGenerationConfig: {
width: number;
height: number;
cfgScale: number;
seed?: number;
numberOfImages?: number;
};
}
// Inpainting via mask prompt (no mask image required)
async function inpaintWithPrompt(
sourceImage: Buffer,
regionDescription: string,
replacementPrompt: string,
width: number,
height: number,
): Promise {
const request: InpaintingRequest = {
taskType: "INPAINTING",
inPaintingParams: {
text: replacementPrompt,
image: sourceImage.toString("base64"),
maskPrompt: regionDescription, // e.g. "the red car in the foreground"
},
imageGenerationConfig: { width, height, cfgScale: 7.0, numberOfImages: 1 },
};
const images = await invokeCanvas(request);
return Buffer.from(images[0], "base64");
}
// Outpainting extends the image — provide direction via text
interface OutpaintingRequest {
taskType: "OUTPAINTING";
outPaintingParams: {
text: string;
negativeText?: string;
image: string;
maskImage?: string;
outPaintingMode?: "DEFAULT" | "PRECISE";
};
imageGenerationConfig: {
width: number;
height: number;
cfgScale: number;
seed?: number;
numberOfImages?: number;
};
}
For inpainting, you can specify either a maskPrompt (a text description of the region to replace, which Nova Canvas interprets via segmentation) or a maskImage (a binary image where white pixels indicate the area to replace and black pixels preserve the original). The mask image must be the same dimensions as the source image. Using maskPrompt is simpler but less precise; use maskImage when pixel-accurate control is required.
IMAGE_VARIATION
Image variation generates new images that maintain the style and subject of a reference image while introducing variation. This is useful for generating alternative versions of product photos or creating consistent visual sets:
interface ImageVariationRequest {
taskType: "IMAGE_VARIATION";
imageVariationParams: {
text?: string; // optional prompt to guide variation direction
negativeText?: string;
images: string[]; // base64 reference images (1–5)
similarityStrength?: number; // 0.2–1.0 (higher = more similar to reference)
};
imageGenerationConfig: {
width: number;
height: number;
cfgScale: number;
seed?: number;
numberOfImages?: number;
};
}
async function generateVariation(
referenceImages: Buffer[],
prompt?: string,
similarityStrength = 0.7,
width = 1024,
height = 1024,
): Promise {
if (referenceImages.length === 0 || referenceImages.length > 5) {
throw new Error("IMAGE_VARIATION requires 1–5 reference images");
}
const request: ImageVariationRequest = {
taskType: "IMAGE_VARIATION",
imageVariationParams: {
images: referenceImages.map((b) => b.toString("base64")),
similarityStrength,
...(prompt ? { text: prompt } : {}),
},
imageGenerationConfig: {
width,
height,
cfgScale: 6.0,
numberOfImages: 1,
},
};
const images = await invokeCanvas(request);
return images.map((b64) => Buffer.from(b64, "base64"));
}
similarityStrength controls how closely the variation adheres to the reference. At 1.0, the output is nearly identical to the reference (useful for style consistency). At 0.2, the output uses only broad style cues and introduces significant variation. For product photo sets, 0.6–0.8 produces distinct images that clearly share the same subject and style.
Production gotchas
Nova Canvas does not support cross-region inference profile IDs
Unlike Nova Micro, Lite, and Pro — which all support us.amazon.nova-* cross-region inference profile IDs — Nova Canvas must be invoked with its single-region model ID amazon.nova-canvas-v1:0. Passing us.amazon.nova-canvas-v1:0 returns a ResourceNotFoundException: Could not resolve model identifier. Canvas has its own throughput quotas per region; if throttling becomes a problem, check your Bedrock service quotas for the Canvas model specifically.
cfgScale minimum is 1.1, not 0
Nova Canvas's cfgScale range starts at 1.1, not 0. Passing values below 1.1 returns ValidationException: cfgScale must be between 1.1 and 10.0. This range is intentionally different from common diffusion model APIs that use 0–1 or 1–20 ranges. Many teams copy cfgScale values from other image generation services and hit this error immediately — validate cfgScale before passing it to Nova Canvas if the value comes from user input or external configuration.
Request body encoding: bytes not string
The body parameter of InvokeModelCommand must be a Uint8Array, not a plain string. Passing a JSON string directly raises a TypeScript compile error (the type is Uint8Array | Blob | ReadableStream). Always use new TextEncoder().encode(JSON.stringify(requestBody)) to encode the JSON. Similarly, decode the response with new TextDecoder().decode(response.body) before JSON.parse().
Image dimensions must exactly match supported sizes
Requesting a dimension not in Nova Canvas's supported list (for example, 800×600 or 1200×628) returns ValidationException: Unsupported image dimensions. The closest standard sizes to common use cases: 1280×720 for 16:9, 768×1344 for 9:16 mobile, 1024×1024 for square, 1024×512 for banner. Build a dimension selector that maps user-specified aspect ratios to the nearest supported size rather than accepting freeform dimensions.
Prompt text limit is 1024 characters, not tokens
The text and negativeText fields in image generation params accept a maximum of 1024 characters each — not 1024 tokens. For detailed prompts, this is a tighter constraint than it appears. Count characters, not words. Prompts exceeding 1024 characters return ValidationException: Text prompt exceeds maximum length.
Monitor your Nova Canvas MCP tools with AliveMCP
AliveMCP monitors MCP server endpoints that wrap image generation workflows. When a Nova Canvas tool starts failing or returning throttling errors, AliveMCP alerts you so you can respond before image generation workflows stall.
Start free monitoring