# Embeddings
`POST /v1/embeddings` converts text into vectors for search, retrieval, clustering, and classification. It accepts the
same request format as OpenAI's embeddings API, so you can use the OpenAI SDKs by changing the base URL to Keln's. API
keys, rate limits, and billing work the same as for chat completions.
=== "Python"
```python
from openai import OpenAI
client = OpenAI(base_url="https://api.keln.ai/v1", api_key="sk-keln-…")
resp = client.embeddings.create(
model="qwen/qwen3-embedding-8b",
input=["Keln runs open models.", "Paris is the capital of France."],
)
print(len(resp.data[0].embedding)) # 4096
```
=== "TypeScript"
```typescript
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.keln.ai/v1", apiKey: "sk-keln-…" });
const resp = await client.embeddings.create({
model: "qwen/qwen3-embedding-8b",
input: ["Keln runs open models.", "Paris is the capital of France."],
});
console.log(resp.data[0].embedding.length); // 4096
```
=== "cURL"
```bash
curl https://api.keln.ai/v1/embeddings \
-H "Authorization: Bearer $KELN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen/qwen3-embedding-8b",
"input": ["Keln runs open models.", "Paris is the capital of France."]
}'
```
The answer, showing only the first three values of each 4,096-dimensional vector:
```json
{
"object": "list",
"model": "qwen/qwen3-embedding-8b",
"data": [
{"object": "embedding", "index": 0, "embedding": [-0.0109, -0.0005, -0.0092, …]},
{"object": "embedding", "index": 1, "embedding": [0.0011, 0.0361, -0.0159, …]}
],
"usage": {"prompt_tokens": 15, "total_tokens": 15, "cost": 0.0000001875}
}
```
## Request
| Field | Contract |
|---|---|
| `model` | An embedding model id from [`GET /v1/models`](models.md) (rows with `output_modalities` set to `["embeddings"]`). Keln returns `400 wrong_endpoint` if you use a chat model here or an embedding model with chat completions. |
| `input` | A string or a list of up to 2,048 strings. Each string produces its own vector, in the same order. Token arrays are not supported (`400 token_input_not_supported`). |
| `dimensions` | Optional. Returns a shorter vector than the model's full length, listed on its page at [keln.ai/models](https://keln.ai/models). Unsupported lengths return `400 embedding_shape_not_supported`. Keln returns only the lengths the model produces. |
| `encoding_format` | `float` (default) or `base64`, which encodes each vector as little-endian 32-bit floats. The OpenAI SDKs request `base64` and decode it automatically. |
| `user` | Accepted. Keln removes it before forwarding the request ([privacy](../capabilities/privacy.md)). |
Unsupported fields return `400 invalid_request`.
## Consistent vectors
Search indexes depend on consistent embeddings, so Keln keeps each model's vectors consistent across requests. If a
model's usual source becomes unavailable, Keln continues serving requests, although the resulting vectors may differ
very slightly.
## Billing
Keln bills embedding models for **input tokens only**. `usage.cost` shows the exact charge, based on the model's price
in [`GET /v1/models`](models.md).
## Errors
| Code | Meaning |
|---|---|
| `token_input_not_supported` | The input contains token arrays. Send strings instead. |
| `embedding_shape_not_supported` | The model doesn't support the requested `dimensions` length. |
| `wrong_endpoint` | A chat model on this endpoint, or an embedding model on chat completions. |
| `invalid_request` | An unsupported field or more than 2,048 inputs. |
| `model_not_found`, rate and balance errors | Same as other Keln endpoints. See [Errors & limits](errors.md). |
Keys, budgets and zero data retention work the same as on chat completions.
Embeddings
POST /v1/embeddings converts text into vectors for search, retrieval, clustering, and classification. It accepts the
same request format as OpenAI's embeddings API, so you can use the OpenAI SDKs by changing the base URL to Keln's. API
keys, rate limits, and billing work the same as for chat completions.
fromopenaiimportOpenAIclient=OpenAI(base_url="https://api.keln.ai/v1",api_key="sk-keln-…")resp=client.embeddings.create(model="qwen/qwen3-embedding-8b",input=["Keln runs open models.","Paris is the capital of France."],)print(len(resp.data[0].embedding))# 4096
importOpenAIfrom"openai";constclient=newOpenAI({baseURL:"https://api.keln.ai/v1",apiKey:"sk-keln-…"});constresp=awaitclient.embeddings.create({model:"qwen/qwen3-embedding-8b",input:["Keln runs open models.","Paris is the capital of France."],});console.log(resp.data[0].embedding.length);// 4096
curlhttps://api.keln.ai/v1/embeddings\-H"Authorization: Bearer $KELN_API_KEY"\-H"Content-Type: application/json"\-d'{ "model": "qwen/qwen3-embedding-8b", "input": ["Keln runs open models.", "Paris is the capital of France."] }'
The answer, showing only the first three values of each 4,096-dimensional vector:
An embedding model id from GET /v1/models (rows with output_modalities set to ["embeddings"]). Keln returns 400 wrong_endpoint if you use a chat model here or an embedding model with chat completions.
input
A string or a list of up to 2,048 strings. Each string produces its own vector, in the same order. Token arrays are not supported (400 token_input_not_supported).
dimensions
Optional. Returns a shorter vector than the model's full length, listed on its page at keln.ai/models. Unsupported lengths return 400 embedding_shape_not_supported. Keln returns only the lengths the model produces.
encoding_format
float (default) or base64, which encodes each vector as little-endian 32-bit floats. The OpenAI SDKs request base64 and decode it automatically.
user
Accepted. Keln removes it before forwarding the request (privacy).
Unsupported fields return 400 invalid_request.
Consistent vectors
Search indexes depend on consistent embeddings, so Keln keeps each model's vectors consistent across requests. If a
model's usual source becomes unavailable, Keln continues serving requests, although the resulting vectors may differ
very slightly.
Billing
Keln bills embedding models for input tokens only. usage.cost shows the exact charge, based on the model's price
in GET /v1/models.
Errors
Code
Meaning
token_input_not_supported
The input contains token arrays. Send strings instead.
embedding_shape_not_supported
The model doesn't support the requested dimensions length.
wrong_endpoint
A chat model on this endpoint, or an embedding model on chat completions.