TokenLab

文字

建立 Embedding

建立表示輸入文字的 embedding 向量

POST
/v1/embeddings

請求主體

輸入較多時,請將 HTTP 用戶端逾時設為至少 120s;端點會在處理完成後回傳。

modelstring必填

要使用的 embedding 模型 ID(例如:text-embedding-3-small)。

inputstring | array必填

要轉換的文字,可以是字串或字串陣列。支援 token 輸入的模型也可接收 number[](一組 token)或 number[][](多組 token)。

encoding_formatstring預設值: float

embeddings 的格式:float 或 base64。

dimensionsinteger

輸出的維度數量(依模型而定)。

userstring

代表終端使用者的唯一識別碼,用於濫用監控。

可用模型

透過 GET /v1/models?recommended_for=embedding 取得目前模型與維度資訊。

回應

objectstring

一律為 list。

dataarray

embedding 物件的陣列。

每個物件包含:

  • object (string):embedding
  • index (integer):輸入陣列中的索引
  • embedding (array | string): float 回傳數值向量,base64 回傳 Base64 字串。
modelstring

使用的模型。

usageobject

Token 使用量,包含 prompt_tokens 和 total_tokens。

請求

curl -X POST "https://api.tokenlab.sh/v1/embeddings" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The quick brown fox jumps over the lazy dog"
  }'

範例中的向量已縮短,方便閱讀。

回應

Response
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [0.0023, -0.0194, 0.0081]
    }
  ],
  "model": "text-embedding-3-small",
  "usage": {
    "prompt_tokens": 9,
    "total_tokens": 9
  }
}

批次 Embeddings

# Embed multiple texts at once
response = client.embeddings.create(
    model="text-embedding-3-small",
    input=[
        "First document text",
        "Second document text",
        "Third document text"
    ]
)

for i, data in enumerate(response.data):
    print(f"Document {i}: {len(data.embedding)} dimensions")

授權

BearerAuth
AuthorizationBearer <token>

API Key 驗證。請在 Dashboard > API > API Keys 建立或管理 API 金鑰。

位置: header

請求標頭

X-TokenLab-Delivery-Policy?string

單次請求傳遞策略。會覆寫 API key 與 Workspace 的預設值。系統會自動優先嘗試 TokenLab Verified,並可能在輸出、請求接受或建立持久性資源前切換至 Official 模式一次。

可選值

  • "auto"
  • "verified"
  • "official"

請求主體

application/json

回應

application/json

application/json

application/json

application/json

application/json

application/json

application/json