Embeddings
Generate text embeddings using OpenAI and Google models through the embeddings API
Embeddings
osmAPI supports text embedding models through the OpenAI-compatible /v1/embeddings endpoint. Embedding models convert text into numerical vectors that capture semantic meaning, useful for search, similarity, clustering, and RAG applications.
Available Models
| Model | Provider | Price / 1M tokens | Dimensions | Max Input |
|---|---|---|---|---|
text-embedding-3-small | OpenAI | $0.02 | 1,536 | 8,191 |
text-embedding-3-large | OpenAI | $0.13 | 3,072 | 8,191 |
gemini-embedding-001 | Google AI Studio | $0.15 | 3,072 | 2,048 |
gemini-embedding-2-preview | Google AI Studio | $0.20 | 3,072 | 8,192 |
You can also view all available embedding models via the dedicated endpoint.
Making Requests
Single Text Input
curl -X POST "https://api.osmapi.com/v1/embeddings" \
-H "Authorization: Bearer $OSM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "The quick brown fox jumps over the lazy dog"
}'Multiple Text Inputs (Batch)
curl -X POST "https://api.osmapi.com/v1/embeddings" \
-H "Authorization: Bearer $OSM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": [
"First document to embed",
"Second document to embed",
"Third document to embed"
]
}'Specifying a Provider
Use the provider/model format to route to a specific provider:
curl -X POST "https://api.osmapi.com/v1/embeddings" \
-H "Authorization: Bearer $OSM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google-ai-studio/gemini-embedding-001",
"input": "Hello world"
}'Response Format
The response follows the OpenAI embeddings format:
{
"id": "embd-abc123",
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [0.0023, -0.0091, 0.0152, ...],
"index": 0
}
],
"model": "openai/text-embedding-3-small",
"usage": {
"prompt_tokens": 9,
"total_tokens": 9,
"cost": 0.0000166
}
}The usage.cost field shows the total cost in USD for the request.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g., text-embedding-3-small or openai/text-embedding-3-small) |
input | string, string[], number[], or number[][] | Yes | Text or token array to embed. Can be a single string, array of strings, token array, or array of token arrays. |
dimensions | integer | No | Number of output dimensions. Supported by OpenAI v3 models and Google models. |
encoding_format | string | No | Format of the embedding vectors. float (default) or base64. |
Custom Dimensions
Both OpenAI v3 models and Google models support reducing the output dimensions:
curl -X POST "https://api.osmapi.com/v1/embeddings" \
-H "Authorization: Bearer $OSM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-large",
"input": "Hello world",
"dimensions": 1024
}'Reducing dimensions trades some accuracy for smaller storage and faster
similarity comparisons. OpenAI's text-embedding-3-large at 1024 dimensions
still outperforms the full 1536-dimension ada-002 model.
List Embedding Models
You can list all available embedding models:
curl "https://api.osmapi.com/v1/embeddings/models" \
-H "Authorization: Bearer $OSM_API_KEY"Pricing
Embeddings are billed on input tokens only (no output cost). The cost is deducted from your organization's credits when using credits or hybrid mode, or charged to your provider API key in API keys mode.
SDK Compatibility
The endpoint is fully compatible with the OpenAI SDK:
from openai import OpenAI
client = OpenAI(
api_key="your-osm-api-key",
base_url="https://api.osmapi.com/v1"
)
response = client.embeddings.create(
model="text-embedding-3-small",
input="Hello world"
)
print(response.data[0].embedding[:5])import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-osm-api-key",
baseURL: "https://api.osmapi.com/v1",
});
const response = await client.embeddings.create({
model: "text-embedding-3-small",
input: "Hello world",
});
console.log(response.data[0].embedding.slice(0, 5));How is this guide?