Skip to main content

Synchronous API details

General text embedding models convert text data into numerical vectors for downstream tasks such as semantic search, recommendation, clustering, and classification.

Model overview

  • Singapore
  • Beijing
  • Hong Kong (China)
  • dashscope CLI
ModelVector dimensionsMaximum rowsMaximum tokens processed per row (Note)Unit price (per million input tokens)Supported languagesFree quota(Note)
qwen3.7-text-embedding2560, 2,048, 1,536, 1,024 (default), 768, 512, 25620128,000$0.07201 mainstream languages and dialects, including Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian1 million tokensValidity: within 90 days after Model Studio activation
text-embedding-v4
Part of the Qwen3-Embedding series
2,048, 1,536, 1,024 (default), 768, 512, 256, 128, 64108,192$0.07100+ mainstream languages, including Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian1 million tokensValidity: within 90 days after Model Studio activation
text-embedding-v31,024 (default), 768, 51250+ mainstream languages, including Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian500,000 tokensValidity: within 90 days after Model Studio activation
For model rate limiting, see Rate limiting.

Prerequisites

If you are familiar with the OpenAI ecosystem, you can use the compatible API for quick migration; the DashScope API offers richer exclusive features. Choose based on your needs. You need to have obtained and configured an API Key and configured the API Key in environment variables. If you call through the SDK, you also need to install the DashScope SDK.

OpenAI compatibility

base_url to configure when calling with the SDK:
  • Singapore: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
  • China (Beijing): https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
  • Hong Kong (China): https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1
endpoint to configure when calling with HTTP:
  • Singapore: POSThttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/embeddings
  • China (Beijing): POSThttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/embeddings
  • Hong Kong (China): POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/embeddings
Replace {WorkspaceId} with your actual workspace ID when calling.

Request body

modelstringRequiredThe model name to call. Select from the model names in the Model overview table.inputarray<string> or string or fileRequiredThe input text to process. It can be a string, an array of strings, or a file. Different model versions support different text lengths and batch sizes, as follows:
  • qwen3.7-text-embedding model:
    • When the input is a string: supports up to 128,000 tokens.
    • When the input is a list of strings or a file: supports up to 20 items (rows), each up to 128,000 tokens.
  • text-embedding-v3 / v4 models:
    • When the input is a string: supports up to 8,192 tokens.
    • When the input is a list of strings or a file: supports up to 10 items (rows), each up to 8,192 tokens.
dimensions integer OptionalThe specified vector dimensions, which must be one of the following values: 2560 (only applies to qwen3.7-text-embedding), 2048 (only applies to text-embedding-v4), 1536 (only applies to text-embedding-v4) 1024, 768, 512, 256, 128, or 64. The default value is 1024.encoding_format string OptionalControls the returned embedding format. The input supports float and base64, and the returned embedding data also supports both float and base64 formats. The actual returned format depends on the gateway the request is routed to:
  • Legacy gateway: regardless of whether encoding_format is set to float or base64, it only returns float data and does not support base64 output.
  • New gateway:
    • Short requests: data is returned in the format set by encoding_format.
    • Long requests: internally routed to the legacy gateway, only float data is returned.
  • Input string
  • Input string list
  • Input file
  • Python
  • Java
  • curl
import os
from openai import OpenAI

client = OpenAI(
    # If you use a model in the China (Beijing) region, you must use an API key from that region. Get one at: https://modelstudio.console.alibabacloud.com/model/settings/api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),  # If the environment variable is unset, insert your API key here
    # The following URL is for the Singapore region. When calling, replace {WorkspaceId} with your actual workspace ID. URLs vary by region.
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)

completion = client.embeddings.create(
    model="qwen3.7-text-embedding",
    input='The clothes are of good quality and look good, definitely worth the wait. I love them.',
    dimensions=1024,
    encoding_format="float"
)

print(completion.model_dump_json())

Response object

dataarrayTask output information.

Property

