Alibaba Cloud Model Studio's embedding models are compatible with the OpenAI API. To migrate your existing OpenAI applications to Model Studio, you only need to adjust the following three parameters:
base_url: Replace with
https://dashscope-intl.aliyuncs.com/compatible-mode/v1.If you use a model in the China (Beijing) region, you must replace the URL with https://dashscope.aliyuncs.com/compatible-mode/v1.
api_key: Replace with a Model Studio API key.
model: Replace with a model name from the list below.
Supported models
Singapore
Model | Embedding dimensions | Batch size | Max tokens per row (Note) | Price (Million input tokens) | Supported languages | Free quota(Note) |
text-embedding-v4 Part of the Qwen3-Embedding series | 2,048, 1,536, 1,024 (default), 768, 512, 256, 128, 64 | 10 | 8,192 | $0.07 | Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, Russian, and 100+ other major languages | 1 million tokens Valid for 90 days after you activate Model Studio. |
text-embedding-v3 | 1,024 (default), 768, 512 | Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, Russian, and 50+ other major languages | 500,000 tokens Validity: 90 days after you activate Model Studio |
Beijing
Model | Vector dimension | Maximum rows | Maximum tokens per row | Supported languages | Price (per 1 million input tokens) |
text-embedding-v4 Qwen3-Embedding series | 2,048, 1,536, 1,024 (default), 768, 512, 256, 128, or 64 | 10 | 8,192 | More than 100 mainstream languages, such as Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian, and multiple programming languages | $0.072 |
How to use
Call examples
This section provides examples of string input using Python (OpenAI SDK) and cURL (HTTP). For examples that use other programming languages or input methods, see Get started with text embedding.
OpenAI SDK
To call the service using the OpenAI SDK, you must first install the OpenAI SDK.
import os
from openai import OpenAI
def get_response():
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # If you have not configured the environment variable, replace the value with your API key.
# The base_url of the Alibaba Cloud Model Studio service. If you use a model in the China (Beijing) region, you must replace the URL with https://dashscope.aliyuncs.com/compatible-mode/v1.
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.embeddings.create(
model="text-embedding-v3", # If you use a model in the China (Beijing) region, you must replace the model name with text-embedding-v4.
input='The quality of the clothes is excellent. They are beautiful. It was worth the wait. I like them and will buy from here again.',
encoding_format="float"
)
print(completion.model_dump_json())
if __name__ == '__main__':
get_response()HTTP
Submit an interface call
Singapore: POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/embeddings
China (Beijing): POST https://dashscope.aliyuncs.com/compatible-mode/v1/embeddingsCall from the command line
# If you use a model in the China (Beijing) region, you must replace the URL with https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings \
curl --location 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/embeddings' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "text-embedding-v3",
"input": "The quality of the clothes is excellent. They are beautiful. It was worth the wait. I like them and will buy from here again.",
"encoding_format": "float"
}'The following result is returned after you run the code:
Sample error response
If an access request error occurs, the cause is indicated by the code and message parameters in the response.
{
"error": {
"message": "Incorrect API key provided. ",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}API reference
Error codes
If a call fails, see Error messages for troubleshooting.