Install the SDK

Updated at:

Model Studio provides official DashScope SDKs (Python, Java) and supports OpenAI SDKs (Python, Node.js, Java, Go) for OpenAI-compatible API calls.

NoteTo call real-time speech or multimodal models supported by Realtime API over AOQ, see AOQ SDK downloads. For supported models and protocols, see Model and protocol support.

Install the SDK

Python

The SDK requires Python >= 3.9.

You can call models on Alibaba Cloud Model Studio using the OpenAI Python SDK or the DashScope Python SDK.

Install the OpenAI Python SDK

Install or upgrade the OpenAI Python SDK by running the following command:

# If this fails, replace pip with pip3
pip install -U openai

When the message Successfully installed ... openai-x.x.x appears in the terminal, the OpenAI Python SDK has been installed successfully.

Install the DashScope Python SDK

Install or upgrade the DashScope Python SDK by running the following command:

# If this fails, replace pip with pip3
# The examples in this documentation are based on DashScope Python SDK 2.0; version 2.0.1 or later is required
pip install -U "dashscope>=2.0.1"

When the message Successfully installed ... dashscope-x.x.x appears in the terminal, the DashScope Python SDK has been installed successfully.

NoteThe Python SDK examples in this documentation are all written against DashScope Python SDK 2.0. Make sure you install version 2.0.1 or later. Existing projects on 1.x can keep running (1.x and 2.0 coexist in the same package); see each code example for how to migrate to 2.0.

Java

DashScope

Add the DashScope Java SDK dependency to your project, and replace the-latest-version with the latest version number.

Gradle

dependencies {
    implementation group: 'com.alibaba', name: 'dashscope-sdk-java', version: 'the-latest-version'
}

Maven

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dashscope-sdk-java</artifactId>
    <version>the-latest-version</version>
</dependency>

OpenAI

Add the OpenAI Java SDK dependency to your project, and replace the-latest-version with the latest version number. (3.5.0 is recommended.)

The SDK requires Java 8 or later.

Gradle

dependencies {
    implementation("com.openai:openai-java:the-latest-version")
}

Maven

<dependency>
  <groupId>com.openai</groupId>
  <artifactId>openai-java</artifactId>
  <version>the-latest-version</version>
</dependency>

Node.js

OpenAI

Run this command in your terminal:

npm install --save openai
# Or
yarn add openai

NoteIf installation fails, you can complete the installation by configuring a registry mirror, for example:

npm config set registry https://registry.npmmirror.com/

After configuring the mirror, rerun the SDK installation command.

When the message added xx package in xxs appears in the terminal, the OpenAI SDK has been installed successfully. You can run npm list openai to check the version details.

Go

OpenAI

OpenAI provides an SDK for Go (requires Go 1.22+). You can install it in your project directory with the following command:

go get 'github.com/openai/openai-go/v3'

Or set a fixed version for installation:

go get -u 'github.com/openai/openai-go/v3@v3.8.1'

If access to the server times out, set an Alibaba Cloud mirror proxy: go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

Use the following statement to import it in your code:

import (
	"github.com/openai/openai-go/v3" // imported as openai
)

What to do next

After successfully installing the SDK, you can: