REST API
Reference this guide to learn how to run inference using REST API.
This tutorial covers how to use the Together Embedding endpoint to get embeddings.
For the full API reference go to API Reference.
Prerequisites
- Ensure you have
curl
installed in your machine. - Get your Together API key by signing up at api.together.ai.
Define the Endpoint URL and API Key
Launch your terminal. Define the endpoint URL and the API key for authentication.
ENDPOINT_URL="https://api.together.xyz/v1/embeddings"
TOGETHER_API_KEY="YOUR_API_KEY"
Find your API token in your account settings.
Choose your embedding model and text
The input to the API is a JSON-formatted object with the following request parameters:
- The
model
field specifies an embedding model that you’d like to use. In this example, we'll specifytogethercomputer/m2-bert-80M-8k-retrieval
. You can find a full list of models here. - The
input
field is a text or a list of texts that you want to embed. You may want to chunk this text into smaller pieces not to exceed the model specific context length if it's a large body of text. You can find the max context length of a model in the model table.
Create the curl
Request
curl
RequestTo retrieve the embeddings for your input, issue the following curl command as seen below.
curl -X POST $ENDPOINT_URL \
-H "Authorization: Bearer $TOGETHER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "Our solar system orbits the Milky Way galaxy at about 515,000 mph.",
"model": "togethercomputer/m2-bert-80M-8k-retrieval"
}'
Output
Your output should be a JSON array that contains the embeddings. The dimension of the embedding vector should match the model embedding dimension.
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.44990748,
-0.2521129,
...
-0.43091708,
0.214978
],
"index": 0
}
],
"model": "togethercomputer/m2-bert-80M-8k-retrieval",
"request_id": "840fc1b5bb2830cb-SEA"
}
The response’s data[0].embedding
key contains the embeddings for your input. For the full API reference, go to API Reference.
Updated 5 months ago