Skip to content

Embeddings

POST /v1/embeddings

| Field | Type | Required | Description | |---|---|---|---| | model | string | yes | Embedding model to use. There is no default — you must specify a model. See supported models below. | | input | string | string[] | yes | Text to embed. Pass a single string or an array of strings for batch embedding. | | encoding_format | string | no | Output format. Currently "float" is supported. | | dimensions | number | no | Number of dimensions for the output vector. Supported by select models. |

| Provider | Example Models | Notes | |---|---|---| | Cloudflare Workers AI | @cf/baai/bge-small-en-v1.5, @cf/baai/bge-base-en-v1.5, @cf/baai/bge-large-en-v1.5 | General-purpose English embeddings | | Google Gemini | gemini-embedding-001 (text-embedding-004, text-embedding-3-small, and text-embedding-3-large aliases) | Multilingual, supports requested dimensions | | Voyage AI | voyage-3.5-lite, voyage-3-lite | Domain-specialised embeddings |

Use GET /v1/models to get the full current list with provider metadata, dimensions, aliases, and enabled availability based on configured provider credentials/bindings.

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",
"project_id": "my_project",
"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",
"project_id": "my_project",
"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",
"project_id": "my_project",
"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`);
});