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

# POST /v1/embeddings

> Proxy endpoint for embeddings with authentication and tracking

## Overview

The proxy embeddings endpoint provides OpenAI-compatible embedding generation with authentication, rate limiting, and cost tracking.

## Endpoint

```
POST {PROXY_BASE_URL}/v1/embeddings
```

Alternate routes:

* `POST /embeddings`
* `POST /engines/{model}/embeddings`
* `POST /openai/deployments/{model}/embeddings`

## Authentication

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication.

  ```
  Authorization: Bearer sk-litellm-xxx...
  ```
</ParamField>

## Request Headers

<ParamField header="Content-Type" type="string" default="application/json">
  Content type of the request body.
</ParamField>

<ParamField header="x-litellm-user-id" type="string">
  End-user ID for tracking.
</ParamField>

<ParamField header="x-litellm-metadata" type="string">
  JSON stringified metadata.
</ParamField>

## Request Body

<ParamField body="model" type="string" required>
  Embedding model to use.

  Examples: `text-embedding-3-small`, `text-embedding-ada-002`
</ParamField>

<ParamField body="input" type="string | array" required>
  Text to embed. Can be a single string or array of strings.

  ```json theme={null}
  {
    "input": "The quick brown fox"
  }
  ```

  Or:

  ```json theme={null}
  {
    "input": ["First text", "Second text", "Third text"]
  }
  ```
</ParamField>

<ParamField body="encoding_format" type="string" default="float">
  Format of the embeddings.

  Options: `"float"`, `"base64"`
</ParamField>

<ParamField body="dimensions" type="integer">
  Number of dimensions for the embedding (text-embedding-3 models only).
</ParamField>

<ParamField body="user" type="string">
  Unique identifier for end-user.
</ParamField>

## Response

### Success Response (200)

<ResponseField name="object" type="string">
  Object type, always "list".
</ResponseField>

<ResponseField name="data" type="array">
  Array of embedding objects.

  <Expandable title="embedding object">
    <ResponseField name="object" type="string">
      Object type, always "embedding".
    </ResponseField>

    <ResponseField name="embedding" type="array">
      The embedding vector as array of floats.
    </ResponseField>

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

<ResponseField name="model" type="string">
  Model used for embeddings.
</ResponseField>

<ResponseField name="usage" type="object">
  Token usage information.

  <Expandable title="usage object">
    <ResponseField name="prompt_tokens" type="integer">
      Number of tokens in the input.
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      Total tokens used.
    </ResponseField>
  </Expandable>
</ResponseField>

## Examples

### Basic Request

```bash theme={null}
curl -X POST http://localhost:4000/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-litellm-xxx" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The quick brown fox jumps over the lazy dog"
  }'
```

### Python Request

```python theme={null}
import openai

client = openai.OpenAI(
    api_key="sk-litellm-xxx",
    base_url="http://localhost:4000"
)

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

print(response.data[0].embedding)
```

### Batch Embeddings

```python theme={null}
import openai

client = openai.OpenAI(
    api_key="sk-litellm-xxx",
    base_url="http://localhost:4000"
)

texts = [
    "First document",
    "Second document",
    "Third document"
]

response = client.embeddings.create(
    model="text-embedding-3-small",
    input=texts
)

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

### With User Tracking

```python theme={null}
import openai

client = openai.OpenAI(
    api_key="sk-litellm-xxx",
    base_url="http://localhost:4000"
)

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="Sample text",
    extra_headers={
        "x-litellm-user-id": "user-123"
    }
)
```

### Custom Dimensions

```python theme={null}
import openai

client = openai.OpenAI(
    api_key="sk-litellm-xxx",
    base_url="http://localhost:4000"
)

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="Sample text",
    dimensions=512  # Reduce from default 1536
)

print(len(response.data[0].embedding))  # 512
```

## Error Responses

### 401 Unauthorized

```json theme={null}
{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}
```

### 429 Too Many Requests

```json theme={null}
{
  "error": {
    "message": "Rate limit exceeded for key",
    "type": "rate_limit_error"
  }
}
```

### 400 Bad Request

```json theme={null}
{
  "error": {
    "message": "Invalid input format",
    "type": "invalid_request_error"
  }
}
```

## Proxy Features

### Cost Tracking

The proxy automatically tracks embedding costs:

* Per-key spending
* Per-team spending
* Per-user spending

### Rate Limiting

Keys can have TPM limits for embeddings:

* Requests throttled automatically
* 429 error when limit exceeded

### Model Routing

Proxy can route to different embedding providers:

* OpenAI
* Azure OpenAI
* Cohere
* Bedrock
* Vertex AI
* And more!

## Related

* [POST /v1/chat/completions](/api/proxy/chat-completions)
* [Key Management](/api/proxy/keys)
* [Usage Tracking](https://docs.litellm.ai/docs/proxy/users)
