Migrating from 2.x¶
3.0 is an intentional FQCN, source, and binary compatibility break. Legacy 2.x APIs other
than AgentStudio moved to com.alibaba.dashscope.legacy_2x.*, carry type-level @Deprecated
(-Xlint:deprecation shows details), and will be removed in 4.0. AgentStudio
(com.alibaba.dashscope.applications.agentstudio.*) and shared are not deprecated.
Two migration paths:
- Keep compiling now — prefix your 2.x imports with
legacy_2x(see Legacy 2.x). - Move to the 3.0 client — use the mapping table below; new code should always use 3.0.
Entry-point mapping¶
2.x class (com.alibaba.dashscope.*) |
3.0 equivalent (client.*) |
|---|---|
aigc.generation.Generation |
chat().completions().create / createStreaming |
aigc.multimodalconversation.MultiModalConversation |
multimodal().chat().create / createStreaming |
embeddings.TextEmbedding / BatchTextEmbedding |
embeddings().create |
rerank.TextReRank |
rerank().create |
aigc.imagesynthesis.ImageSynthesis |
images().generate + jobs().create / wait / fetch |
aigc.videosynthesis.VideoSynthesis |
videos().generate + jobs().* |
app.Application |
apps().completions().create / createStreaming |
decision.DecisionModel |
decision().create |
audio.asr.* / audio.tts.* / audio.qwen_tts_realtime.* |
audio().asr() / tts() / realtime() |
multimodal.tingwu.TingWu |
tingwu().jobs().create / wait |
tokenizers.* |
tokenization().count / TokenizerFactory |
assistants.* / threads.* |
no 3.0 equivalent yet — keep the legacy_2x imports |
Before / after¶
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
Generation generation = new Generation();
GenerationParam param = GenerationParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("qwen-plus")
.messages(Arrays.asList(
Message.builder().role(Role.USER.getValue()).content("Tell me a joke").build()))
.build();
GenerationResult result = generation.call(param); // throws checked ApiException
import com.alibaba.dashscope.DashScopeClient;
import com.alibaba.dashscope.types.completions.ChatCompletion;
import com.alibaba.dashscope.types.completions.ChatCompletionCreateParams;
import com.alibaba.dashscope.types.messages.Message;
// Reads DASHSCOPE_API_KEY from the config chain; one client, shared connection pool.
try (DashScopeClient client = DashScopeClient.builder().build()) {
ChatCompletion resp = client.chat().completions().create(
ChatCompletionCreateParams.builder()
.model("qwen-plus")
.messages(Collections.singletonList(Message.user("Tell me a joke")))
.build());
System.out.println(resp.outputText());
}
Key behavior changes¶
- Exceptions — checked
ApiException/NoApiKeyException/InputRequiredException→ unchecked DashScopeException family. Build the client withraiseOnError(false)to restore 2.x-style result inspection (result.isError()). - Streaming — sync
streamCallreturningFlowable→createStreamingreturning a typedResponseStream(for-each, try-with-resources). The async client still exposesFlowable. - Client lifecycle — per-capability
new Generation()objects → oneDashScopeClient(orDashScopeAsyncClient) in try-with-resources, sharing connection pool and config. - Configuration — per-param
apiKey(...)and global constants → the config chain: builder > system property > environment variable >~/.dashscope/config.toml> default.DashScopeClient.builder().build()works with justDASHSCOPE_API_KEYexported. - AgentStudio — same business package, new FQCN
com.alibaba.dashscope.applications.agentstudio.*; also reachable viaclient.agentStudio(). The 3.0baseUrldoes not apply to AgentStudio;DASHSCOPE_AGENTSTUDIO_URLoverrides its endpoint.
Where to go next¶
- Legacy 2.x — keeping existing code compiling on the 3.0 artifact.
- Errors and Diagnosis — the new exception family and retry behavior.
- Configuration — the config chain and per-request overrides.
- Archived runnable 2.x samples: examples/legacy_2x/.