文本向量
SenseTime TokenPlan 当前模型与接入说明
文本向量
把输入转换成向量。当前文本向量模型为 qwen3.7-text-embedding。
请求地址
POST https://token.sensetime.com/api/v1/embeddings
- Content-Type:
application/json - OpenAI 兼容客户端的
base_url/baseURL填写https://token.sensetime.com/api/v1,不要再额外拼接/v1。embeddings.create对应此路径。 - 请求体不超过 4 MiB。未定义字段会被拒绝。
授权
请求必须携带 API Key:
Authorization: Bearer <API_KEY>
将 <API_KEY> 替换为工作台创建的密钥。下面的示例使用环境变量 TOKENPLAN_API_KEY。
模型选择
当前文本向量模型:qwen3.7-text-embedding。
调用前查询模型列表,确认被选模型实际返回的 mode 为 embedding。
请求体
fallbacks 当前仅接受空值,不要传入。
模型 ID。
文本、文本数组、token 数组、token 数组列表,或模型支持的多模态输入。不能为空,同一数组不能混用不同形式。批量最多 2048 条。
float 或 base64。
输出维度,传入时必须大于 0。
任务类型。
标题。
是否自动截断。
input 的可接受形式:
| 形式 | 示例 |
|---|---|
| 文本 | "你好" |
| 文本数组 | ["你好", "世界"] |
| token 数组 | [1, 2, 3] |
| token 数组列表 | [[1, 2], [3]] |
| 内容块数组的列表 | [[{"type": "text", "text": "你好"}]] |
| 带内容的对象数组 | [{"content": [{"type": "text", "text": "你好"}]}] |
token ID 是非负整数,且不超过 9007199254740991。
内容块 type:
| type | 要求 |
|---|---|
text | text 为非空字符串 |
tokens | tokens 为 token 数组 |
image | image 为对象 |
audio | audio 为对象 |
video | video 为对象 |
file | file 为对象 |
对象元素还可以带 params。其中 encoding_format、dimensions 的限制与请求体相同。多模态内容块是否生效,以被选模型的实际能力为准。
请求示例
curl "https://token.sensetime.com/api/v1/embeddings" \
-H "Authorization: Bearer $TOKENPLAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-text-embedding",
"input": "你好",
"encoding_format": "float"
}'响应字段
成功时 HTTP 状态码为 200,Content-Type 为 application/json。
对象类型。
向量结果。
Show child attributesHide child attributes
对象类型。
对应输入的下标。同一下标可以有多条结果。
Base64 字符串,或数值向量、向量列表。
该条结果的编码格式。
text、image、video 或 audio。统一向量时不返回。
视频模态时返回。
Show child attributesHide child attributes
开始偏移,秒。
结束偏移,秒。
实际响应的模型 ID。
Token 消耗。
Show child attributesHide child attributes
输入 token 数。
Show child attributesHide child attributes
从提示缓存读取的 token,已计入 prompt_tokens。
本次写入提示缓存的 token,已计入 prompt_tokens。
输出 token 数。
Show child attributesHide child attributes
输入与输出之和。
Show child attributesHide child attributes
Show child attributesHide child attributes
Web 搜索次数。
响应示例
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0123, -0.0456]
}
],
"model": "qwen3.7-text-embedding",
"usage": {
"prompt_tokens": 2,
"total_tokens": 2
}
}
错误处理
model 或 input 缺失、input 为空、编码不是 float 或 base64、dimensions 不是正整数,或请求体含未定义字段时,请求失败。