Embeddings
POST/v1/embeddings
Embed text through your own OpenAI or Google key, in the OpenAI embeddings shape.
Embeddings in the OpenAI shape, through your own OpenAI or Google key (or an OpenAI-compatible endpoint you configured), never the platform's. Memory itself needs no key of yours: this endpoint is for your own use of embeddings.
Example
Against https://platform.memtro.com, with your key in MEMTRO_API_KEY.
curl https://platform.memtro.com/v1/embeddings \
-H "Authorization: Bearer $MEMTRO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "openai/text-embedding-3-small", "input": ["billing migration", "Q3 launch"]}'
from openai import OpenAI
client = OpenAI(base_url="https://platform.memtro.com/v1", api_key="sk-memtro-…")
result = client.embeddings.create(model="openai/text-embedding-3-small", input=["billing migration", "Q3 launch"])
print(len(result.data[0].embedding))
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://platform.memtro.com/v1", apiKey: process.env.MEMTRO_API_KEY });
const result = await client.embeddings.create({ model: "openai/text-embedding-3-small", input: ["billing migration", "Q3 launch"] });
console.log(result.data[0].embedding.length);
Vectors shortened here.
{
"object": "list",
"data": [
{ "object": "embedding", "index": 0, "embedding": [0.0123, -0.0481, …] },
{ "object": "embedding", "index": 1, "embedding": [-0.0067, 0.0215, …] }
],
"model": "openai/text-embedding-3-small",
"usage": { "prompt_tokens": 6, "total_tokens": 6 }
}
Authentication
An API key, as Authorization: Bearer or x-api-key.
- Every reply, errors included, carries
x-request-idandrequest-idheaders with the same id, startingreq-. Quote it to support. - It sends no CORS headers, so a page on another origin cannot call it; call it from a server.
Request body
JSON, with Content-Type: application/json.
modelstringOptionalAn embedding model id.
memtroandbrainmean the default.inputstring or array of stringsRequiredThe text to embed, or several.
encoding_formatstringOptionalAccepted, but the reply is always arrays of floats.
Response
200application/json
One vector per input, in order.
object"list"OptionalAlways
list.dataarray of objectsOptional{"object": "embedding", "index", "embedding": [numbers]}per input. OpenAI and Google models are asked for vectors of the server's configured dimension.modelstringOptional<provider>/<model>that made them.usageobjectOptionalprompt_tokens,total_tokens.
Errors
In the OpenAI envelope, {"error": {"message", "type", "param", "code"}}. What each code means and what to do about it is in the error catalogue.
| Status | Code | When |
|---|---|---|
| 400 | none | The body is not |
| 400 | provider_not_configured | No embedding-capable key: add an OpenAI or Google key. |
| 400 | invalid_provider_base_url | An OpenAI-compatible endpoint's base URL cannot be used: not a URL, not |
| 400 | provider_base_url_not_allowed | An OpenAI-compatible endpoint's host is not approved for the organisation, is private or internal, does not resolve, or redirected, whether refused before the request or during it. |
| 401 | invalid_api_key | The key is missing, malformed, revoked or expired. |
| 402 | subscription_inactive | The organisation has no active subscription. |
| provider's | upstream_error | The provider returned an error. |
Notes
No CORS headers: call it from a server, not from a page on another origin.