> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# 임베딩 생성

> 입력 텍스트를 나타내는 임베딩 벡터를 생성합니다

## 요청 본문

**동기 요청 타임아웃:** 이 비채팅 엔드포인트는 라우팅된 모델이 완료될 때까지 기다립니다. 큰 입력, 긴 오디오, 큰 배치는 일반적인 30s 클라이언트 기본값을 초과할 수 있으므로 HTTP 클라이언트 타임아웃을 최소 `120s` 로 설정하세요.

<ParamField body="model" type="string" required>
  사용할 임베딩 모델의 ID입니다 (예: `text-embedding-3-small`).
</ParamField>

<ParamField body="input" type="string | array" required>
  임베딩할 입력 텍스트입니다. 문자열 또는 문자열 배열이 될 수 있습니다.
</ParamField>

<ParamField body="encoding_format" type="string" default="float">
  임베딩의 형식입니다: `float` 또는 `base64`.
</ParamField>

<ParamField body="dimensions" type="integer">
  출력 차원 수입니다 (모델별 상이).
</ParamField>

<ParamField body="user" type="string">
  오용 모니터링을 위해 최종 사용자를 나타내는 고유 식별자입니다.
</ParamField>

## 사용 가능한 모델

| 모델                       | 차원   | 설명    |
| ------------------------ | ---- | ----- |
| `text-embedding-3-large` | 3072 | 최고 품질 |
| `text-embedding-3-small` | 1536 | 균형형   |
| `text-embedding-ada-002` | 1536 | 레거시   |

## 응답

<ResponseField name="object" type="string">
  항상 `list`입니다.
</ResponseField>

<ResponseField name="data" type="array">
  임베딩 객체의 배열입니다.

  각 객체는 다음을 포함합니다:

  * `object` (string): `embedding`
  * `index` (integer): 입력 배열 내 인덱스
  * `embedding` (array): 임베딩 벡터
</ResponseField>

<ResponseField name="model" type="string">
  사용된 모델입니다.
</ResponseField>

<ResponseField name="usage" type="object">
  `prompt_tokens` 및 `total_tokens`를 포함한 Token 사용량입니다.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  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"
    }'
  ```

  ```python Python theme={null}
  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]}")
  ```

  ```javascript JavaScript theme={null}
  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 PHP theme={null}
  <?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));
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "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
    }
  }
  ```
</ResponseExample>

## 배치 임베딩

```python theme={null}
# 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")
```
