Creating embeddings

Last change on 2026-11-11 • Created on 2026-11-11 • ID: AI-F03F3

An embedding is a vector of numbers that represents the meaning of a text. Texts with a similar meaning have similar vectors. You can use embeddings for semantic search, to compare texts, or for retrieval-augmented generation (RAG), for example. This guide shows you how to create embeddings with Hetzner Inference API.

Prerequisites

  • An Inference Token in the HETZNER_INFERENCE_TOKEN environment variable. To learn how to create an Inference Token, see Quickstart.
  • For the Python or JavaScript examples, the OpenAI SDK (pip install openai or npm install openai).

The base URL and authentication are the same as for all other requests. For details, see Generating text with Hetzner Inference API.

Creating embeddings

Use POST /v1/embeddings with the BAAI/bge-m3 model to turn a text into a vector.

cURL

curl https://inference.hetzner.com/v1/embeddings \
  -H "Authorization: Bearer $HETZNER_INFERENCE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "BAAI/bge-m3",
    "input": "Hello world"
  }'

Python

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.hetzner.com/v1",
    api_key=os.environ["HETZNER_INFERENCE_TOKEN"],
)

response = client.embeddings.create(
    model="BAAI/bge-m3",
    input="Hello world",
)

print(response.data[0].embedding)

JavaScript

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://inference.hetzner.com/v1",
  apiKey: process.env.HETZNER_INFERENCE_TOKEN,
});

const response = await client.embeddings.create({
  model: "BAAI/bge-m3",
  input: "Hello world",
});

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

The vector is in the data[0].embedding field.

Several texts in one request

To create embeddings for several texts, pass a list of texts in input:

response = client.embeddings.create(
    model="BAAI/bge-m3",
    input=["First text", "Second text"],
)

for item in response.data:
    print(item.index, item.embedding[:5])

The response contains one entry in data for each text. The index field shows which text from the list a vector belongs to.

A request with several texts counts as a single request toward the rate limit. If you process many texts, you need far fewer requests this way.

There is no fixed limit on the number of texts per request. However, the entire request can be up to 32 MiB in size. The API rejects larger requests with status code 413. How many texts fit into one request depends on the length of the texts.

Please note: Send a total of about 1 million tokens per request at most. This equals about 100 texts with the maximum length of 8,192 tokens. With larger requests, the API does not process the texts any faster. Each request takes longer, though, and if a request fails, you have to send more texts again.

Notes

  • Length of the texts: Each text can be at most as long as the context window of the model. For BGE M3, this is 8,192 tokens. Split longer texts into smaller sections first.
  • Text only: The API creates embeddings from text only.
  • Matching endpoint: Embedding models only work with /v1/embeddings. Chat models do not work there.

For other differences from the OpenAI API, see Compatibility with OpenAI and Anthropic.

Next steps

Table of Contents