Skip to content
Try chatGet API key

Embeddings

POST /embeddings turns text into a vector. model and input are required.

Copies this page's setup instructions, to paste into your coding agent.
Show the prompt
Help me set this up to use Bayle AI, an OpenAI-compatible API. Full guide: https://docs.bayle.ai/guides/embeddings/

Goal: generate text embeddings through Bayle from this project.

1. Find or create the OpenAI client for this project (Python or Node, whichever it already uses) and point it at Bayle:
   Python: OpenAI(api_key=os.environ["BAYLE_API_KEY"], base_url="https://api.bayle.ai")
   Node: new OpenAI({ apiKey: process.env.BAYLE_API_KEY, baseURL: 'https://api.bayle.ai' })
2. Pick an embedding model: curl -s "https://api.bayle.ai/models?type=embedding" | jq -r '.data[].id'
   Show me the list and let me choose EMBEDDING_MODEL_ID.
3. Embed one string: client.embeddings.create(model=EMBEDDING_MODEL_ID, input="The quick brown fox.") and read result.data[0].embedding.
4. Embed many at once by passing an array as `input`; one request is cheaper than many. Results come back in `data`, each with an `index`: order them by `index` before using them.
5. Optional fields: `dimensions` asks for a smaller vector on models that support it; `encoding_format` is "float" (default) or "base64". With base64 each embedding is a base64 string, so decode it (Python: np.frombuffer(base64.b64decode(s), dtype=np.float32)). `user` is accepted but ignored.
6. Test: embed "The quick brown fox." and print the vector length and `usage.total_tokens` (it equals `usage.prompt_tokens`, since nothing is generated).

Rules:
1. The base URL is https://api.bayle.ai exactly as written. Append no path to it.
2. Read the key from the BAYLE_API_KEY environment variable. Never write the key itself into a file you create, a command, a commit or the chat. Where the tool keeps the key in its own settings screen, tell me where to paste it. If BAYLE_API_KEY is not set, stop and ask me to create a key at https://chat.bayle.ai/developers and export it.
3. Take model ids only from GET https://api.bayle.ai/models (no key needed). Never guess one.
4. Finish with one real test request, show me the result and list the files you changed.
result = client.embeddings.create(
model="EMBEDDING_MODEL_ID",
input="The quick brown fox.",
)
print(len(result.data[0].embedding))

Find an embedding model with GET /models?type=embedding.

Pass an array. Results come back in data, in the order the inputs were sent, each carrying its index.

result = client.embeddings.create(
model="EMBEDDING_MODEL_ID",
input=["first document", "second document", "third document"],
)
vectors = [item.embedding for item in sorted(result.data, key=lambda d: d.index)]

Batching is the cheaper path when you have many short inputs, since it is one request rather than many.

Field Type Notes
model string Required. An embedding model id.
input string or array of strings Required.
dimensions integer Requests a smaller output vector, for models that support reducing it.
encoding_format float or base64 Defaults to float.
user string Accepted for OpenAI client compatibility. Bayle does not act on it.

With encoding_format: "base64", each embedding comes back as a base64 string rather than an array of numbers. It is a smaller payload, worth it for large batches, but you have to decode it:

import base64
import numpy as np
raw = base64.b64decode(result.data[0].embedding)
vector = np.frombuffer(raw, dtype=np.float32)

The response carries usage.prompt_tokens and usage.total_tokens. For embeddings these are the same number, since nothing is generated.