Gemini Edit

Edit existing images using Google's Gemini 2.0 Flash model. Modify, enhance, or transform images based on text instructions.

POST
/api/v1/models/gemini/edit

Edit an existing image using text instructions

Model
Gemini 2.0 Flash
Cost
5 credits/image
Avg. Time
4-6 seconds

Request Body

NameTypeDescription
imageUrlrequiredstringURL of the image to edit (must be publicly accessible)
promptrequiredstringText instructions describing the desired edit
aspectRatiostringDefault: originalOutput aspect ratio (1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9)

Image URL Requirements

The source image must be publicly accessible via HTTPS. You can use the Upload API to get a public URL for your images.

Example Request

"text">-purple-600">curl "text-blue-600">-X POST https://vydra.app/api/v1/models/gemini/edit \
  "text-blue-600">-H "Authorization: Bearer YOUR_API_KEY" \
  "text-blue-600">-H "Content">-Type: application/json" \
  "text-blue-600">-d '{
    "imageUrl": "https://example.com/photo.jpg",
    "prompt": "Remove the background and replace it with a tropical beach at sunset",
    "aspectRatio": "16:9"
  }'

Response

200 OKjson
{
  "imageUrl": "https://pub-xxx.r2.dev/generated/gemini-edit/org_123/1706234400000.png",
  "mimeType": "image/png",
  "creditsCharged": 5,
  "durationMs": 4850
}

Common Use Cases

Background Replacement

Remove or change the background of any image.

"Replace the background with a professional office setting"

Object Removal

Remove unwanted objects from photos.

"Remove the car from the driveway"

Style Transfer

Change the artistic style of an image.

"Convert this photo to a watercolor painting style"

Object Addition

Add new elements to existing images.

"Add a golden retriever sitting in the foreground"

Color Changes

Modify colors of specific elements.

"Change the car color from blue to red"

Complete Workflow Example

Upload an image first, then edit it:

Upload and Edit Workflowjavascript
// Step 1: Upload your image
"text-purple-600">const formData = "text-purple-600">new FormData();
formData.append("text-green-600">'file', imageFile);

"text-purple-600">const uploadResponse = "text-purple-600">await fetch("text-green-600">'https://vydra.app/api/v1/upload', {
  method: "text-green-600">'POST',
  headers: {
    "text-green-600">'Authorization': "text-green-600">'Bearer YOUR_API_KEY'
  },
  body: formData
});

"text-purple-600">const { url: imageUrl } = "text-purple-600">await uploadResponse.json();

// Step 2: Edit the uploaded image
"text-purple-600">const editResponse = "text-purple-600">await fetch("text-green-600">'https://vydra.app/api/v1/models/gemini/edit', {
  method: "text-green-600">'POST',
  headers: {
    "text-green-600">'Authorization': "text-green-600">'Bearer YOUR_API_KEY',
    "text-green-600">'Content-Type': "text-green-600">'application/json'
  },
  body: JSON.stringify({
    imageUrl: imageUrl,
    prompt: "text-green-600">'Make this look like a professional headshot with soft lighting'
  })
});

"text-purple-600">const { imageUrl: editedImageUrl } = "text-purple-600">await editResponse.json();
console.log("text-green-600">'Edited image:', editedImageUrl);

Editing Tips

Be Specific About Changes

Instead of "make it better", describe exactly what you want: "increase the contrast, add warm tones, and sharpen the details".

Reference Original Elements

You can reference elements in the original image: "change the color of the house in the background" or "replace the sky while keeping the trees".

Iterative Editing

For complex edits, make changes in steps. Edit the result of one edit to make additional changes. Each edit costs 5 credits.