embeddinglistThe value of the object returned by this call, which is an array of float elements containing the specific embedding vectors.indexintegerThe index of the input text in the input array that corresponds to the algorithm result in this structure.objectstringThe type of the object returned by this call. The default value is embedding.
modelstringThe name of the model called.objectstringThe type of data returned by this call. The default value is list.usageobjectThe Token usage of this request. Embedding models only have input and no output, so prompt_tokens and total_tokens always have the same value.

Property

prompt_tokensintegerThe number of Tokens corresponding to the input content of this request. The value is the same as total_tokens.total_tokens integerThe total number of Tokens consumed by this request, used for metering and billing. The Token count is based on the result of the input string parsed by the model Tokenizer, which may differ from the character or word count you estimate on your own.
idstringThe unique identifier of the request. It can be used for tracing request details and troubleshooting.
{
  "data": [
    {
      "embedding": [
        -0.0695386752486229, 0.030681096017360687, ...
      ],
      "index": 0,
      "object": "embedding"
    },
    ...
    {
      "embedding": [
        -0.06348952651023865, 0.060446035116910934, ...
      ],
      "index": 5,
      "object": "embedding"
    }
  ],
  "model": "qwen3.7-text-embedding",
  "object": "list",
  "usage": {
    "prompt_tokens": 184,
    "total_tokens": 184
  },
  "id": "73591b79-d194-9bca-8bb5-xxxxxxxxxxxx"
}

DashScope

base_url to configure when calling with the SDK:
  • Singapore: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1
  • China (Beijing): https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1
  • Hong Kong (China): https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1
endpoint to configure when calling with HTTP:
  • Singapore: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding
  • China (Beijing): POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding
  • Hong Kong (China): POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding
Replace {WorkspaceId} with your actual workspace ID when calling.

Request body

modelstringRequiredThe model to call. Select one from the model names in the table in Model overview.inputstringorarray<string>RequiredThe input text to process. It can be a string, an array of strings, or a file. Different model versions support different text lengths and batch sizes, as follows:
  • qwen3.7-text-embedding model:
    • When the input is a string: supports up to 128,000 tokens.
    • When the input is a list of strings or a file: supports up to 20 items (rows), each up to 128,000 tokens.
  • text-embedding-v3 / v4 models:
    • When the input is a string: supports up to 8,192 tokens.
    • When the input is a list of strings or a file: supports up to 10 items (rows), each up to 8,192 tokens.
text_type stringOptional
When calling over HTTP, put text_type into the parameters object.
After text is converted into vectors, it can be applied to downstream tasks such as retrieval, clustering, and classification. For asymmetric tasks such as retrieval, to achieve better retrieval performance, it is recommended to distinguish between the query text (query) type and the corpus text (document) type. For symmetric tasks such as ingestion, clustering, and classification, you do not need to specify this explicitly; the system default value document is used.dimension integer Optional
When calling over HTTP, put dimension into the parameters object.
The specified vector dimensions, which must be one of the following values: 2560 (only applies to qwen3.7-text-embedding), 2048 (only applies to text-embedding-v4), 1536 (only applies to text-embedding-v4) 1024, 768, 512, 256, 128, or 64. The default value is 1024.output_type string Optional
When calling over HTTP, put output_type into the parameters object.
The user-specified discrete vector output only applies to the qwen3.7-text-embedding、``text-embedding-v3 and text-embedding-v4 models. The value can be dense, sparse, or dense&sparse, and the default is dense, which outputs only continuous vectors. Sparse vector output (sparse and dense&amp;sparse) is only supported when called through the DashScope API.instruct string OptionalAdd a custom task description to guide the model in understanding the query intent. It is recommended to write it in English, which typically brings about a 1%–5% performance improvement.This parameter only takes effect when text_type is set to query, and the Token usage is counted based on the number of input texts. When text_type is set to document or text_type is not set, this parameter does not take effect and is not counted in Token usage.
  • Input string
  • Input string list
  • Input file
  • Python
  • Java
  • curl
