Add image quality tier support for image generation models#108
Draft
adambalogh wants to merge 1 commit into
Draft
Add image quality tier support for image generation models#108adambalogh wants to merge 1 commit into
adambalogh wants to merge 1 commit into
Conversation
Expose a single `quality` request field (low/medium/high) that selects output resolution for image-generation models. Each model maps the tier to its own native size via `image_quality_sizes` in the registry: - ByteDance Seedream / Seedance and Gemini image models: 1K / 2K / 4K - Z.ai GLM-Image: 1024 / 1280 / 2048 px Models with no resolution control (xAI Grok, Gemini 2.5 Flash Image) ignore the option. The `medium` tier mirrors each model's previous default, so omitting `quality` is unchanged. The field is folded into the signed request hash, validated up front (clean 400 on bad values), and documented in the OpenAPI spec. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ENGmJDbJJHAM89HSGQuoeF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
qualityrequest parameter (low|medium|high) to image generation endpoints, allowing callers to control output resolution across multiple providers. Each model maps the simple quality tier to its provider-specific size format via a newimage_quality_sizesfield inModelConfig.Key Changes
Model Registry (
model_registry.py):image_quality_sizes: Optional[dict[str, str]]field toModelConfigto map quality tiers to provider-specific resolution strings1K/2K/4K), Z.ai GLM-Image (1024x1024/1280x1280/2048x2048), and Gemini Nano Banana (1K/2K/4K)VALID_IMAGE_QUALITIESconstant andresolve_image_size()helper function to validate and map quality tiers to model-specific sizesLLM Backend (
llm_backend.py):get_chat_model_cached()to acceptimage_qualityparameter and pass resolved image size to Gemini'simage_configgenerate_images()to acceptqualityparameter and apply size overrides to provider payloads (Z.ai, Seedance, Seedream)Chat Controller (
chat_controller.py):qualityfield inCreateChatCompletionRequestwith clean 400 error response for invalid valuesqualityparameter through both streaming and non-streaming image generation pathsAPI Models (
create_chat_completion_request.py):qualityfield toCreateChatCompletionRequestPydantic modelOpenAPI Spec (
openapi.yaml):qualityparameter with enum values and provider-specific resolution mappingsTests (
test_image_generation.py):Documentation (
CLAUDE.md):Implementation Details
resolve_image_size(), which validates the tier and looks up the model's provider-specific size stringmediumtier is configured to match each model's previous hardcoded default, ensuring backward compatibility whenqualityis omittedimage_quality_sizesconfigured (e.g., xAI Grok) returnNonefromresolve_image_size(), causing the provider default to be usedhttps://claude.ai/code/session_01ENGmJDbJJHAM89HSGQuoeF