Skip to content

OpenAI compatible - Embedding

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:

Supported models

Singapore

ModelEmbedding dimensionsMax rowsMax tokens per line (Note)Price (per 1M input tokens)Supported languagesFree quota (Note)
text-embedding-v4 ** Qwen3-Embedding series2,048, 1,536, 1,024 (default), 768, 512, 256, 128, or 64108,192$0.07More than 100 mainstream languages, such as Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian1 million tokens Valid for 90 days after Model Studio activation
text-embedding-v31,024 (default), 768, or 512More than 50 mainstream languages, such as Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian500,000 tokens Valid for 90 days after Model Studio activation

Beijing

Model**Embedding dimensionsMax rowsMax tokens per line (Note)Price (per 1M input tokens)Supported languages
text-embedding-v4 ** Qwen3-Embedding series2,048, 1,536, 1,024 (default), 768, 512, 256, 128, or 64108,192$0.072More than 100 mainstream languages, such as Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian, and multiple programming languages

China (Hong Kong)

Model**Embedding dimensionsMax rowsMax tokens per line (Note)Price (per 1M input tokens)Supported languages
text-embedding-v4 Qwen3-Embedding series2,048, 1,536, 1,024 (default), 768, 512, 256, 128, or 64108,192$0.07More than 100 mainstream languages, such as Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian, and multiple programming languages

Multimodal embedding models, such as qwen3-vl-embedding and the tongyi-embedding-vision series, do not support the OpenAI-compatible API. See Multimodal Embedding.

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.

HELPCODEESCAPE-python
import os
from openai import OpenAI

def get_response():
    client = OpenAI(
        # API keys vary by region. Get your API key: https://www.alibabacloud.com/help/en/model-studio/get-api-key
        api_key=os.getenv("DASHSCOPE_API_KEY"), # If you have not configured the environment variable, replace this value with your API key.
        # The base_url of the Model Studio service. If you use a model in the China (Beijing) region, 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, 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

HELPCODEESCAPE-http
Singapore: POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/embeddings
China (Beijing): POST https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings

Call from the command line

HELPCODEESCAPE-curl

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: Result

HELPCODEESCAPE-json
{
  "data": [
    {
      "embedding": [
        0.0023064255,
        -0.009327292,
        ....
        -0.0028842222
      ],
      "index": 0,
      "object": "embedding"
    }
  ],
  "model":"text-embedding-v3",
  "object":"list",
  "usage":{"prompt_tokens":23,"total_tokens":23},
  "id":"f62c2ae7-0906-9758-ab34-47c5764f07e2"
}

Sample error response

If an access request error occurs, the cause is indicated by the code and message parameters in the response.

HELPCODEESCAPE-json
{
    "error": {
        "message": "Incorrect API key provided. ",
        "type": "invalid_request_error",
        "param": null,
        "code": "invalid_api_key"
    }
}

API reference

Text embedding API reference

Error codes

If the model call fails and returns an error message, see Error messages for resolution.

Mirror of Alibaba Cloud Model Studio docs for reference and RAG. Not affiliated with Alibaba Cloud.