Skip to content

feat(dashscope): add qwen-image-edit-plus image edits and qwen3-tts-vc tts - #33862

Closed
devin-ai-integration[bot] wants to merge 2 commits into
litellm_oss_daily_2026_07_17from
litellm_dashscope_image_edit_tts
Closed

devin-ai-integration[bot] wants to merge 2 commits into
litellm_oss_daily_2026_07_17from
litellm_dashscope_image_edit_tts

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Screenshots / Proof of Fix

Live e2e proof against DashScope is pending a DASHSCOPE_API_KEY; none is provisioned in this environment. Once a key is available the runbook below reproduces both flows against the real API

# image edit -> /v1/images/edits
curl http://localhost:4000/v1/images/edits \
  -H "Authorization: Bearer sk-1234" \
  -F model="dashscope/qwen-image-edit-plus" \
  -F prompt="add falling snow" \
  -F image="@cat.png"

# tts -> /v1/audio/speech
curl http://localhost:4000/v1/audio/speech \
  -H "Authorization: Bearer sk-1234" \
  -H "Content-Type: application/json" \
  -d '{"model":"dashscope/qwen3-tts-vc","input":"hello from litellm","voice":"<enrolled_voice_id>"}' \
  --output out.wav

Type

🆕 New Feature

Changes

Adds two new DashScope surfaces on top of the existing image generation support

qwen-image-edit-plus is wired to the standardized /v1/images/edits route through a new DashScopeImageEditConfig. DashScope has no OpenAI-style edit endpoint; it uses the multimodal-generation endpoint, so the config sends JSON (not multipart), base64-encodes each input image into a data: URL under input.messages[].content, and normalizes the returned image URLs back into an ImageResponse. Multiple input images are supported. It is registered in ProviderConfigManager.get_provider_image_edit_config, and the generic image_edit_handler path picks it up

qwen3-tts-vc is wired to /v1/audio/speech through a new DashScopeTextToSpeechConfig. DashScope TTS is not OpenAI-compatible; it posts {"model", "input": {"text", "voice", ...}} to the multimodal-generation endpoint and returns an audio file URL valid for 24h, so the response transform downloads that URL and returns the bytes as HttpxBinaryResponseContent. -vc is voice cloning, so voice carries a pre-enrolled custom voice id and extra DashScope-specific fields pass through extra_body. Registered in get_provider_text_to_speech_config plus a dispatch branch in speech() mirroring the other config-based TTS providers

DashScope is listed in openai_compatible_providers for chat and embeddings, and the speech() OpenAI-compatible branch would otherwise intercept the TTS call and post the wrong request shape, so that branch now excludes dashscope and lets the dedicated config handle it

Model metadata for dashscope/qwen-image-edit-plus (image_generation, edits + generations endpoints) and dashscope/qwen3-tts-vc (audio_speech) is added to both the canonical and backup cost maps

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/9582d90df7974fb6a678a8a8e4e10372

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

CLAassistant commented Jul 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ Mubashir Osmani
❌ devin-ai-integration[bot]


Mubashir Osmani seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

…c tts

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_dashscope_image_edit_tts branch from 07878cd to b5f3ea6 Compare July 18, 2026 22:10
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to litellm_oss_daily_2026_07_17 July 18, 2026 22:10
@greptile-apps

greptile-apps Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds two new DashScope surfaces: image editing via qwen-image-edit-plus (routed through /v1/images/edits) and text-to-speech via qwen3-tts-vc (routed through /v1/audio/speech). Both features use DashScope's multimodal-generation endpoint rather than OpenAI-compatible endpoints and are wired through litellm's config-based provider system.

  • DashScopeImageEditConfig base64-encodes input images into a JSON request body and parses the returned image URLs back into an ImageResponse; the _read_all_bytes helper only covers bytes, BytesIO, and BufferedReader, silently rejecting the tuple and PathLike variants that FileTypes includes.
  • DashScopeTextToSpeechConfig posts to DashScope, then downloads the returned audio URL via a raw httpx.get() call inside transform_text_to_speech_response; this blocking call runs on the asyncio event loop when aspeech=True is used and also bypasses litellm's HTTP infrastructure (retries, proxy, OTEL tracing).
  • Model metadata entries and provider registrations in utils.py and main.py follow existing patterns correctly.

