Generate images from text prompts using various AI models.
const response = await client.images.generate({
model: "google-imagen-4.0",
prompt: "A serene mountain lake at sunset",
n: 1,
response_format: "url",
});
console.log(response.data[0].url);
console.log(response.cost);
| Parameter | Type | Description |
|---|---|---|
prompt |
string |
Text description of the image |
model |
string |
Image generation model |
n |
number |
Number of images to generate |
size |
string |
Image dimensions (e.g. 1024x1024) |
quality |
'standard' | 'hd' |
Image quality level |
style |
'vivid' | 'natural' |
Image style |
response_format |
'url' | 'b64_json' |
How to receive the image |
interface ImageGenerationResponse {
created: number;
data: ImageObject[];
model: string;
cost: number;
}
interface ImageObject {
url?: string;
b64_json?: string;
}
To receive the image as base64 data instead of a URL:
const response = await client.images.generate({
model: "google-imagen-4.0",
prompt: "A futuristic city skyline",
response_format: "b64_json",
});
const imageData = response.data[0].b64_json;
// Use as data URI: `data:image/png;base64,${imageData}`
No headings found on this page.
