メインコンテンツへスキップ

リクエストボディ

同期リクエストのタイムアウト: この非チャットエンドポイントは、ルーティング先モデルの処理完了を待ちます。大きな入力、長い音声、大きなバッチは一般的な 30s のクライアント既定値を超えることがあるため、HTTP クライアントのタイムアウトは少なくとも 120s に設定してください。
model
string
必須
使用する embedding モデルの ID(例: text-embedding-3-small)。
input
string | array
必須
embedding 化する入力テキスト。文字列または文字列の配列を指定できます。
encoding_format
string
デフォルト:"float"
embeddings の形式: float または base64
dimensions
integer
出力の次元数(モデル固有)。
user
string
不正使用の監視のためにエンドユーザーを表す一意の識別子。

利用可能なモデル

モデル次元説明
text-embedding-3-large3072最高品質
text-embedding-3-small1536バランス型
text-embedding-ada-0021536レガシー

レスポンス

object
string
常に list です。
data
array
embedding オブジェクトの配列。各オブジェクトには以下が含まれます:
  • object (string): embedding
  • index (integer): 入力配列内のインデックス
  • embedding (array): embedding ベクトル
model
string
使用されたモデル。
usage
object
prompt_tokens および total_tokens を含む token 使用量。
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"
  }'
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.tokenlab.sh/v1"
)

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="The quick brown fox jumps over the lazy dog"
)

embedding = response.data[0].embedding
print(f"Embedding dimension: {len(embedding)}")
print(f"First 5 values: {embedding[:5]}")
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'sk-your-api-key',
  baseURL: 'https://api.tokenlab.sh/v1'
});

const response = await client.embeddings.create({
  model: 'text-embedding-3-small',
  input: 'The quick brown fox jumps over the lazy dog'
});

console.log(response.data[0].embedding.slice(0, 5));
<?php
$ch = curl_init('https://api.tokenlab.sh/v1/embeddings');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer sk-your-api-key'
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'model' => 'text-embedding-3-small',
        'input' => 'The quick brown fox jumps over the lazy dog'
    ])
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
print_r(array_slice($data['data'][0]['embedding'], 0, 5));
{
  "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")