---
title: "Edit Document Visual"
method: POST
path: "/api/document/edit-visual"
tags: ["Gemini Document Editor"]
---

# Edit Document Visual

`POST /api/document/edit-visual`

Visually edit a document using Gemini 2.5 Flash Image API

This endpoint:
1. Receives a document image + list of field changes
2. Builds an intelligent prompt with strict formatting preservation
3. Calls Gemini 2.5 Flash Image to generate edited version
4. Saves edited document to S3 with 'edited' metadata
5. Returns document metadata with S3 URL for download

Example request:
```
POST /api/document/edit-visual
Content-Type: multipart/form-data

file: [document.jpg]
changes: [
    {"fieldName": "Name", "oldValue": "Andres", "newValue": "Fernando"},
    {"fieldName": "Total", "oldValue": "100.00", "newValue": "150.00"}
]
user_id: "user_123"
original_document_id: "doc_456" (optional)
```

Args:
    file: Document image file to edit
    changes: JSON string of field changes [{fieldName, oldValue, newValue}]
    user_id: User ID for S3 file organization
    original_document_id: Optional original document ID for tracking
    s3_storage: S3Storage instance (injected)

Returns:
    JSON with edited document metadata:
    - document_id: Unique ID for edited document
    - s3_url: Download URL for edited document
    - s3_key: S3 storage key
    - is_edited: True (tagged as edited)
    - changes_applied: Number of field changes
    - changes: List of changes applied

Raises:
    HTTPException: If Gemini API call fails or invalid input

## Response `200`

Successful Response

- unknown

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/qomplement/apis/fastapi.md) · [All operations](https://skmtc.net/qomplement/apis/fastapi/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/qomplement/fastapi/revisions/718de1c0d866/schema)
