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 (former
1.x uses callback classes (
One-shot local file recognition (1.x
1.x
One-shot synthesis uses
Batch embeddings (1.x
Streaming application calls keep the
Beyond interface names, note these behavioral differences when migrating:
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 |
| Agent application | Application.call | client.apps.completions.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 callback classes (Recognition + RecognitionCallback); 2.0 uses a context manager + event iteration.
Recognition.call(file)) maps to for event in client.audio.asr.recognize_file(path, model=...):.
Speech synthesis
1.x tts_v2 receives audio via callbacks; 2.0 uses iteration/session style.
client.audio.tts.synthesize(text, model=..., voice=...); pure streaming iterates client.audio.tts.stream(text, ...).
Embeddings and rerank
BatchTextEmbedding) map to client.embeddings.jobs.create/fetch/wait. Rerank TextReRank.call maps to client.rerank.create, with results moving from resp.output.results[i] to resp.results[i].
Agent application calls
incremental_output parameter (it decides the frame shape); per-frame output moves from response.output.text to partial.text.
Behavioral differences
Beyond interface names, note these behavioral differences when migrating:
- Error handling: 1.x checks
status_code/codeon the response; 2.0 raises theDashScopeErrorfamily by default (withe.code/e.status_code/e.request_id/e.message). For envelope-style behavior, constructClient(raise_on_error=False). - Streaming output: 1.x
Generation.call(stream=True)replays the full text on every frame by default (incremental_output=Truefor deltas); 2.0 streams are always incremental. Bailian applications (apps.completions) keep theincremental_outputswitch. - Async task waiting: 1.x
waitwaits indefinitely by default and returns an error response on timeout; 2.0jobs.waithas a default 24-hour budget, exponential backoff polling, and raises on FAILED tasks. - Response shape: 1.x wraps payload content under
output(response.output.choices[...]); 2.0 is flat (response.choices[...]) with conveniences likeresp.output_textandjob.succeeded. - Non-signature parameters: 2.0 resource methods have closed named signatures; model-specific parameters passed through in 1.x must go via
parameters={...}(image materials viaextra_input=).
Related documentation
- Install and upgrade: Install the SDK
- Text generation: Text generation, Streaming output, Multi-turn conversation
- Images and video: Image generation, Video generation
- Speech: Audio file transcription, Real-time speech recognition, Real-time TTS
- Embeddings and rerank: Embeddings, Rerank
- Application calls: Application Calling