Skip to content

Embeddings

POST /v1/embeddings
FieldTypeRequiredDescription
modelstringyesEmbedding model to use. There is no default — you must specify a model. See supported models below.
inputstring | string[]yesText to embed. Pass a single string or an array of strings for batch embedding.
encoding_formatstringnoOutput format. Currently "float" is supported.
dimensionsnumbernoNumber of dimensions for the output vector. Supported by select models.
ProviderExample ModelsNotes
Cloudflare Workers AI@cf/baai/bge-base-en-v1.5, @cf/baai/bge-large-en-v1.5General-purpose English embeddings
Google Geminitext-embedding-004, embedding-001Multilingual, supports dimensions
Voyage AIvoyage-3, voyage-3-lite, voyage-code-3, voyage-finance-2Domain-specialised, high accuracy

Use GET /v1/models to get the full current list with provider metadata.

The response follows the standard OpenAI embeddings format:

{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0089, 0.0412, ...]
}
],
"model": "voyage-3",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}

For batch inputs, data contains one entry per input string, in the same order.

Terminal window
curl https://your-gateway.workers.dev/v1/embeddings \
-H "Authorization: Bearer <GATEWAY_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "voyage-3",
"input": "The quick brown fox jumps over the lazy dog"
}'
Terminal window
curl https://your-gateway.workers.dev/v1/embeddings \
-H "Authorization: Bearer <GATEWAY_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "@cf/baai/bge-base-en-v1.5",
"input": [
"How do I reset my password?",
"Where can I find my invoice?",
"How do I cancel my subscription?"
]
}'
Terminal window
curl https://your-gateway.workers.dev/v1/embeddings \
-H "Authorization: Bearer <GATEWAY_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-004",
"input": "Semantic search query",
"dimensions": 256
}'

The gateway is fully compatible with the OpenAI Node.js SDK:

import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://your-gateway.workers.dev/v1',
apiKey: '<GATEWAY_API_KEY>',
});
const result = await client.embeddings.create({
model: 'voyage-3-lite',
input: ['cat', 'dog', 'fish'],
});
result.data.forEach((item, i) => {
console.log(`Text ${i}: ${item.embedding.length} dims`);
});