Confidence Score: 3/5

Not safe to merge as-is: the TTS response transform makes a blocking network call that stalls the event loop on every async TTS request, and the image-edit helper will raise an unhelpful error for standard tuple-style file inputs.

The TTS audio download uses a raw synchronous httpx.get() inside transform_text_to_speech_response, which is called directly from async_text_to_speech_handler. This will freeze the event loop for up to 60 seconds on any aspeech call, making async TTS effectively unusable. The same call also bypasses litellm's retry, proxy, and tracing infrastructure. Separately, _read_all_bytes in the image-edit config silently raises ValueError for the tuple and PathLike variants that FileTypes explicitly includes, so users passing files the standard way (e.g. ("image.png", bytes)) will get an opaque error with no fix hint.

litellm/llms/dashscope/text_to_speech/transformation.py (blocking HTTP download in response transform) and litellm/llms/dashscope/image_edit/transformation.py (_read_all_bytes incomplete FileTypes coverage).

Important Files Changed

Filename Overview
litellm/llms/dashscope/text_to_speech/transformation.py New DashScope TTS config; contains a blocking httpx.get() call inside transform_text_to_speech_response that stalls the async event loop and bypasses litellm's HTTP infrastructure.
litellm/llms/dashscope/image_edit/transformation.py New DashScope image-edit config; _read_all_bytes does not handle tuple or PathLike variants of FileTypes, causing silent ValueError for common caller patterns; type signature for image also under-specifies the accepted list variant.
litellm/main.py Adds a dashscope TTS dispatch branch, consistent with the existing minimax/aws_polly pattern; no functional issues in the dispatch code itself.
litellm/utils.py Registers dashscope in get_provider_image_edit_config and get_provider_text_to_speech_config following existing provider patterns; straightforward and correct.
tests/test_litellm/llms/dashscope/test_dashscope_image_edit_transformation.py Unit tests use mocks throughout; covers request building, response parsing, error paths; no real network calls.
tests/test_litellm/llms/dashscope/test_dashscope_text_to_speech_transformation.py Unit tests properly patch httpx.get; covers TTS request shape, audio download, and error cases; no real network calls.
model_prices_and_context_window.json Adds metadata for two new dashscope models; supported endpoints look correct.
litellm/model_prices_and_context_window_backup.json Mirror of the canonical model prices file; same additions, consistent.

Reviews (1): Last reviewed commit: "feat(dashscope): add qwen-image-edit-plu..." | Re-trigger Greptile

