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

# OpenAI Embedding

***

## Request

<CodeGroup>
  ```shellscript cURL theme={null}
  curl --location 'https://api.znapai.com/v1/embeddings' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer $ZnapAI_API_KEY' \
  --data '{
      "input": "The food was delicious and the waiter...",
      "model": "text-embedding-ada-002",
      "encoding_format": "float"
    }'
  ```

  ```python OpenAI SDK (Python) theme={null}
  import openai
  client = openai.OpenAI(
      api_key="$ZnapAI_API_KEY",
      base_url="https://api.znapai.com/"
  )

  response = client.embeddings.create(
      model="text-embedding-ada-002",
      input="The food was delicious and the waiter...",
      encoding_format="float"
  )

  print(response)
  ```

  ```javascript OpenAI SDK (JS) theme={null}
  import OpenAI from "openai";
  const openai = new OpenAI({
    apiKey: "$ZnapAI_API_KEY",
    baseURL: "https://api.znapai.com/"
  });

  const response = await openai.embeddings.create({
    model: "text-embedding-ada-002",
    input: "The food was delicious and the waiter...",
    encoding_format: "float",
  });

  console.log(response);
  ```
</CodeGroup>

## Response

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        0.001287413,
        -0.0028842222
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}
```

***

## Parameters

<ParamField path="input" type="string | array" required>
  Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays.

  The input must not exceed the max input tokens for the model (8192 tokens for all embedding models), cannot be an empty string, and any array must be 2048 dimensions or less. In addition to the per-input token limit, all embedding models enforce a maximum of 300,000 tokens summed across all inputs in a single request.

  Supported formats:

  * `string`: The string that will be turned into an embedding.
  * `array of strings`: The array of strings that will be turned into an embedding.
  * `array of numbers`: The array of integers (tokens) that will be turned into an embedding.
  * `array of arrays of numbers`: The array of arrays containing integers (tokens) that will be turned into an embedding.
</ParamField>

<ParamField path="model" type="string" required>
  ID of the model to use.

  Supported models:

  * `text-embedding-ada-002`
  * `text-embedding-3-small`
  * `text-embedding-3-large`
</ParamField>

<ParamField path="dimensions" type="integer">
  The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.
</ParamField>

<ParamField path="encoding_format" type="string" default="float">
  The format to return the embeddings in.

  Options:

  * `float`
  * `base64`
</ParamField>

<ParamField path="user" type="string">
  A unique identifier representing your end-user, which can help monitor and detect abuse.
</ParamField>

***

## Returns

The response is a `CreateEmbeddingResponse` object containing the generated embeddings and usage statistics.

<ResponseField name="object" type="string">
  The object type, which is always `"list"`.
</ResponseField>

<ResponseField name="data" type="array">
  The list of embeddings generated by the model.

  <Expandable title="data[]" defaultOpen="true">
    <ResponseField name="object" type="string">
      The object type, which is always `"embedding"`.
    </ResponseField>

    <ResponseField name="embedding" type="array">
      The embedding vector, which is a list of floats. The length of the vector depends on the model and the `dimensions` parameter.
    </ResponseField>

    <ResponseField name="index" type="integer">
      The index of the embedding in the list of embeddings.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="model" type="string">
  The name of the model used to generate the embedding.
</ResponseField>

<ResponseField name="usage" type="object">
  The usage information for the request.

  <Expandable title="usage" defaultOpen="true">
    <ResponseField name="prompt_tokens" type="integer">
      The number of tokens used by the prompt.
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      The total number of tokens used by the request.
    </ResponseField>
  </Expandable>
</ResponseField>
