# Embeddings

> Turn text into vectors with an embedding model.

**POST** `https://deference.si/v1/embeddings`

Follows OpenAI's Embeddings format. Use an embedding model from [`/models?type=embeddings`](https://deference.si/models?type=embeddings), or from `GET /v1/models`, which lists them with an embeddings output modality. Send the key as `Authorization: Bearer sk-df-...` or `x-api-key`.

## Example

**curl**

```bash
curl https://deference.si/v1/embeddings \
  -H "Authorization: Bearer $DEFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/text-embedding-3-small",
    "input": "A ledger is a list of entries."
  }'
```

**Python**

```python
import os
from openai import OpenAI

client = OpenAI(base_url="https://deference.si/v1", api_key=os.environ["DEFERENCE_API_KEY"])

result = client.embeddings.create(
    model="openai/text-embedding-3-small",
    input="A ledger is a list of entries.",
)
print(len(result.data[0].embedding))
```

**TypeScript**

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://deference.si/v1",
  apiKey: process.env.DEFERENCE_API_KEY,
});

const result = await client.embeddings.create({
  model: "openai/text-embedding-3-small",
  input: "A ledger is a list of entries.",
});
console.log(result.data[0].embedding.length);
```

## Request body

* `model` (string, required): An embedding model id.
* `input` (string | array, required): The text to embed, or an array of strings.
* `encoding_format` (string): `float` (default) or `base64`.
* `dimensions` (integer): Output size, for models that support shortening.

## Response

```json
{
  "object": "list",
  "data": [{ "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456] }],
  "model": "openai/text-embedding-3-small",
  "usage": { "prompt_tokens": 8, "total_tokens": 8 }
}
```

The `embedding` array is shortened here. Embeddings are charged for input tokens.