import os
import dashscope

# The following configuration is for the Singapore (ap-southeast-1) region. Replace {WorkspaceId} with your actual workspace ID. The region value varies by region.
client = dashscope.Client(
    # If you have not set an environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # API keys are region-specific. To get an API key, see https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

resp = client.embeddings.create(
    model="qwen3.7-text-embedding",
    input='风急天高猿啸哀, 渚清沙白鸟飞回, 无边落木萧萧下, 不尽长江滚滚来',
    dimension=1024,  # Specify the vector dimension (only supported by qwen3.7-text-embedding, text-embedding-v3, and text-embedding-v4)
    output_type="dense&sparse"
)

print(resp)

Response object

In Python SDK 2.0, the fields of the response object returned by client.embeddings.create are as follows (in the JSON returned by the HTTP API, embeddings is wrapped in output).
request_id stringThe unique identifier of the request. It can be used for tracing request details and troubleshooting.embeddingsarrayThe algorithm output of this request, which is an array of structures, each containing the algorithm output for the corresponding input text.
sparse_embedding arrayThe discrete vector representation of the algorithm output for the corresponding string (sparse embedding only applies to text-embedding-v3 and text-embedding-v4).
index integerThe position index of the word or character in the vocabulary.value floatIndicates the weight or importance score of the Token. A higher value indicates that the Token is more important or relevant in the context of the current text.token stringThe actual text unit or word in the vocabulary.
embedding arrayThe continuous vector representation of the algorithm output for the corresponding string (dense embedding).index integerThe index of the input text in the input array that corresponds to the algorithm result in this structure.
usageobjectThe token usage of this request. Embedding models only have input and no output, so the values of the fields in this object are always the same.

Property

input_tokens integerThe number of Tokens corresponding to the input content of this request. The value is the same as total_tokens.Only qwen3.7-text-embedding returns this parameter. text-embedding-v4, text-embedding-v3, text-embedding-v2, and text-embedding-v1 do not return this parameter.total_tokens integerThe total number of Tokens consumed by this request, used for metering and billing. The Token count is based on the result of the input string parsed by the model Tokenizer, which may differ from the character or word count you estimate on your own.When instruct is set and text_type is set to query, instruct is counted repeatedly in token usage based on the number of input texts.
Call FailedWhen a call fails, the SDK throws DashScopeError. You can obtain failure details through e.status_code (HTTP return code), e.code (error code), e.message (error message), and e.request_id (unique request identifier). For more information, see Error codes.
{
    "request_id": "1ba94ac8-e058-99bc-9cc1-7fdb37940a46",
    "embeddings": [
      {
         "index": 0,
         "sparse_embedding":[
           {"index":7149,"value":0.829,"token":"风"},
           .....
           {"index":111290,"value":0.9004,"token":"哀"}],
         "embedding": [-0.006929283495992422,-0.005336422007530928, ...]
      },
      {
         "index": 1,
         "sparse_embedding":[
           {"index":246351,"value":1.0483,"token":"渚"},
           .....
           {"index":2490,"value":0.8579,"token":"回"}],
         "embedding": [-0.006929283495992422,-0.005336422007530928, ...]
      },
      {
         "index": 2,
         "sparse_embedding":[
           {"index":3759,"value":0.7065,"token":"无"},
           .....
           {"index":1130,"value":0.815,"token":"下"}],
         "embedding": [-0.006929283495992422,-0.005336422007530928, ...]
      },
      {
         "index": 3,
         "sparse_embedding":[
           {"index":562,"value":0.6752,"token":"不"},
           .....
           {"index":1589,"value":0.7097,"token":"来"}],
         "embedding": [-0.001945948973298072,-0.005336422007530928, ...]
      }
    ],
    "usage":{
        "total_tokens":27
    }
}

Error codes

If a model call fails and returns an error message, see Error codes for troubleshooting.