向量请求
POST https://stack.zeotrue.com/v1/embeddings,使用接口类型为 embedding 的模型。必填 model、input。input 的批量形式、长度及向量维度参数由模型决定。
先设置环境变量
将 ZEO_NEXUS_API_KEY 设置为对应网关的密钥,将示例中的 YOUR_MODEL_ID 替换为平台模型 ID。Python 先安装 requests;Node.js 使用 18 或更高版本。这里的 JavaScript 在服务端运行。
cURL · Bash / Zsh
curl --fail-with-body --show-error 'https://stack.zeotrue.com/v1/embeddings' \
-H "Authorization: Bearer $ZEO_NEXUS_API_KEY" \
-H 'Content-Type: application/json' \
--data '{
"model": "YOUR_MODEL_ID",
"input": "ZeoNexus 模型服务"
}'Python · requests
import os
import requests
url = 'https://stack.zeotrue.com/v1/embeddings'
headers = {'Authorization': "Bearer " + os.environ["ZEO_NEXUS_API_KEY"], 'Content-Type': 'application/json'}
payload = {'model': 'YOUR_MODEL_ID', 'input': 'ZeoNexus 模型服务'}
response = requests.post(url, headers=headers, json=payload, timeout=(10, 120))
response.raise_for_status()
print(response.json())Node.js · fetch
// Node.js 18+
if (!process.env.ZEO_NEXUS_API_KEY) throw new Error('请设置 ZEO_NEXUS_API_KEY');
const response = await fetch("https://stack.zeotrue.com/v1/embeddings", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.ZEO_NEXUS_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"model": "YOUR_MODEL_ID",
"input": "ZeoNexus 模型服务"
}),
signal: AbortSignal.timeout(120000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
console.log(await response.json());读取向量
{"object":"list","data":[{"object":"embedding","index":0,"embedding":[0.12,-0.03,0.08]}],"usage":{"prompt_tokens":8,"total_tokens":8}}使用 data[].index 关联输入,读取 embedding 数组。示例不是固定维度;向量库索引维度必须与模型一致。更换向量模型通常需要重新生成已有文档向量。
知识库接入
在 Dify、Continue 或 RAG 框架中为 Embedding 单独配置模型,确认同一密钥包含其授权。聊天模型、Embedding 模型和 Rerank 模型分工不同。
常见问题
model_mode_mismatch 表示模型与路径不匹配。批量输入失败时按模型限制拆分;返回维度不匹配时核对建库模型。用量和价格以平台记录为准。