文本嵌入
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "embedding-3",
"input": "你好,今天天气怎么样.",
"dimensions": 2
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/embeddings"
payload = {
"model": "embedding-3",
"input": "你好,今天天气怎么样.",
"dimensions": 2
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'embedding-3', input: '你好,今天天气怎么样.', dimensions: 2})
};
fetch('https://open.bigmodel.cn/api/paas/v4/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"embedding-3\",\n \"input\": \"你好,今天天气怎么样.\",\n \"dimensions\": 2\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/embeddings"
payload := strings.NewReader("{\n \"model\": \"embedding-3\",\n \"input\": \"你好,今天天气怎么样.\",\n \"dimensions\": 2\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'embedding-3',
'input' => '你好,今天天气怎么样.',
'dimensions' => 2
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"model": "<string>",
"object": "list",
"data": [
{
"index": 123,
"object": "embedding",
"embedding": [
123
]
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}模型 API
文本嵌入
使用 GLM Embedding 系列模型将文本转换为高维向量表示,用于语义相似性和搜索。点击 Try it 按钮可快速试用。
POST
/
paas
/
v4
/
embeddings
文本嵌入
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "embedding-3",
"input": "你好,今天天气怎么样.",
"dimensions": 2
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/embeddings"
payload = {
"model": "embedding-3",
"input": "你好,今天天气怎么样.",
"dimensions": 2
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'embedding-3', input: '你好,今天天气怎么样.', dimensions: 2})
};
fetch('https://open.bigmodel.cn/api/paas/v4/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"embedding-3\",\n \"input\": \"你好,今天天气怎么样.\",\n \"dimensions\": 2\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/embeddings"
payload := strings.NewReader("{\n \"model\": \"embedding-3\",\n \"input\": \"你好,今天天气怎么样.\",\n \"dimensions\": 2\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'embedding-3',
'input' => '你好,今天天气怎么样.',
'dimensions' => 2
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"model": "<string>",
"object": "list",
"data": [
{
"index": 123,
"object": "embedding",
"embedding": [
123
]
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Body
application/json
嵌入模型名称,如 embedding-3、embedding-2
Available options:
embedding-3, embedding-2 输入文本,支持字符串或字符串数组。
embedding-2的单条请求最多支持512个Tokens,数组总长度不得超过8Kembedding-3的单条请求最多支持3072个Tokens,且数组最大不得超过64条
输出向量维度,Embedding-3 默认 2048,Embedding-2 固定 1024。Embedding-3 支持自定义,可选值:256、512、1024或2048。
Available options:
2048, 1024, 512, 256 Required range:
x >= 1Was this page helpful?
⌘I