Gemini embedContent 基础接口
curl --request POST \
--url https://kaienapi.com/v1beta/models/{model}:embedContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content": {
"parts": [
{
"text": "需要向量化的文本"
}
]
}
}
'import requests
url = "https://kaienapi.com/v1beta/models/{model}:embedContent"
payload = { "content": { "parts": [{ "text": "需要向量化的文本" }] } }
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({content: {parts: [{text: '需要向量化的文本'}]}})
};
fetch('https://kaienapi.com/v1beta/models/{model}:embedContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://kaienapi.com/v1beta/models/{model}:embedContent"
payload := strings.NewReader("{\n \"content\": {\n \"parts\": [\n {\n \"text\": \"需要向量化的文本\"\n }\n ]\n }\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))
}{}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}Gemini embedContent 基础接口
Gemini 原生向量接口,用于按 Gemini content.parts 结构生成文本向量。
请求格式
模型名放在路径 {model} 中。请求体使用 Gemini 原生结构,把文本放入 content.parts[].text。按用途补充 taskType 和 title。
适用位置
- 已经使用 Gemini 原生 SDK 或 AI Studio payload。
- 保留 Gemini 的 embedding 请求结构。
- 给检索、聚类或相似度计算生成向量。
读取结果
响应结构按 Gemini embedContent 风格返回。写入向量库前,确认输出维度与目标 collection 一致。
POST
/
v1beta
/
models
/
{model}
:embedContent
Gemini embedContent 基础接口
curl --request POST \
--url https://kaienapi.com/v1beta/models/{model}:embedContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content": {
"parts": [
{
"text": "需要向量化的文本"
}
]
}
}
'import requests
url = "https://kaienapi.com/v1beta/models/{model}:embedContent"
payload = { "content": { "parts": [{ "text": "需要向量化的文本" }] } }
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({content: {parts: [{text: '需要向量化的文本'}]}})
};
fetch('https://kaienapi.com/v1beta/models/{model}:embedContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://kaienapi.com/v1beta/models/{model}:embedContent"
payload := strings.NewReader("{\n \"content\": {\n \"parts\": [\n {\n \"text\": \"需要向量化的文本\"\n }\n ]\n }\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))
}{}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}