Crear Embeddings
curl --request POST \
--url https://api.example.com/v1/embeddings \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"input": [
"<string>"
],
"encoding_format": "<string>",
"dimensions": 123
}
'import requests
url = "https://api.example.com/v1/embeddings"
payload = {
"model": "<string>",
"input": ["<string>"],
"encoding_format": "<string>",
"dimensions": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
input: ['<string>'],
encoding_format: '<string>',
dimensions: 123
})
};
fetch('https://api.example.com/v1/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'input' => [
'<string>'
],
'encoding_format' => '<string>',
'dimensions' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": [\n \"<string>\"\n ],\n \"encoding_format\": \"<string>\",\n \"dimensions\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/embeddings")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": [\n \"<string>\"\n ],\n \"encoding_format\": \"<string>\",\n \"dimensions\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"input\": [\n \"<string>\"\n ],\n \"encoding_format\": \"<string>\",\n \"dimensions\": 123\n}"
response = http.request(request)
puts response.read_bodyEmbeddings y reordenación
Crear Embeddings
Convierte texto en representaciones vectoriales
POST
/
v1
/
embeddings
Crear Embeddings
curl --request POST \
--url https://api.example.com/v1/embeddings \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"input": [
"<string>"
],
"encoding_format": "<string>",
"dimensions": 123
}
'import requests
url = "https://api.example.com/v1/embeddings"
payload = {
"model": "<string>",
"input": ["<string>"],
"encoding_format": "<string>",
"dimensions": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
input: ['<string>'],
encoding_format: '<string>',
dimensions: 123
})
};
fetch('https://api.example.com/v1/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'input' => [
'<string>'
],
'encoding_format' => '<string>',
'dimensions' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": [\n \"<string>\"\n ],\n \"encoding_format\": \"<string>\",\n \"dimensions\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/embeddings")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": [\n \"<string>\"\n ],\n \"encoding_format\": \"<string>\",\n \"dimensions\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"input\": [\n \"<string>\"\n ],\n \"encoding_format\": \"<string>\",\n \"dimensions\": 123\n}"
response = http.request(request)
puts response.read_bodyContenido actualizado: 2026-06-06
Descripción de la interfaz
Convierte el texto de entrada en un vector de alta dimensión, utilizado para búsqueda semántica, agrupamiento, recomendaciones y otros escenarios. Totalmente compatible con el formato OpenAI Embeddings API.Modelos compatibles
| Modelo | Dimensiones | Descripción |
|---|---|---|
text-embedding-3-large | 3072 | Alta precisión, recomendado para entornos de producción |
text-embedding-3-small | 1536 | Gran relación calidad/precio |
text-embedding-ada-002 | 1536 | Modelo clásico |
Parámetros de solicitud
string
requerido
Nombre del modelo de embedding, por ejemplo
text-embedding-3-largestring | string[]
requerido
Texto a embeddar, se admite una sola cadena o un arreglo de cadenas
string
predeterminado:"float"
Formato de retorno:
float o base64integer
Dimensión del vector de salida (soportado solo por
text-embedding-3-*)Formato de la respuesta
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023064255, -0.009327292, ...]
}
],
"model": "text-embedding-3-large",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
Ejemplo de código
from openai import OpenAI
client = OpenAI(
api_key="sk-xxx",
base_url="https://api.crazyrouter.com/v1"
)
response = client.embeddings.create(
model="text-embedding-3-large",
input="Crazyrouter 是一个 AI 模型网关"
)
embedding = response.data[0].embedding
print(f"向量维度: {len(embedding)}")
print(f"前5个值: {embedding[:5]}")
response = client.embeddings.create(
model="text-embedding-3-large",
input=[
"第一段文本",
"第二段文本",
"第三段文本"
]
)
for item in response.data:
print(f"索引 {item.index}: 维度 {len(item.embedding)}")
curl -X POST https://api.crazyrouter.com/v1/embeddings \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-large",
"input": "Crazyrouter 是一个 AI 模型网关"
}'
En solicitudes por lotes, se admite un máximo de 2048 textos por vez. Se recomienda no superar los 8191 tokens por texto.