通用 Embedding 接口规范
文本向量化接口将文本转换为高维向量表示,用于语义搜索、文本分类、聚类等场景。
| 项目 | 值 |
|---|---|
| Base URL | https://api.taiha.cn/v1 |
| API Key | 在控制台创建 |
| Model ID | 在模型广场查看 |
鉴权方式:所有协议统一使用
Authorization: Bearer <API Key>请求头。
向量化请求
POST /v1/embeddings
- cURL
- Python
curl -X POST 'https://api.taiha.cn/v1/embeddings' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <API Key>' \
-d '{
"model": "<Model ID>",
"input": "你好"
}'
import requests
url = "https://api.taiha.cn/v1/embeddings"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <API Key>",
}
payload = {
"model": "<Model ID>",
"input": "你好"
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
print(result)
if "data" in result:
print("Assistant:", result["data"][0]["embedding"])
常用参数
model string 必填 | 模型ID
string 必填 | 模型ID- 模型ID,请按照模型广场中模型所示名称填写,区分大小写。
- 您也可以通过请求端点models来获得所有可请求的模型列表。
input string 必填 | 向量文本
string 必填 | 向量文本要转换为向量的输入文本。可以是单个字符串,或字符串数组(批量处理)
encoding_format string 可选 | 返回格式
string 可选 | 返回格式返回向量的编码格式。可选值:float 或 base64,默认 float
dimensions integer 可选 | 向量维度
integer 可选 | 向量维度返回向量的维度数,仅部分模型支持
user string 可选 | 用户标识
string 可选 | 用户标识最终用户的唯一标识符,用于监控和检测滥用行为