> ## 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.

# Criar Embedding

> Cria um vetor de embedding representando o texto de entrada

## Corpo da Requisição

**Timeout de solicitações síncronas:** este endpoint não-chat aguarda o modelo roteado terminar. Entradas grandes, áudios longos ou lotes grandes podem exceder os padrões comuns de 30s dos clientes, então configure o timeout do seu cliente HTTP para pelo menos `120s`.

<ParamField body="model" type="string" required>
  ID do modelo de embedding a ser usado (ex.: `text-embedding-3-small`).
</ParamField>

<ParamField body="input" type="string | array" required>
  Texto de entrada para gerar embedding. Pode ser uma string ou um array de strings.
</ParamField>

<ParamField body="encoding_format" type="string" default="float">
  Formato para os embeddings: `float` ou `base64`.
</ParamField>

<ParamField body="dimensions" type="integer">
  Número de dimensões para a saída (específico do modelo).
</ParamField>

<ParamField body="user" type="string">
  Um identificador único representando seu usuário final para monitoramento de abuso.
</ParamField>

## Modelos Disponíveis

| Modelo                   | Dimensões | Descrição        |
| ------------------------ | --------- | ---------------- |
| `text-embedding-3-large` | 3072      | Melhor qualidade |
| `text-embedding-3-small` | 1536      | Equilibrado      |
| `text-embedding-ada-002` | 1536      | Legado           |

## Resposta

<ResponseField name="object" type="string">
  Sempre `list`.
</ResponseField>

<ResponseField name="data" type="array">
  Array de objetos de embedding.

  Cada objeto contém:

  * `object` (string): `embedding`
  * `index` (integer): Índice no array de entrada
  * `embedding` (array): O vetor de embedding
</ResponseField>

<ResponseField name="model" type="string">
  Modelo usado.
</ResponseField>

<ResponseField name="usage" type="object">
  Uso de tokens com `prompt_tokens` e `total_tokens`.
</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>

## Embeddings em Lote

```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")
```
