Model Studio provides official DashScope SDKs (Python, Java) and supports OpenAI SDKs (Python, Node.js, Java, Go) for OpenAI-compatible API calls.
Install the SDK
Python
The SDK requires Python >= 3.9.
You can call models on Model Studio using the DashScope Python SDK (recommended) or the OpenAI Python SDK.
Install the DashScope Python SDK
Install or upgrade the DashScope Python SDK:
# If this fails, replace pip with pip3
pip install -U dashscope
Look for Successfully installed ... dashscope-x.x.x to confirm installation.
Install the OpenAI Python SDK
Install or upgrade the OpenAI Python SDK:
# If this fails, replace pip with pip3
pip install -U openai
Look for Successfully installed ... openai-x.x.x to confirm installation.
Java
DashScope
Add the DashScope Java SDK dependency. Replace the-latest-version with the latest version number from the Maven repository.
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 (replace the-latest-version with the latest version number; recommended: 3.5.0). 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, configure a registry mirror:
npm config set registry https://registry.npmmirror.com/
After configuring the mirror, rerun the SDK installation command.
Look for added xx package in xxs to confirm installation. Check version: npm list openai.
Go
OpenAI
Install the OpenAI Go SDK (which requires Go 1.22+) in your project folder:
go get 'github.com/openai/openai-go/v3'
Or install a specific version:
go get -u 'github.com/openai/openai-go/v3@v3.8.1'
If the installation times out, set an Alibaba Cloud mirror:
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
Import the SDK:
import (
"github.com/openai/openai-go/v3" // imported as openai
)
What to do next
After installing the SDK:
- Select a model that fits your scenario from the Model Studio console.
- Start building your application using models for text generation, image generation, video generation, speech synthesis, speech recognition, embedding, or reranking.
- Learn about the compatibility details with the OpenAI API.