googleapis / googleapis/python-genai

Support output_compression_quality in Gemini API

Open
#2,346 2 comments 0 reactions 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p3 type: feature request
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

The `ImageConfig` currently includes fields like `output_mime_type` and `output_compression_quality`, but they are not supported in the Gemini API, as noted in the source code:
```
output_mime_type: Optional[str] = Field(
default=None,
description="""MIME type of the generated image. This field is not
supported in Gemini API.""",
)
output_compression_quality: Optional[int] = Field(
default=None,
description="""Compression quality of the generated image (for
``image/jpeg`` only). This field is not supported in Gemini API.""",
)
```
See: https://github.com/googleapis/python-genai/blob/main/google/genai/types.py#L5431

### Use Case

In production, we generate a large number of images via Gemini API.

Network bandwidth is a major cost factor.
Being able to control output compression would significantly reduce traffic and cost.

### Observation

From testing with `gemini-3.1-flash-image-preview`, the output appears to be JPEG with very high quality (likely close to 100).

Example:

```python
data = part.inline_data.data
mime_type = part.inline_data.mime_type
print(f'output inline_data: mime={mime_type}, bytes={len(data)}, MB={len(data)/1024/1024:.2f}')
```

Result:
```
output inline_data: mime=image/jpeg, bytes=3667955, MB=3.50
```

However, re-encoding the same image locally using:
```python
image.save(..., format="JPEG", quality=92)
```
produces a file of only ~773 KB **(~4× smaller)** with no noticeable visual degradation.

Actually, the final image I delivered to end user is compressed with jpeg quality 92, and it is clear enough.

### Problem

* The API always returns high-quality images
* Developers cannot control compression level
* This leads to:
* Significant network overhead
* Higher proxy / egress cost
* Unnecessary bandwidth usage at scale

### Proposal

Support the following fields in ImageConfig:

* output_mime_type (e.g. image/jpeg)
* output_compression_quality (e.g. 80–95)

Even a simple implementation (JPEG-only, best-effort quality) would already be very valuable.

### Additional Benefit

Reducing output size could also:

* Improve latency (faster response transfer)
* Reduce server/network load
* Improve scalability of high-throughput applications

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.