# Embeddings (https://inference.net/docs/api/embeddings)

The Embeddings API returns one vector for each input in one request. It is compatible with the OpenAI embeddings API. Use it with an embedding model. An embedding model serves only embeddings requests.

## Endpoint

```
POST https://api.inference.net/v1/embeddings
```

Send your API key in the `Authorization: Bearer` header, as for other endpoints. The response is one JSON object. The endpoint does not stream.

To send embeddings requests asynchronously, use `POST /v1/slow/embeddings`. See [Asynchronous Inference](/docs/api/async/overview/).

## Request

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | Yes | The identifier of an embedding model. |
| `input` | string or array | Yes | The input to embed: a string, an array of strings, a token-id array, or an array of token-id arrays. Image models also accept image messages (see below). |
| `encoding_format` | string | No | `float` (the default) returns each vector as an array of numbers. `base64` returns each vector as a base64 string of little-endian float32 values. |
| `dimensions` | integer | No | The number of dimensions of each vector. Only models that support shortened vectors accept it. |
| `user` | string | No | An identifier for your end user. |

An image input is an array that holds one user message with one `image_url` part. The URL is a base64 data URI (`image/png`, `image/jpeg`, `image/gif` or `image/webp`) or an `https` URL. To embed several images, send an array of these messages (at most 50).

<CodeTabs>

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.inference.net/v1",
  apiKey: process.env.INFERENCE_API_KEY,
});

const response = await client.embeddings.create({
  model: "<embedding-model>",
  input: ["The quick brown fox", "jumps over the lazy dog"],
});

console.log(response.data[0].embedding);
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.inference.net/v1",
    api_key=os.environ["INFERENCE_API_KEY"],
)

response = client.embeddings.create(
    model="<embedding-model>",
    input=["The quick brown fox", "jumps over the lazy dog"],
)

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

```bash
curl https://api.inference.net/v1/embeddings \
  -H "Authorization: Bearer $INFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<embedding-model>",
    "input": ["The quick brown fox", "jumps over the lazy dog"]
  }'
```

</CodeTabs>

An image input:

```json
{
  "model": "<image-embedding-model>",
  "input": [
    {
      "role": "user",
      "content": [{ "type": "image_url", "image_url": { "url": "https://example.com/cat.png" } }]
    }
  ]
}
```

An `https://` image URL must use a public host name that resolves to public addresses, stay on `https://` across redirects (up to 4 hops), and return a PNG, JPEG, GIF or WebP image of at most 384 KiB within 10 seconds. The worker retries HTTP 408, 429, 5xx, dropped connections and timeouts twice. If a fetch still fails with HTTP 408, 429, 5xx or a timeout, synchronous `POST /v1/embeddings` returns HTTP `503` (`image_fetch_unavailable`) for you to retry with backoff (completion-window redispatch applies only to async `POST /v1/slow/embeddings`); permanent failures such as HTTP 403/404, oversized payloads, invalid image types or disallowed hosts return HTTP `400` (`invalid_image_url`).

## Response

| Field | Type | Description |
| --- | --- | --- |
| `object` | string | Always `list`. |
| `data` | array | One item for each input, in input order. Each item is `{"object": "embedding", "index": <position>, "embedding": <vector>}`. |
| `model` | string | The model identifier you sent. |
| `usage.prompt_tokens` | integer | The number of input tokens. |
| `usage.total_tokens` | integer | The same as `usage.prompt_tokens`. |

```json
{
  "object": "list",
  "data": [
    { "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456, "..."] },
    { "object": "embedding", "index": 1, "embedding": [0.0789, 0.0012, "..."] }
  ],
  "model": "<embedding-model>",
  "usage": { "prompt_tokens": 10, "total_tokens": 10 }
}
```

The `x-inference-id` response header contains the generation id.

## Billing

You pay for `usage.prompt_tokens` as input tokens. There are no output tokens.

## Errors

Errors use the same JSON shape as other endpoints: `{"error": {"message": "...", "type": "..."}}`.

| Status | Cause |
| --- | --- |
| 400 | The body is not valid: `input` or `model` is missing, `input` has the wrong shape, `encoding_format` is not `float` or `base64`, or `dimensions` is not a positive integer. `error.fields` names each bad field. |
| 400 | The model is not an embedding model. |
| 403 | Your team does not have access to the model. |
| 404 | The model does not exist. |

If the upstream provider returns an error without a JSON body, you get `error.type` `upstream_error` with the upstream HTTP status and `content-type: application/json`. `error.request_id` matches the `X-Request-Id` response header. Anthropic-format (`/v1/messages`) errors omit `error.request_id`; use the header.