Google AI Integration
Learn how to upload images from Google Gemini image generation directly to easyCDN with the Node.js SDK.
Installation
Install both the easyCDN Node.js SDK and the official Google GenAI SDK:
bash
npm install @easycdn/server @google/genaiUsage
typescript
import { createClient } from '@easycdn/server'
import { GoogleGenAI } from '@google/genai'
const easyCdnClient = createClient({
secretKey: process.env.EASYCDN_SECRET_KEY!,
})
const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! })
// Generate image with Gemini
const response = await ai.models.generateContent({
model: 'gemini-2.5-flash-image',
contents: 'Generate an image of a tiny banana wearing sunglasses',
config: {
responseModalities: ['Text', 'Image'],
},
})
// Upload all images to easyCDN
const uploadedAssets = await easyCdnClient.uploadFromGoogleAi(response)
console.log('Uploaded assets:')
for (const asset of uploadedAssets) {
console.log(`- ${asset.asset.name}: ${asset.asset.url}`)
}Extended Usage
You can also use the uploadFromGoogleAi() method with additional options. You can give a custom name to each image, set a prefix for the filename, set the expiration date, and transform the image. The expiration date and transform options are the same as with normal uploads. See the API reference for more details.
typescript
const uploadedAssets = await easyCdnClient.uploadFromGoogleAi(response, {
fileNamePrefix: 'gemini-art',
expiresAt: dayjs().add(1, 'day').toISOString(),
transform: {
image: {
width: 642,
format: 'webp',
},
},
})
API Reference
For complete API documentation including all options (custom naming, transformations, expiration, progress tracking), see the uploadFromGoogleAi() reference.