Comment on lines +152 to +157
raise self.get_error_class(
error_message=str(response_json.get("message", response_json)),
status_code=raw_response.status_code,
headers=raw_response.headers,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Synchronous HTTP download blocks event loop in async path

transform_text_to_speech_response is called directly from async_text_to_speech_handler (llm_http_handler.py:11495) without await. The httpx.get(audio_url, timeout=60.0) call is a blocking network request — it will stall the entire asyncio event loop for up to 60 seconds on every aspeech call, preventing other coroutines from running. Beyond the async problem, the raw httpx.get usage bypasses litellm's HTTP infrastructure (retries, proxy configuration, OTEL tracing), violating the project rule that custom HTTP handlers must reuse litellm's existing HTTP handler layer.

Rule Used: What: Block any PR which writes it's own custom ht... (source)

Comment on lines +175 to +183
{
"image": "data:{};base64,{}".format(
ImageEditRequestUtils.get_image_content_type(img),
base64.b64encode(self._read_all_bytes(img)).decode("utf-8"),
)
}
for img in images
if img is not None
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 _read_all_bytes silently rejects valid FileTypes variants

FileTypes is a union that includes PathLike, IO[bytes], and tuple forms like (filename, bytes) and (filename, bytes, content_type). Any caller who passes a standard file tuple (the most common form from HTTP multipart clients) or a pathlib.Path reaches the final raise ValueError("Unsupported image type for DashScope image edit.") with no useful hint about what went wrong. Handling only the bytes / BytesIO / BufferedReader subset means most real-world FileTypes values will fail at runtime.

Comment on lines +111 to +115
def transform_image_edit_request(
self,
model: str,
prompt: str | None,
image: FileTypes | None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The image parameter is typed as FileTypes | None (matching the base class), but _prepare_image_parts silently accepts a list[FileTypes] — the tests already exercise this path with two images. The public signature should advertise the list variant so callers know it is supported and static type checkers don't flag list arguments.

Suggested change
def transform_image_edit_request(
self,
model: str,
prompt: str | None,
image: FileTypes | None,
def transform_image_edit_request(
self,
model: str,
prompt: str | None,
image: FileTypes | list[FileTypes] | None,

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Review (LIT-4580)

Recommendation: request changes. One blocker, plus a scope gap against the ticket

Blocker

Async TTS stalls the event loop. transform_text_to_speech_response in litellm/llms/dashscope/text_to_speech/transformation.py downloads the audio with a synchronous httpx.get(audio_url, timeout=60.0). That method is invoked from async_text_to_speech_handler (litellm/llms/custom_httpx/llm_http_handler.py:11495) with no await, so every aspeech=True call blocks the whole asyncio loop for up to 60s. It also uses raw httpx instead of litellm's shared HTTP handler, so it skips retries, proxy config, and logging/tracing, which is the same thing Greptile flagged. The unit test hides this because it patches httpx.get; a real proxy call would freeze. The base transform_text_to_speech_response hook is sync, so fixing this properly likely means adding an async download path (e.g. do the second fetch in the async handler via get_async_httpx_client, or add an async response-transform hook) rather than a blocking call inside the transform

Requirements gap

The ticket asks for dashscope image + TTS (qwen-image-2.0, qwen-image-edit-plus, qwen3-tts-vc), byteplus seedream, pruna, and novita image models. This PR only adds qwen-image-edit-plus (edits) and qwen3-tts-vc (TTS). qwen-image-2.0, byteplus seedream, pruna, and novita are not here, and I could not find sibling PRs for them. Please confirm whether those are tracked elsewhere or still outstanding

Minor

  • No pricing on the new cost-map entries (dashscope/qwen-image-edit-plus, dashscope/qwen3-tts-vc) in either the canonical or backup map, so spend tracking reports $0 for these models. Add cost fields if the pricing is published
  • Error-class inconsistency: DashScopeImageEditConfig does not override get_error_class, so raise self.get_error_class(...) calls the base method, which itself raises a generic BaseLLMException; the outer raise is dead code and image-edit errors surface as BaseLLMException rather than DashScopeError. The TTS config overrides get_error_class to return a DashScopeError. Mirror that in the image-edit config for consistent error typing

Nitpicks

  • _read_all_bytes only handles bytes / BytesIO / BufferedReader and raises for tuple / PathLike FileTypes variants. Greptile flagged this, but it is a verbatim copy of the existing gemini/image_edit config, so it matches current codebase precedent (image bytes are normalized upstream before reaching the transform). Not blocking; if you want to harden it, do both configs and factor out the shared helper since it is now duplicated
  • Greptile P2: transform_image_edit_request's image param is typed FileTypes | None while _prepare_image_parts accepts lists (tests pass two images). The base signature is Optional[FileTypes], so widening the override diverges from base; low priority either way

Good

Clean config-based wiring, registered in both ProviderConfigManager hooks, JSON-vs-multipart handled correctly for the multimodal-generation endpoint, in-band error-code handling on 200 responses, both canonical and backup cost maps updated, and the 17 unit tests pass locally

Note: the failing osv-scan check is preexisting (vulnerable mcp 1.26.0 in uv.lock), unrelated to this diff

@codecov

codecov Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.40741% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...itellm/llms/dashscope/image_edit/transformation.py 81.96% 11 Missing ⚠️
...lm/llms/dashscope/text_to_speech/transformation.py 88.23% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

… speech dispatch

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@codspeed

codspeed Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_dashscope_image_edit_tts (b5f3ea6) with litellm_oss_daily_2026_07_17 (1ebf2a7)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant