开发者资源

文档中心

产品指南、接入说明与 API 参考

文档中心文本向量
文本向量

文本向量

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 当前仅接受空值,不要传入。

modelstring必填

模型 ID。

inputstring | array必填

文本、文本数组、token 数组、token 数组列表,或模型支持的多模态输入。不能为空,同一数组不能混用不同形式。批量最多 2048 条。

encoding_formatstring

float 或 base64。

dimensionsinteger

输出维度,传入时必须大于 0。

task_typestring

任务类型。

titlestring

标题。

auto_truncateboolean

是否自动截断。

input 的可接受形式:

形式示例
文本"你好"
文本数组["你好", "世界"]
token 数组[1, 2, 3]
token 数组列表[[1, 2], [3]]
内容块数组的列表[[{"type": "text", "text": "你好"}]]
带内容的对象数组[{"content": [{"type": "text", "text": "你好"}]}]

token ID 是非负整数,且不超过 9007199254740991。

内容块 type:

type要求
texttext 为非空字符串
tokenstokens 为 token 数组
imageimage 为对象
audioaudio 为对象
videovideo 为对象
filefile 为对象

对象元素还可以带 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。

objectstring

对象类型。

dataobject[]

向量结果。

Show child attributesHide child attributes
objectstring

对象类型。

indexinteger

对应输入的下标。同一下标可以有多条结果。

embeddingstring | number[] | number[][]

Base64 字符串,或数值向量、向量列表。

encoding_formatstring

该条结果的编码格式。

modalitystring

text、image、video 或 audio。统一向量时不返回。

video_segmentobject

视频模态时返回。

Show child attributesHide child attributes
start_offset_secinteger

开始偏移,秒。

end_offset_secinteger

结束偏移,秒。

modelstring

实际响应的模型 ID。

usageobject

Token 消耗。

Show child attributesHide child attributes
prompt_tokensinteger

输入 token 数。

prompt_tokens_detailsobject
Show child attributesHide child attributes
text_tokensinteger
audio_tokensinteger
image_tokensinteger
cached_read_tokensinteger

从提示缓存读取的 token,已计入 prompt_tokens。

cached_write_tokensinteger

本次写入提示缓存的 token,已计入 prompt_tokens。

completion_tokensinteger

输出 token 数。

completion_tokens_detailsobject
Show child attributesHide child attributes
text_tokensinteger
accepted_prediction_tokensinteger
audio_tokensinteger
citation_tokensinteger
num_search_queriesinteger
reasoning_tokensinteger
image_tokensinteger
rejected_prediction_tokensinteger
total_tokensinteger

输入与输出之和。

tool_usageobject
Show child attributesHide child attributes
web_searchobject
Show child attributesHide child attributes
num_requestsinteger

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 不是正整数,或请求体含未定义字段时,请求失败。

相关指南