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

# Embeddings

> Embed text with the embedding models of OpenAI, Azure, Mistral and Alibaba, with the OpenAI Embeddings format.

The body is an [OpenAI Embeddings request](https://platform.openai.com/docs/api-reference/embeddings/create): the gateway sends it to the provider with `model` replaced by the provider's own model id, and answers with the provider's response. Point any OpenAI client at `https://gateway.weflayr.com/v1` with a [Gateway API key](https://docs.weflayr.com/product/api-keys.md).

## OpenAI fields

The gateway reads `model`, `input` (a string, a list of strings, or token ids), `encoding_format`, `dimensions` and `user`. Any other field is sent to the provider as is, including `provider_options` and `self_heal`, which are not read here. `provider_api_key` is refused.

> [!NOTE]
>
> Only embedding models of `openai`, `azure`, `mistral` and `alibaba` are served. Mistral answers float arrays only, whatever `encoding_format` says.

## Weflayr fields

The gateway reads these fields on top of the OpenAI ones and never sends them to the provider. With the OpenAI SDK, pass them in `extra_body` (Python) or as extra keys of the request object (Node.js).

**model** `string` *required*

An embedding model name (e.g. `text-embedding-3-small`), as [`GET /v1/models`](https://docs.weflayr.com/api/gateway/models) lists them. Do not prefix the name with the provider: the provider goes in `provider`. Routing strategies are not served here.

**provider** `string`

Serve the model from this provider only: `alibaba`, `azure`, `mistral` or `openai`. Omit to let Weflayr pick one.

**region** `string`

Serve the model from this region only: `GLOBAL`, `US` or `EU`. Omit to let Weflayr pick one, preferring `GLOBAL`, then `US`, then `EU`.

**weflayr** `object`

What the call is for, shown on your dashboards.

**properties**

**customer\_name** `string`

The customer the call is made for. It joins your AI cost to your [revenue](https://docs.weflayr.com/product/cost-and-revenue). Defaults to the OpenAI `user` field.

**call\_name** `string`

The name of this LLM call inside its feature, e.g. `embed_ticket`.

**tags** `\{string: string\}`

Your own dimensions to filter on, e.g. `{"environment": "production"}`. At most 64, with keys of 1 to 128 bytes and values of at most 1,024 bytes.

**store\_message\_content** `boolean` (default: true)

Keep the embedded text. Set `false` to keep only tokens, cost and latency.

**x-weflayr-metadata** `JSON object`

The feature the call belongs to, as `{"feature_name": "search"}`. It also takes `feature_run_uuid` (32 hex characters, to group the calls of one feature run), `customer_name`, `call_name` and `tags`; the body's `weflayr` values win over the header's. The [SDKs](https://docs.weflayr.com/sdks/python.md#send-metadata-to-the-gateway) set this header for you.

## Response

An OpenAI embedding list, with the fields the provider sent.

## Errors

A model that is not an embedding model, or a provider that serves no embeddings, returns a 400 `embeddings_unsupported`. For the other errors, see [Errors](https://docs.weflayr.com/api/introduction.md#errors).

```python Python theme={null}
from openai import OpenAI

client = OpenAI(base_url="https://gateway.weflayr.com/v1", api_key="<WEFLAYR_API_KEY>")

embeddings = client.embeddings.create(
    model="text-embedding-3-small",
    input="The quick brown fox jumps over the lazy dog.",
    extra_headers={"x-weflayr-metadata": '{"feature_name": "search"}'},
    extra_body={"provider": "openai", "weflayr": {"customer_name": "acme", "call_name": "embed_query"}},
)
```

```js Node.js theme={null}
const OpenAI = require('openai');

const client = new OpenAI({ baseURL: 'https://gateway.weflayr.com/v1', apiKey: '<WEFLAYR_API_KEY>' });

const embeddings = await client.embeddings.create(
  {
    model: 'text-embedding-3-small',
    input: 'The quick brown fox jumps over the lazy dog.',
    provider: 'openai',
    weflayr: { customer_name: 'acme', call_name: 'embed_query' },
  },
  { headers: { 'x-weflayr-metadata': JSON.stringify({ feature_name: 'search' }) } },
);
```

```bash cURL theme={null}
curl https://gateway.weflayr.com/v1/embeddings \
  -H "Authorization: Bearer $WEFLAYR_API_KEY" \
  -H "Content-Type: application/json" \
  -H 'x-weflayr-metadata: {"feature_name": "search"}' \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The quick brown fox jumps over the lazy dog.",
    "provider": "openai",
    "weflayr": {"customer_name": "acme", "call_name": "embed_query"}
  }'
```

```json 200 theme={null}
{
  "object": "list",
  "data": [
    {"object": "embedding", "index": 0, "embedding": [0.0023064255, -0.009327292, 0.015797347]}
  ],
  "model": "text-embedding-3-small",
  "usage": {"prompt_tokens": 10, "total_tokens": 10}
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.