Embeddings
Call Vertex AI and AWS Bedrock embedding models through EasyRouter's unified API
Convert text into vector embeddings. Compatible with the OpenAI Embeddings API — existing OpenAI SDKs work without any code changes.
Supported Models
| Model | Provider | Dimensions | Batch Limit | dimensions param |
|---|---|---|---|---|
gemini-embedding-001 | Google Vertex AI | 3072 | 1 (single) | No |
text-embedding-004 | Google Vertex AI | 768 | 5 | Yes |
amazon.titan-embed-text-v2:0 | AWS Bedrock | 1024 (default) | 1 (single) | Yes (256 / 512 / 1024) |
Model Details
Provider: Google Vertex AI Dimensions: 3072 Batch Limit: 1
input must be a string — arrays are not supported. The dimensions
parameter is not supported. Maximum 2048 tokens per request.
Best for RAG retrieval and knowledge base construction requiring high-precision semantic vectors.
curl https://easyrouter.io/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-embedding-001",
"input": "EasyRouter is an enterprise-grade AI API gateway"
}'from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://easyrouter.io/v1"
)
resp = client.embeddings.create(
model="gemini-embedding-001",
input="EasyRouter is an enterprise-grade AI API gateway"
)
print(f"Dimensions: {len(resp.data[0].embedding)}") # 3072package main
import (
"context"
"fmt"
"github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("YOUR_API_KEY")
config.BaseURL = "https://easyrouter.io/v1"
client := openai.NewClientWithConfig(config)
resp, err := client.CreateEmbeddings(context.Background(),
openai.EmbeddingRequest{
Model: "gemini-embedding-001",
Input: []string{"EasyRouter is an enterprise-grade AI API gateway"},
},
)
if err != nil {
panic(err)
}
fmt.Printf("Dimensions: %d\n", len(resp.Data[0].Embedding)) // 3072
}import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://easyrouter.io/v1",
});
const resp = await client.embeddings.create({
model: "gemini-embedding-001",
input: "EasyRouter is an enterprise-grade AI API gateway",
});
console.log(`Dimensions: ${resp.data[0].embedding.length}`); // 3072<?php
$response = file_get_contents('https://easyrouter.io/v1/embeddings', false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
]),
'content' => json_encode([
'model' => 'gemini-embedding-001',
'input' => 'EasyRouter is an enterprise-grade AI API gateway',
]),
],
])
);
$data = json_decode($response, true);
echo 'Dimensions: ' . count($data['data'][0]['embedding']) . PHP_EOL; // 3072Provider: Google Vertex AI Dimensions: 768 Batch Limit: 5
Supports batch input (array, up to 5 items). Supports dimensions
compression — recommended values: 256 / 512 / 768. Maximum 2048 tokens
per request.
Cost-effective for large-scale vector storage and text similarity tasks.
Single input:
curl https://easyrouter.io/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-004",
"input": "AI is transforming the world"
}'Batch (up to 5 items):
curl https://easyrouter.io/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-004",
"input": ["text one", "text two", "text three"]
}'Compress to 256 dimensions:
curl https://easyrouter.io/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-004",
"input": "compressed storage example",
"dimensions": 256
}'from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://easyrouter.io/v1"
)
# Single input
resp = client.embeddings.create(
model="text-embedding-004",
input="AI is transforming the world"
)
print(f"Dimensions: {len(resp.data[0].embedding)}") # 768
# Batch (up to 5 items)
resp = client.embeddings.create(
model="text-embedding-004",
input=["text one", "text two", "text three"]
)
for item in resp.data:
print(f"[{item.index}] Dimensions: {len(item.embedding)}") # 768
# Compress to 256 dimensions
resp = client.embeddings.create(
model="text-embedding-004",
input="compressed storage example",
dimensions=256
)
print(f"Dimensions: {len(resp.data[0].embedding)}") # 256package main
import (
"context"
"fmt"
"github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("YOUR_API_KEY")
config.BaseURL = "https://easyrouter.io/v1"
client := openai.NewClientWithConfig(config)
// Batch
resp, err := client.CreateEmbeddings(context.Background(),
openai.EmbeddingRequest{
Model: "text-embedding-004",
Input: []string{"text one", "text two", "text three"},
},
)
if err != nil {
panic(err)
}
for _, item := range resp.Data {
fmt.Printf("[%d] Dimensions: %d\n", item.Index, len(item.Embedding)) // 768
}
// Compress to 256 dimensions
resp, err = client.CreateEmbeddings(context.Background(),
openai.EmbeddingRequest{
Model: "text-embedding-004",
Input: []string{"compressed storage example"},
Dimensions: 256,
},
)
if err != nil {
panic(err)
}
fmt.Printf("Dimensions: %d\n", len(resp.Data[0].Embedding)) // 256
}import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://easyrouter.io/v1",
});
// Batch (up to 5 items)
const batchResp = await client.embeddings.create({
model: "text-embedding-004",
input: ["text one", "text two", "text three"],
});
batchResp.data.forEach((item) => {
console.log(`[${item.index}] Dimensions: ${item.embedding.length}`); // 768
});
// Compress to 256 dimensions
const compressedResp = await client.embeddings.create({
model: "text-embedding-004",
input: "compressed storage example",
dimensions: 256,
});
console.log(`Dimensions: ${compressedResp.data[0].embedding.length}`); // 256<?php
// Batch (up to 5 items)
$response = file_get_contents('https://easyrouter.io/v1/embeddings', false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
]),
'content' => json_encode([
'model' => 'text-embedding-004',
'input' => ['text one', 'text two', 'text three'],
]),
],
])
);
$data = json_decode($response, true);
foreach ($data['data'] as $item) {
echo "[{$item['index']}] Dimensions: " . count($item['embedding']) . PHP_EOL; // 768
}
// Compress to 256 dimensions
$response = file_get_contents('https://easyrouter.io/v1/embeddings', false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
]),
'content' => json_encode([
'model' => 'text-embedding-004',
'input' => 'compressed storage example',
'dimensions' => 256,
]),
],
])
);
$data = json_decode($response, true);
echo 'Dimensions: ' . count($data['data'][0]['embedding']) . PHP_EOL; // 256Provider: AWS Bedrock Dimensions: 1024 (default) Batch Limit: 1
input must be a string — arrays are not supported. dimensions
only accepts 256, 512, or 1024. encoding_format: base64 is not
supported. Output vectors are L2-normalized; billing uses exact token
counts.
Default dimensions (1024):
curl https://easyrouter.io/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "amazon.titan-embed-text-v2:0",
"input": "Hello, Bedrock!"
}'Specify 256 dimensions:
curl https://easyrouter.io/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "amazon.titan-embed-text-v2:0",
"input": "compressed vector example",
"dimensions": 256
}'from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://easyrouter.io/v1"
)
# Default dimensions (1024)
resp = client.embeddings.create(
model="amazon.titan-embed-text-v2:0",
input="Hello, Bedrock!"
)
print(f"Dimensions: {len(resp.data[0].embedding)}") # 1024
# Specify 256 dimensions
resp = client.embeddings.create(
model="amazon.titan-embed-text-v2:0",
input="compressed vector example",
dimensions=256
)
print(f"Dimensions: {len(resp.data[0].embedding)}") # 256package main
import (
"context"
"fmt"
"github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig("YOUR_API_KEY")
config.BaseURL = "https://easyrouter.io/v1"
client := openai.NewClientWithConfig(config)
// Default dimensions (1024)
resp, err := client.CreateEmbeddings(context.Background(),
openai.EmbeddingRequest{
Model: "amazon.titan-embed-text-v2:0",
Input: []string{"Hello, Bedrock!"},
},
)
if err != nil {
panic(err)
}
fmt.Printf("Dimensions: %d\n", len(resp.Data[0].Embedding)) // 1024
// Specify 256 dimensions
resp, err = client.CreateEmbeddings(context.Background(),
openai.EmbeddingRequest{
Model: "amazon.titan-embed-text-v2:0",
Input: []string{"compressed vector example"},
Dimensions: 256,
},
)
if err != nil {
panic(err)
}
fmt.Printf("Dimensions: %d\n", len(resp.Data[0].Embedding)) // 256
}import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://easyrouter.io/v1",
});
// Default dimensions (1024)
const resp = await client.embeddings.create({
model: "amazon.titan-embed-text-v2:0",
input: "Hello, Bedrock!",
});
console.log(`Dimensions: ${resp.data[0].embedding.length}`); // 1024
// Specify 256 dimensions
const compressedResp = await client.embeddings.create({
model: "amazon.titan-embed-text-v2:0",
input: "compressed vector example",
dimensions: 256,
});
console.log(`Dimensions: ${compressedResp.data[0].embedding.length}`); // 256<?php
// Default dimensions (1024)
$response = file_get_contents('https://easyrouter.io/v1/embeddings', false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
]),
'content' => json_encode([
'model' => 'amazon.titan-embed-text-v2:0',
'input' => 'Hello, Bedrock!',
]),
],
])
);
$data = json_decode($response, true);
echo 'Dimensions: ' . count($data['data'][0]['embedding']) . PHP_EOL; // 1024
// Specify 256 dimensions
$response = file_get_contents('https://easyrouter.io/v1/embeddings', false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
]),
'content' => json_encode([
'model' => 'amazon.titan-embed-text-v2:0',
'input' => 'compressed vector example',
'dimensions' => 256,
]),
],
])
);
$data = json_decode($response, true);
echo 'Dimensions: ' . count($data['data'][0]['embedding']) . PHP_EOL; // 256Error Codes
| HTTP Status | Error Message | Cause |
|---|---|---|
| 400 | input is empty | input field is missing |
| 400 | amazon titan embedding only supports a single input per request | Array passed to Titan |
| 400 | gemini-embedding-001 only supports single input per request | Array passed to gemini-embedding-001 |
| 400 | text-embedding-004 supports up to 5 inputs per request | Batch exceeds 5 items |
| 400 | unsupported bedrock embedding model: xxx | Unsupported Bedrock embedding model |
| 401 | Invalid token | API Key is invalid or expired |
| 429 | Rate limit exceeded | Request rate limit exceeded |
| 500 | upstream error | Upstream service error, retry later |
Model Selection Guide
| Use Case | Recommended Model | Reason |
|---|---|---|
| RAG / high-precision retrieval | gemini-embedding-001 | 3072 dimensions, highest semantic accuracy |
| Large-scale vector storage (cost-saving) | text-embedding-004 + dimensions=256 | Batch support + dimension compression |
| Text similarity / classification | text-embedding-004 | 768 dimensions, cost-effective, supports batching |
| AWS infrastructure users | amazon.titan-embed-text-v2:0 | Native Bedrock, exact token billing, dim compression |
| Multilingual scenarios | All three | Native support for Chinese, English, and more |
API Reference
Authorization
BearerAuth
使用 Bearer Token 认证。
格式: Authorization: Bearer sk-xxxxxx
In: header
Request Body
application/json
要嵌入的文本
"float""float" | "base64"输出向量维度
Response Body
application/json
curl -X POST "https://easyrouter.io/v1/embeddings" \ -H "Content-Type: application/json" \ -d '{ "model": "text-embedding-ada-002", "input": "string" }'{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
0
]
}
],
"model": "string",
"usage": {
"prompt_tokens": 0,
"total_tokens": 0
}
}