All Products
Search
Document Center

Alibaba Cloud Model Studio:Install the SDK

Last Updated:Feb 19, 2025

Model Studio provides SDKs for Python and Java (also called DashScope SDK), and invocation methods compatible with OpenAI SDK. This topic describes how to install Open AI SDK and DashScope SDK.

Procedure

Python

Step 1: Check Python version

Run the following command in the terminal to check whether Python is installed:

Make sure that you have Python version 3.8 or higher, see Install Python.

python -V
pip --version

Take Windows CMD as an example:

image

FAQ

Q: An error occurs when executing python -V, pip --version:

  • 'python' is not recognized as an internal or external command, operable program or batch file.

  • 'pip' is not recognized as an internal or external command, operable program or batch file.

  • -bash: python: command not found

  • -bash: pip: command not found

A: Take the following steps:

Windows
  1. Make sure that you have installed Python in your computing environment and that you have added python.exe to PATH. image

  2. If you have installed Python and added the environment variable, but the error still occurs, close the current terminal and open a new terminal to try again.

Linux and macOS
  1. Make sure you have installed Python in your computing environment.

  2. If you have installed Python but the error still occurs, run which python pip to check whether python and pip exist in the system.

    • If the following result is returned, close the current terminal and open a new terminal to try again.

      /usr/bin/python
      /usr/bin/pip
    • If the following result is returned, run which python3 pip3 to check again.

      /usr/bin/which: no python in (/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
      /usr/bin/which: no pip in (/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)

      If the following result is returned, run python3 -V, pip3 --version to check the version.

      /usr/bin/python3
      /usr/bin/pip3

Step 2: Configure virtual environment (optional)

After Python is installed, you can set up a virtual environment to manage dependencies for OpenAI Python SDK or DashScope Python SDK. The virtual environment can avoid conflicts with your other projects.

  1. Create a virtual environment

    Run the following command to create a virtual environment named .venv:

    # If the operation fails, replace python with python3 and run again
    python -m venv .venv
  2. Activate the virtual environment

    For Windows:

    .venv\Scripts\activate

    For macOS or Linux:

    source .venv/bin/activate

Step 3: Install OpenAI Python SDK or DashScope Python SDK

Install OpenAI Python SDK or DashScope Python SDK to call models in Model Studio.

OpenAI Python SDK

Run the following command:

# If the operation fails, replace pip with pip3 and run again
pip install -U openai

image

When the terminal displays Successfully installed ... openai-x.x.x, OpenAI Python SDK is installed.

DashScope Python SDK

Run the following command:

# If the operation fails, replace pip with pip3 and run again
pip install -U dashscope

image

When the terminal displays Successfully installed ... dashscope-x.x.x, DashScope Python SDK is installed.

Node.js

Step 1: Check Node.js installation status

Run the following command in the terminal to check whether Node.js and npm are installed in the current computing environment:

node -v
npm -v

Take Windows CMD as an example:

image

This command displays your current Node.js version. If Node.js is not installed in your environment, you can download it from Node.js official website.

Step 2: Install the SDK

Run the following command in the terminal:

npm install --save openai
# Or
yarn add openai
Note

If the installation fails, you can run the following command to configure a repository mirror:

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

Then, run the installation command to install the SDK again.

image

When the terminal displays added xx package in xxs, the OpenAI SDK is installed. You can run npm list openai to check the version information.

Java

Step 1: Check Java version

Run the following command in the terminal:

java -version
# (Optional) If you use Maven to manage and build Java projects, ensure that Maven is correctly installed in your development environment
mvn --version

Take Windows CMD as an example:

image

DashScope Java SDK requires Java 8 or higher. The first line of the output shows your Java version. For example, openjdk version "16.0.1" 2021-04-20 indicates Java 16 is installed. If Java is not installed or the installed version is earlier than Java 8, go to Java Downloads to download and install the appropriate version.

Step 2: Install DashScope Java SDK

After you install Java, you can then install DashScope Java SDK. For information about the SDK versions, see DashScope Java SDK. Run the following command to include the Java SDK dependency in your project. Replace the-latest-version with the actual latest version number.

XML

  1. Open your Maven project's pom.xml file.

  2. Add the dependency information within the <dependencies> tag.

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dashscope-sdk-java</artifactId>
        <!-- Please replace 'the-latest-version' with the latest version number: https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
        <version>the-latest-version</version>
    </dependency>
  3. Save pom.xml.

  4. Use Maven commands, such as mvn compile or mvn clean install, to refresh your project's dependencies. DashScope Java SDK will be downloaded and integrated into your project automatically.

Take Windows IDEA as an example:

image

Gradle

  1. Open your Gradle project's build.gradle file.

  2. Add the dependency information within the dependencies block.

    dependencies {
        // Please replace 'the-latest-version' with the latest version number: https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java
        implementation group: 'com.alibaba', name: 'dashscope-sdk-java', version: 'the-latest-version'
    }
  3. Save build.gradle.

  4. Navigate to your project's root directory in the command line and run the following Gradle command to refresh your project dependencies. DashScope Java SDK will be downloaded and integrated into your project automatically.

    ./gradlew build --refresh-dependencies

Take Windows IDEA as an example:

image

What to do next

Explore sample codes to call models with the OpenAI SDK or DashScope SDK.

References

For a list of models that support the OpenAI SDK, see Compatiblity with OpenAI.