リクエストボディ modelstring必須 呼び出すモデルの名前。モデル名については、「モデル概要」の表をご参照ください。 inputarray<string> or string or file必須 処理する入力テキスト。入力は、文字列、文字列の配列、またはファイルが可能です。 テキスト長とバッチサイズの制限は、モデルのバージョンによって異なります:
-
qwen3.7-text-embedding モデル:
- 文字列入力:最大 128,000 トークン。
- 文字列リストまたはファイル入力:最大 20 アイテム (行)、各アイテム (行) は最大 128,000 トークン。
-
text-embedding-v3 / v4 モデル:
- 文字列入力:最大長 8,192 トークン。
- 文字列リストまたはファイル入力:最大 10 アイテム (行)、各アイテム (行) は最大 8,192 トークン。
dimensions integer 任意 出力される埋め込みベクトルの次元。次の値のいずれかである必要があります:2560 (qwen3.7-text-embedding のみ)、2048 (text-embedding-v4 のみ)、1536 (text-embedding-v4 のみ)、1024、768、512、256、128、または 64。デフォルト値は 1024 です。 encoding_format string 任意 返される埋め込みフォーマット。現在、float のみがサポートされています。 | 入力文字列Pythonimport os
from openai import OpenAI
client = OpenAI(
# 中国 (北京) リージョンのモデルを使用する場合、そのリージョンの API キーを使用する必要があります。取得先: https://modelstudio.console.alibabacloud.com/?tab=model#/api-key
api_key=os.getenv("DASHSCOPE_API_KEY"), # 環境変数が設定されていない場合は、プレースホルダーをご利用の API キーに置き換えてください。
# これはシンガポールリージョンの URL です。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
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())
Javaimport java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dashscope.utils.JsonUtils;
public final class Main {
public static void main(String[] args) {
// 中国 (北京) リージョンのモデルを使用する場合、そのリージョンの API キーを使用する必要があります。取得先: https://modelstudio.console.alibabacloud.com/?tab=model#/api-key
String apiKey = System.getenv("DASHSCOPE_API_KEY");
if (apiKey == null) {
System.out.println("DASHSCOPE_API_KEY not found in environment variables");
return;
}
// これはシンガポールリージョンの URL です。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
String baseUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/embeddings";
HttpClient client = HttpClient.newHttpClient();
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("model", "qwen3.7-text-embedding");
requestBody.put("input", "The wind is strong, the sky is high, and the apes cry mournfully. The islet is clear, the sand is white, and the birds fly back. The boundless forest sheds its leaves shower by shower. The endless river rolls on wave after wave.");
requestBody.put("dimensions", 1024);
requestBody.put("encoding_format", "float");
try {
String requestBodyString = JsonUtils.toJson(requestBody);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(baseUrl))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + apiKey)
.POST(HttpRequest.BodyPublishers.ofString(requestBodyString))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
System.out.println("Response: " + response.body());
} else {
System.out.printf("Failed to retrieve response, status code: %d, response: %s%n", response.statusCode(), response.body());
}
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
curl
中国 (北京) リージョンのモデルを使用する場合、そのリージョンのAPI キーを使用し、URL を https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/embeddings に置き換える必要があります。以下のコード例では、シンガポールリージョンの URL を使用しています。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/embeddings' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen3.7-text-embedding",
"input": "The wind is strong, the sky is high, and the apes cry mournfully. The islet is clear, the sand is white, and the birds fly back. The boundless forest sheds its leaves shower by shower. The endless river rolls on wave after wave.",
"dimensions": 1024,
"encoding_format": "float"
}'
入力文字列リストPythonimport os
from openai import OpenAI
client = OpenAI(
# 中国 (北京) リージョンのモデルを使用する場合、そのリージョンの API キーを使用する必要があります。取得先: https://modelstudio.console.alibabacloud.com/?tab=model#/api-key
api_key=os.getenv("DASHSCOPE_API_KEY"), # 環境変数が設定されていない場合は、プレースホルダーをご利用の API キーに置き換えてください。
# これはシンガポールリージョンの URL です。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)
completion = client.embeddings.create(
model="qwen3.7-text-embedding",
input=['The wind is strong, the sky is high, and the apes cry mournfully.', 'The islet is clear, the sand is white, and the birds fly back.', 'The boundless forest sheds its leaves shower by shower.', 'The endless river rolls on wave after wave.'],
dimensions=1024,
encoding_format="float"
)
print(completion.model_dump_json())
Javaimport java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Arrays;
import com.alibaba.dashscope.utils.JsonUtils;
public final class Main {
public static void main(String[] args) {
// 環境変数から API キーを取得します。設定されていない場合は、ご利用の API キーに置き換えてください。
// 中国 (北京) リージョンのモデルを使用する場合、そのリージョンの API キーを使用する必要があります。取得先: https://modelstudio.console.alibabacloud.com/?tab=model#/api-key
String apiKey = System.getenv("DASHSCOPE_API_KEY");
if (apiKey == null) {
System.out.println("DASHSCOPE_API_KEY not found in environment variables");
return;
}
// これはシンガポールリージョンの URL です。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
String baseUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/embeddings";
HttpClient client = HttpClient.newHttpClient();
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("model", "qwen3.7-text-embedding");
List<String> inputList = Arrays.asList("The wind is strong, the sky is high, and the apes cry mournfully.", "The islet is clear, the sand is white, and the birds fly back.", "The boundless forest sheds its leaves shower by shower.", "The endless river rolls on wave after wave.");
requestBody.put("input", inputList);
requestBody.put("encoding_format", "float");
try {
// リクエストボディを JSON 文字列に変換します。
String requestBodyString = JsonUtils.toJson(requestBody);
// HTTP リクエストをビルドします。
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(baseUrl))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + apiKey)
.POST(HttpRequest.BodyPublishers.ofString(requestBodyString))
.build();
// リクエストを送信し、レスポンスを受信します。
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
System.out.println("Response: " + response.body());
} else {
System.out.printf("Failed to retrieve response, status code: %d, response: %s%n", response.statusCode(), response.body());
}
} catch (Exception e) {
// 例外をキャッチして出力します。
System.err.println("Error: " + e.getMessage());
}
}
}
curl
中国 (北京) リージョンのモデルを使用する場合、そのリージョンのAPI キーを使用し、URL を https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/embeddings に置き換える必要があります。以下のコード例では、シンガポールリージョンの URL を使用しています。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/embeddings' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen3.7-text-embedding",
"input": [
"The wind is strong, the sky is high, and the apes cry mournfully.",
"The islet is clear, the sand is white, and the birds fly back.",
"The boundless forest sheds its leaves shower by shower.",
"The endless river rolls on wave after wave."
],
"dimensions": 1024,
"encoding_format": "float"
}'
入力ファイルPythonimport os
from openai import OpenAI
client = OpenAI(
# 中国 (北京) リージョンのモデルを使用する場合、そのリージョンの API キーを使用する必要があります。取得先: https://modelstudio.console.alibabacloud.com/?tab=model#/api-key
api_key=os.getenv("DASHSCOPE_API_KEY"), # 環境変数が設定されていない場合は、プレースホルダーをご利用の API キーに置き換えてください。
# これはシンガポールリージョンの URL です。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)
# 'texts_to_embedding.txt' をご利用のファイル名またはパスに置き換えてください。
with open('texts_to_embedding.txt', 'r', encoding='utf-8') as f:
completion = client.embeddings.create(
model="qwen3.7-text-embedding",
input=f,
encoding_format="float"
)
print(completion.model_dump_json())
Javaimport java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
public static void main(String[] args) {
// 環境変数から API キーを取得します。設定されていない場合は、ご利用の API キーに置き換えてください。
// 中国 (北京) リージョンのモデルを使用する場合、そのリージョンの API キーを使用する必要があります。取得先: https://modelstudio.console.alibabacloud.com/?tab=model#/api-key
String apiKey = System.getenv("DASHSCOPE_API_KEY");
if (apiKey == null) {
System.out.println("DASHSCOPE_API_KEY not found in environment variables");
return;
}
// これはシンガポールリージョンの URL です。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
String baseUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/embeddings";
HttpClient client = HttpClient.newHttpClient();
// 入力ファイルを読み取ります。
StringBuilder inputText = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new FileReader("<path_to_your_content_root>"))) {
String line;
while ((line = reader.readLine()) != null) {
inputText.append(line).append("\n");
}
} catch (IOException e) {
System.err.println("Error reading input file: " + e.getMessage());
return;
}
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("model", "qwen3.7-text-embedding");
requestBody.put("input", inputText.toString().trim());
requestBody.put("dimensions", 1024);
requestBody.put("encoding_format", "float");
try {
String requestBodyString = JsonUtils.toJson(requestBody);
// HTTP リクエストをビルドします。
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(baseUrl))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + apiKey)
.POST(HttpRequest.BodyPublishers.ofString(requestBodyString))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
System.out.println("Response: " + response.body());
} else {
System.out.printf("Failed to retrieve response, status code: %d, response: %s%n", response.statusCode(), response.body());
}
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
curl
中国 (北京) リージョンのモデルを使用する場合、そのリージョンのAPI キーを使用し、URL を https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/embeddings に置き換える必要があります。以下のコード例では、シンガポールリージョンの URL を使用しています。ご利用の実際のワークスペース ID で {WorkspaceId} を置き換えてください。URL はリージョンによって異なります。
'texts_to_embedding.txt' をご利用のファイル名またはパスに置き換えてください。
FILE_CONTENT=$(cat texts_to_embedding.txt | jq -Rs .)
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/embeddings' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen3.7-text-embedding",
"input": ['"$FILE_CONTENT"'],
"dimensions": 1024,
"encoding_format": "float"
}'
|