Create text embeddings
Generate text embeddings with ShareAI for semantic search, retrieval and similarity, with supported input formats and model requirements.
On this page
https://api.shareai.now/api/v1/embeddingsConvert one or more texts into embedding vectors.
- Base URL
https://api.shareai.now- Authentication
- Bearer API key or approved OAuth access token
Choose an embedding model enabled on ShareAI and allowed by your credential. Chat models cannot be substituted for embedding models. Model availability and supported options depend on the configured provider.
Send a request#
cURL
curl --fail-with-body --request POST \
"https://api.shareai.now/api/v1/embeddings" \
-H "Authorization: Bearer $SHAREAI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_EMBEDDING_MODEL",
"input": [
"How do I connect a device?",
"Where can I read my usage?"
],
"encoding_format": "float"
}'
Python
import json
import os
import urllib.request
headers = {"Authorization": "Bearer " + os.environ["SHAREAI_API_KEY"]}
headers["Content-Type"] = "application/json"
payload = {'model': 'YOUR_EMBEDDING_MODEL', 'input': ['How do I connect a device?', 'Where can I read my usage?'], 'encoding_format': 'float'}
data = json.dumps(payload).encode()
request = urllib.request.Request('https://api.shareai.now/api/v1/embeddings', data=data, headers=headers, method='POST')
with urllib.request.urlopen(request, timeout=60) as response:
print(json.load(response))
TypeScript
const url = "https://api.shareai.now/api/v1/embeddings";
const headers: Record = {
Authorization: `Bearer ${process.env.SHAREAI_API_KEY}`,
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "YOUR_EMBEDDING_MODEL",
"input": [
"How do I connect a device?",
"Where can I read my usage?"
],
"encoding_format": "float"
};
const response = await fetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
console.log(await response.json());
Request fields#
| Field | Value |
|---|---|
model | An enabled embedding model ID. |
input | A nonempty string or an array of up to 128 nonempty strings. |
encoding_format | float or base64. |
dimensions | Optional integer from 1 to 65536; the selected model must support it. |
Read the vectors#
Read the data array and use each result’s index to match its embedding to the input. Keep the same model and dimensions when embedding your documents and search queries. The result also includes provider-reported usage.
Batch within limits#
Combined input text is limited to 256 KiB. Responses are synchronous and limited to 2 MiB, so large vectors or batches can exceed the response limit. Reduce the batch size or use supported smaller dimensions. Token-ID arrays are not accepted.
Authentication and availability#
An approved OAuth access token can replace the API key. Account-funded requests require surcharge and an accepted plan. Model and provider restrictions still apply. If the model is not enabled for embeddings, choose an available embedding model; changing the credential cannot enable a model.
Usage#
Embeddings consume input tokens. Check model pricing before running a large batch and use Console Usage to review activity. Handle validation, authorization and availability errors before retrying.
Last updated September 15, 2026