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"}},
)
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' }) } },
);
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"}
}'
{
"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}
}
Gateway
Embeddings
Embed text with the embedding models of OpenAI, Azure, Mistral and Alibaba, with the OpenAI Embeddings format.
POST
/
v1
/
embeddings
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"}},
)
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' }) } },
);
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"}
}'
{
"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}
}
The body is an OpenAI Embeddings request: 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.
OpenAI fields
The gateway readsmodel, 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.
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 inextra_body (Python) or as extra keys of the request object (Node.js).
string
required
An embedding model name (e.g.
text-embedding-3-small), as GET /v1/models lists them. Do not prefix the name with the provider: the provider goes in provider. Routing strategies are not served here.string
Serve the model from this provider only:
alibaba, azure, mistral or openai. Omit to let Weflayr pick one.string
Serve the model from this region only:
GLOBAL, US or EU. Omit to let Weflayr pick one, preferring GLOBAL, then US, then EU.object
What the call is for, shown on your dashboards.
Show properties
Show properties
string
The customer the call is made for. It joins your AI cost to your revenue. Defaults to the OpenAI
user field.string
The name of this LLM call inside its feature, e.g.
embed_ticket.{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.boolean
default:"true"
Keep the embedded text. Set
false to keep only tokens, cost and latency.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 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 400embeddings_unsupported. For the other errors, see Errors.
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"}},
)
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' }) } },
);
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"}
}'
{
"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}
}