Together AI SDK (Python)
from together import Together
import os
client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)
response = client.embeddings.create(
model="BAAI/bge-large-en-v1.5",
input="New York City",
)
print(response.data[0].embedding)import Together from "together-ai";
const client = new Together({
apiKey: process.env.TOGETHER_API_KEY,
});
const response = await client.embeddings.create({
model: "BAAI/bge-large-en-v1.5",
input: "New York City",
});
console.log(response.data[0].embedding);
import Together from "together-ai";
const client = new Together({
apiKey: process.env.TOGETHER_API_KEY,
});
const response = await client.embeddings.create({
model: "BAAI/bge-large-en-v1.5",
input: "New York City",
});
console.log(response.data[0].embedding);
curl -X POST "https://api.together.ai/v1/embeddings" \
-H "Authorization: Bearer $TOGETHER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "BAAI/bge-large-en-v1.5",
"input": "New York City"
}'
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.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' => 'togethercomputer/m2-bert-80M-8k-retrieval',
'input' => 'Our solar system orbits the Milky Way galaxy at about 515,000 mph'
]),
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://api.together.ai/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"togethercomputer/m2-bert-80M-8k-retrieval\",\n \"input\": \"Our solar system orbits the Milky Way galaxy at about 515,000 mph\"\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://api.together.ai/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"togethercomputer/m2-bert-80M-8k-retrieval\",\n \"input\": \"Our solar system orbits the Milky Way galaxy at about 515,000 mph\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.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\": \"togethercomputer/m2-bert-80M-8k-retrieval\",\n \"input\": \"Our solar system orbits the Milky Way galaxy at about 515,000 mph\"\n}"
response = http.request(request)
puts response.read_body{
"object": "<unknown>",
"model": "<string>",
"data": [
{
"object": "<unknown>",
"embedding": [
123
],
"index": 123
}
]
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Embeddings
Create embedding
Generate vector embeddings for one or more text inputs. Returns numerical arrays representing semantic meaning, useful for search, classification, and retrieval.
POST
/
embeddings
Together AI SDK (Python)
from together import Together
import os
client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)
response = client.embeddings.create(
model="BAAI/bge-large-en-v1.5",
input="New York City",
)
print(response.data[0].embedding)import Together from "together-ai";
const client = new Together({
apiKey: process.env.TOGETHER_API_KEY,
});
const response = await client.embeddings.create({
model: "BAAI/bge-large-en-v1.5",
input: "New York City",
});
console.log(response.data[0].embedding);
import Together from "together-ai";
const client = new Together({
apiKey: process.env.TOGETHER_API_KEY,
});
const response = await client.embeddings.create({
model: "BAAI/bge-large-en-v1.5",
input: "New York City",
});
console.log(response.data[0].embedding);
curl -X POST "https://api.together.ai/v1/embeddings" \
-H "Authorization: Bearer $TOGETHER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "BAAI/bge-large-en-v1.5",
"input": "New York City"
}'
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.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' => 'togethercomputer/m2-bert-80M-8k-retrieval',
'input' => 'Our solar system orbits the Milky Way galaxy at about 515,000 mph'
]),
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://api.together.ai/v1/embeddings"
payload := strings.NewReader("{\n \"model\": \"togethercomputer/m2-bert-80M-8k-retrieval\",\n \"input\": \"Our solar system orbits the Milky Way galaxy at about 515,000 mph\"\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://api.together.ai/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"togethercomputer/m2-bert-80M-8k-retrieval\",\n \"input\": \"Our solar system orbits the Milky Way galaxy at about 515,000 mph\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.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\": \"togethercomputer/m2-bert-80M-8k-retrieval\",\n \"input\": \"Our solar system orbits the Milky Way galaxy at about 515,000 mph\"\n}"
response = http.request(request)
puts response.read_body{
"object": "<unknown>",
"model": "<string>",
"data": [
{
"object": "<unknown>",
"embedding": [
123
],
"index": 123
}
]
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
The name of the embedding model to use.
See all of Together AI's embedding models
Available options:
WhereIsAI/UAE-Large-V1, BAAI/bge-large-en-v1.5, BAAI/bge-base-en-v1.5, togethercomputer/m2-bert-80M-8k-retrieval Example:
"togethercomputer/m2-bert-80M-8k-retrieval"
A string providing the text for the model to embed.
Example:
"Our solar system orbits the Milky Way galaxy at about 515,000 mph"
Was this page helpful?
⌘I