Skip to main content

Embedding API

文本向量化服务,基于 BAAI/bge-small-zh-v1.5 模型。

端点

POST https://hubnode.uk/embed

text

认证

需要 Bearer Token。先在 注册页面 获取 API 密钥。

curl -X POST https://hubnode.uk/api/auth/oauth2/token \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
请求参数
参数 类型 说明
texts string[] 要向量化的文本列表
响应字段
字段 类型 说明
embeddings float[][] 512 维向量
model string 模型名称
tokens_used int 消耗的 Token 数
cURL 示例
bash
# 1. 获取 Token
JWT=$(curl -s -X POST https://hubnode.uk/api/auth/oauth2/token \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_ID","client_secret":"YOUR_SECRET"}' \
| python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")

# 2. 调用 Embedding API
curl -X POST https://hubnode.uk/embed \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{"texts":["你好世界","Hello world"]}'
Python 示例
python
import requests

# 获取 Token
resp = requests.post("https://hubnode.uk/api/auth/oauth2/token", json={
"client_id": "YOUR_ID", "client_secret": "YOUR_SECRET"
})
token = resp.json()["access_token"]

# 调用 Embedding
resp = requests.post("https://hubnode.uk/embed",
headers={"Authorization": f"Bearer {token}"},
json={"texts": ["你好世界", "Hello world"]})

print(f"向量维度: {len(resp.json()['embeddings'][0])}")
print(f"消耗 Token: {resp.json()['tokens_used']}")
JavaScript 示例
javascript
const tokenResp = await fetch("https://hubnode.uk/api/auth/oauth2/token", {
method: "POST", headers: {"Content-Type":"application/json"},
body: JSON.stringify({client_id:"YOUR_ID", client_secret:"YOUR_SECRET"})
});
const {access_token} = await tokenResp.json();

const resp = await fetch("https://hubnode.uk/embed", {
method: "POST",
headers: {"Authorization":`Bearer ${access_token}`,"Content-Type":"application/json"},
body: JSON.stringify({texts:["你好世界","Hello world"]})
});
const data = await resp.json();
console.log(`向量维度: ${data.embeddings[0].length}, 消耗Token: ${data.tokens_used}`);
响应示例
json
{
"embeddings": [
[0.12, -0.34, 0.56, ...],
[0.23, -0.45, 0.67, ...]
],
"model": "bge-small-zh-v1.5",
"tokens_used": 6
}
限制
免费套餐:每天 100 次请求

Token 有效期:1 小时

单次最大文本数:100 条