Skip to main content
Toolkit/Framework

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:

  • base_url: Replace with https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1.
  • api_key: Replace with a Model Studio API key.
  • model: Replace with a model name from the list below.
Alibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing), Singapore, and China (Hong Kong) regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
  • China (Beijing): from https://dashscope.aliyuncs.com to https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com
  • Singapore: from https://dashscope-intl.aliyuncs.com to https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domain remains fully functional.

Supported models

ModelEmbedding dimensionsMax rowsMaxtokensper linePrice (per 1K input tokens)Supported languagesFree quota(Note)
qwen3.7-text-embedding2,560, 2,048, 1,536, 1,024 (default), 768, 512, 25620128,000CNY 0.0005Batch call: CNY 0.00025Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, Russian, and over 200 other major languages and dialects1 million tokens eachValidity: 90 days after you activate Model Studio
qwen3.7-text-embedding-flash1,024 (default), 768, 512, 25620128,000CNY 0.000125Batch call: CNY 0.000063Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, Russian, and over 200 other major languages and dialects
text-embedding-v4
Part of the Qwen3-Embedding series
2,048, 1,536, 1,024 (default), 768, 512, 256, 128, 64108,192CNY 0.0005Batch call: CNY 0.00025Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, Russian, and over 100 other major languages, plus multiple programming languages
text-embedding-v31,024 (default), 768, 512, 256, 128, or 64Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, Russian, and over 50 other major languages
text-embedding-v21,536252,048CNY 0.0007Batch call: CNY 0.00035Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, Russian500,000 tokens eachValidity: 90 days after you activate Model Studio
text-embedding-v1Chinese, English, Spanish, French, Portuguese, Indonesian
Multimodal embedding models, such as qwen3-vl-embedding and the tongyi-embedding-vision series, do not support the OpenAI-compatible API. See Multimodal Embedding.
The OpenAI-compatible API does not support sparse vector output. To use output_type=sparse with text-embedding-v4, call the DashScope API. If output_type=sparse is sent to the OpenAI-compatible API, it returns HTTP 200 with an empty embedding result.

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
  • HTTP
To call the service using the OpenAI SDK, you must first install the OpenAI SDK.
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),  # If you have not configured the environment variable, replace this value with your API key.
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"  # The base_url of the Model Studio service
)

completion = client.embeddings.create(
    model="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.',
    dimensions=1024, # Specify the vector dimension. Only text-embedding-v3 and text-embedding-v4 support this parameter.
    encoding_format="float"
)

print(completion.model_dump_json())
The following result is returned after you run the code:
{
  "data": [
    {
      "embedding": [
        0.0023064255,
        -0.009327292,
        ....
        -0.0028842222
      ],
      "index": 0,
      "object": "embedding"
    }
  ],
  "model":"text-embedding-v4",
  "object":"list",
  "usage":{"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.
{
    "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 codes for resolution.
Text Generation
Image Generation
Video Generation
World models
3D Model Generation
Audio
  • Audio generation
Realtime API
Text Embedding
Decision Model
TokenPlan
Model Production