Skip to content
Get API key
View as Markdown

Embeddings

Turns text into vectors for search, clustering, and retrieval, in the OpenAI Embeddings format. Embedding models are paid models from providers: each one's price per million input tokens is on its page at freetheai.org/models.

POSThttps://api.freetheai.org/v1/embeddings

Request ​

bash
curl https://api.freetheai.org/v1/embeddings \
  -H "Authorization: Bearer $FTAI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "MODEL_ID", "input": ["first text", "second text"]}'
python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.freetheai.org/v1", api_key=os.environ["FTAI_KEY"])

result = client.embeddings.create(model="MODEL_ID", input=["first text", "second text"])
print(len(result.data[0].embedding))
ts
import OpenAI from 'openai'

const client = new OpenAI({ baseURL: 'https://api.freetheai.org/v1', apiKey: process.env.FTAI_KEY })

const result = await client.embeddings.create({ model: 'MODEL_ID', input: ['first text', 'second text'] })
console.log(result.data[0].embedding.length)
FieldTypeDescription
modelstringAn embedding model ID from GET /v1/models ("type": "embeddings").
inputstring or arrayOne text, a list of texts, or token arrays.
dimensionsintegerOptional. Fewer dimensions, for models that support it (1 to 65536).
encoding_formatstringOptional. float (default) or base64.

Other fields are not sent to the model.

Response ​

json
{
  "object": "list",
  "data": [
    { "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456] },
    { "object": "embedding", "index": 1, "embedding": [0.0789, 0.0012] }
  ],
  "model": "MODEL_ID",
  "usage": { "prompt_tokens": 6, "total_tokens": 6 }
}

You are charged for usage.prompt_tokens at the model's input price. The request first holds an estimate on your wallet; the unused part is given back.

Errors ​

StatusMeaning
400A field has a value the endpoint does not take (the message names it).
401Missing or invalid API key.
402Not enough wallet balance, or the key's budget is used (paid usage errors).
404No model has that ID, or none of the providers you follow serve it.
502 / 503The provider failed or is busy. Retry; a failed request is not charged.