Legacy usage reference and 1.x-to-2.0 migration mapping for the DashScope Python SDK, for existing 1.x projects.
This page is for existing projects still on DashScope Python SDK 1.x. It collects the typical 1.x interface usage in one place and shows the equivalent 2.0 code.
1.x is configured via module-level globals; 2.0 is configured via
Step-by-step tasks (1.x
Step-by-step control (1.x
1.x uses a callback class (
One-shot recognition of a local file (1.x
1.x
For one-shot synthesis (short text returned as a whole), use
Batch embeddings (1.x
Beyond interface names, note the following behavior changes when migrating:
For new projects, use SDK 2.0 directly. 1.x is in frozen maintenance (defect fixes only); 1.x and 2.0 coexist in the same
dashscope package (from 2.0.1), so existing code can migrate incrementally without removing 1.x dependencies. The Assistants / Threads / Runs API family has been retired with 1.x and is no longer supported on the server side; do not use it in new code.Interface migration mapping
| Capability | 1.x interface | 2.0 interface |
|---|---|---|
| Text generation | Generation.call / AioGeneration.call | client.chat.completions.create |
| Multimodal chat | MultiModalConversation.call | client.multimodal.chat.create |
| Image generation | ImageSynthesis.call/async_call/fetch/wait | client.images.generate / client.images.jobs.* |
| Video generation | VideoSynthesis.call/async_call/fetch/wait | client.videos.generate / client.videos.jobs.* |
| Audio file transcription | Transcription.async_call/fetch/wait | client.audio.asr.transcribe / client.audio.asr.jobs.* |
| Real-time speech recognition | Recognition.start/send_audio_frame/stop | client.audio.asr.recognize(...) context manager |
| Speech synthesis | SpeechSynthesizer (tts_v2 callback style) | client.audio.tts.synthesize/stream/connect |
| Text embeddings | TextEmbedding.call / BatchTextEmbedding | client.embeddings.create / client.embeddings.jobs.* |
| Rerank | TextReRank.call | client.rerank.create |
| File management | Files.upload/list/get/delete | client.files.upload/list/get/delete |
| Model list | Models.list/get | client.models.list/get |
Client construction and authentication
1.x is configured via module-level globals; 2.0 is configured via Client constructor arguments (priority: constructor > dashscope.settings > environment variables > ~/.dashscope/config.toml).
Text generation
Multimodal chat
Image generation
async_call/fetch/wait) map to client.images.jobs.create/fetch/wait; task status changes from rsp.output.task_status == "SUCCEEDED" to job.succeeded.
Video generation
In 1.x,
VideoSynthesis extend_prompt defaults to True; in 2.0 it is prompt_extend and the default is decided by the server. Calls that relied on the old default must pass prompt_extend=True explicitly.Audio file transcription
async_call + fetch loop) maps to client.audio.asr.jobs.create + a jobs.fetch loop.
Real-time speech recognition
1.x uses a callback class (Recognition + RecognitionCallback); 2.0 uses a context manager with event iteration.
Recognition.call(file)) maps to for event in client.audio.asr.recognize_file(path, model=...):.
Speech synthesis
1.x tts_v2 collects audio through callbacks; 2.0 uses iteration or sessions.
client.audio.tts.synthesize(text, model=..., voice=...); for pure streaming, iterate bytes from client.audio.tts.stream(text, ...).
Text embeddings and rerank
BatchTextEmbedding) map to client.embeddings.jobs.create/fetch/wait. Rerank TextReRank.call maps to client.rerank.create, and results move from resp.output.results[i] to resp.results[i].
Behavior differences
Beyond interface names, note the following behavior changes when migrating:
- Error handling: 1.x checks
status_code/codeon the response object; 2.0 raises theDashScopeErrorfamily by default (e.code/e.status_code/e.request_id/e.message). For envelope-style handling, constructClient(raise_on_error=False). - Streaming: 1.x
Generation.call(stream=True)replays the full text in every frame by default (incremental_output=Trueis required for deltas); 2.0 streaming is always incremental. - Async task waiting: 1.x
waitwaits indefinitely by default and returns an error response on timeout; 2.0jobs.waithas a 24-hour budget, polls with exponential backoff, and raises when a task FAILED. - Response structure: 1.x wraps business content under
output(response.output.choices[...]); 2.0 flattens it (response.choices[...]) and adds conveniences such asresp.output_textandjob.succeeded. - Out-of-signature parameters: 2.0 resource methods have closed named signatures; model-specific parameters that 1.x passed through must use
parameters={...}(image material inputs useextra_input=).
Related documentation
- Install and upgrade: Install the SDK
- Text generation: Text generation, Streaming, Multi-turn conversation
- Image and video: Image generation, Video generation
- Speech: Audio file transcription, Real-time speech recognition, Real-time speech synthesis
- Embeddings and rerank: Embeddings, Rerank