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

# Edit Document Visual

`POST /api/document/edit-visual`

## Request

- Base URL: `https://api.qomplement.com` (the document declares no server; this is the origin it was published from)
- URL: `https://api.qomplement.com/api/document/edit-visual`
- Auth: none declared

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

## Request body `multipart/form-data`

- BodyEditDocumentVisualApiDocumentEditVisualPost
  - `file` string, binary, nullable: Document image to edit (JPEG, PNG, WebP, or PDF)
  - `document_id` string, nullable: Document ID to fetch from S3 (alternative to file upload)
  - `batch_id` string, nullable: Batch ID for document (used with document_id)
  - `page_number` integer: Page number to edit (for multi-page documents)
  - `changes` string, required: JSON array of field changes: [{fieldName, oldValue, newValue}]
  - `user_id` string, required: User ID for file organization
  - `original_document_id` string: Original document ID for tracking

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/qomplement/apis/qomplement-api.md) - [All operations](https://skmtc.dev/qomplement/apis/qomplement-api/llms.txt) - [OpenAPI document](https://skmtc.dev/qomplement/apis/qomplement-api/revisions/6fe617c112ef?raw)
