Skip to content

Features

The DashScope Java SDK is a typed, resource-style client for Alibaba Cloud Model Studio. Core HTTP resources share the DashScopeClient OkHttp connection pool. Build requests with typed builders and read typed responses.

Resource map

Capability Client accessor Guide
Chat and tool calls client.chat() Chat and streaming
Multimodal understanding client.multimodal() Multimodal
Embeddings and rerank client.embeddings(), client.rerank() Embeddings and rerank
Image and video generation client.images(), client.videos() Images and videos
Speech and meetings client.audio(), client.tingwu() Audio
Files, models, and fine-tuning client.files(), client.models(), client.fineTunes(), client.deployments() Files and fine-tuning
Managed agents and Workflows client.agentStudio() AgentStudio
Token counting client.tokenization() Tokenization
Applications and decisions client.apps(), client.decision() Client resources

Find short calls in capability recipes, and source code and run commands in the examples hub.

Sync and async

  • Use DashScopeClient for sync calls. DashScopeAsyncClient returns CompletableFuture<T> for unary operations and RxJava Flowable<T> for streaming. Manage client lifetime with try-with-resources.
  • The async audio() accessor supports batch ASR only; duplex WebSocket sessions use the sync client. The audio module is still under development, so check for interface changes when upgrading.

See async client.

Streaming

Chat streams return incremental output over SSE. Sync createStreaming() returns a closeable, iterable ResponseStream<T>; read the delta from each chunk and close the stream even when stopping early. Interrupted streams are not automatically resumed.

See chat and streaming.

Protocols and transport

  • Chat: chat().completions() uses the native Model Studio API: HTTP/JSON for regular requests and SSE for streamed responses. Java has no protocol option for switching to OpenAI-compatible or Anthropic-compatible chat protocols. See protocols and transport.
  • Duplex audio: speech and realtime APIs that need bidirectional transport use WebSocket. Choose an HTTP or WebSocket audio API for your task.

Configuration and request options

Configuration resolves from explicit builder options → JVM system properties → environment variables → ~/.dashscope/config.toml → defaults. The API key can also fall back to a saved key file. ClientOptions covers endpoints, region, workspace, timeouts, retries, custom OkHttp clients, and executors. Use RequestOptions to override timeout, retries, credentials, and headers per request.

See configuration.

Errors and diagnosis

Failed requests raise typed DashScopeException subclasses by default. Read the error code, HTTP status, and request ID. Non-streaming HTTP calls retry eligible failures according to policy. When investigating auth, rate limits, or network failures, capture both the request ID and error code.

See errors and diagnosis.

Local development

  • Mock debugging: point baseUrl at a loopback mock gateway to exercise success and failure paths without a real API key. See local mock debugging. The example project's Maven dry-run suite also checks examples that can run offline.
  • Tokenization: use client.tokenization().count() for server-side counts or TokenizerFactory.qwen() with an available vocabulary to estimate budgets locally. First use may download the vocabulary. See tokenization.

SDK-specific capabilities

  • Request envelope encryption: opt in for an HTTP request with enableEncryption(true) in RequestOptions. The SDK fetches and caches the gateway public key. See encrypted channel.

Legacy compatibility

Use 3.x resources for new code. The frozen 2.x API lives under com.alibaba.dashscope.legacy_2x.*; upgrading from the old artifact requires changing imports, and the facade is planned for removal in 4.0. See migration.