Skip to content

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:

  1. Keep compiling now — prefix your 2.x imports with legacy_2x (see Legacy 2.x).
  2. 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 with raiseOnError(false) to restore 2.x-style result inspection (result.isError()).
  • Streaming — sync streamCall returning Flowable → createStreaming returning a typed ResponseStream (for-each, try-with-resources). The async client still exposes Flowable.
  • Client lifecycle — per-capability new Generation() objects → one DashScopeClient (or DashScopeAsyncClient) 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 just DASHSCOPE_API_KEY exported.
  • AgentStudio — same business package, new FQCN com.alibaba.dashscope.applications.agentstudio.*; also reachable via client.agentStudio(). The 3.0 baseUrl does not apply to AgentStudio; DASHSCOPE_AGENTSTUDIO_URL overrides its endpoint.

Where to go next