Create an embedding
curl --request POST \
--url https://tokens.flex.ai/v1/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "bge-m3",
"input": "hello world",
"encoding_format": "float"
}
'import requests
url = "https://tokens.flex.ai/v1/embeddings"
payload = {
"model": "bge-m3",
"input": "hello world",
"encoding_format": "float"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'bge-m3', input: 'hello world', encoding_format: 'float'})
};
fetch('https://tokens.flex.ai/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://tokens.flex.ai/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' => 'bge-m3',
'input' => 'hello world',
'encoding_format' => 'float'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://tokens.flex.ai/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"bge-m3\",\n \"input\": \"hello world\",\n \"encoding_format\": \"float\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://tokens.flex.ai/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"bge-m3\",\n \"input\": \"hello world\",\n \"encoding_format\": \"float\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://tokens.flex.ai/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"bge-m3\",\n \"input\": \"hello world\",\n \"encoding_format\": \"float\"\n}"
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "embedding",
"index": 123,
"embedding": [
123
]
}
],
"model": "<string>",
"usage": {
"prompt_tokens": 123,
"total_tokens": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}Embeddings
Create an embedding
Generate a dense vector representation of one or more input strings. Use the vector to rank documents by similarity, cluster, or as a retrieval index.
POST
/
v1
/
embeddings
Create an embedding
curl --request POST \
--url https://tokens.flex.ai/v1/embeddings \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "bge-m3",
"input": "hello world",
"encoding_format": "float"
}
'import requests
url = "https://tokens.flex.ai/v1/embeddings"
payload = {
"model": "bge-m3",
"input": "hello world",
"encoding_format": "float"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'bge-m3', input: 'hello world', encoding_format: 'float'})
};
fetch('https://tokens.flex.ai/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://tokens.flex.ai/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' => 'bge-m3',
'input' => 'hello world',
'encoding_format' => 'float'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://tokens.flex.ai/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"bge-m3\",\n \"input\": \"hello world\",\n \"encoding_format\": \"float\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://tokens.flex.ai/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"bge-m3\",\n \"input\": \"hello world\",\n \"encoding_format\": \"float\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://tokens.flex.ai/v1/embeddings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"bge-m3\",\n \"input\": \"hello world\",\n \"encoding_format\": \"float\"\n}"
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "embedding",
"index": 123,
"embedding": [
123
]
}
],
"model": "<string>",
"usage": {
"prompt_tokens": 123,
"total_tokens": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"code": "<string>",
"doc_url": "<string>"
}
}Authorizations
Virtual API key. Create one from the
FlexAI dashboard. Pass as
Authorization: Bearer sk-xxxx.
Body
application/json
Embedding model id. See the model catalog.
Example:
"bge-m3"
Text (or list of texts) to embed.
Example:
"hello world"
Encoding of the returned embedding values. Optional; defaults to
"float" (matching OpenAI). Use "base64" for the compact wire
format. Pass a string or omit the field — do not send an explicit null.
Available options:
float, base64 Was this page helpful?
⌘I