OpenAI API compatibility

The Together API provides compatibility for the OpenAI API standard, allowing easier integrations into existing applications.

Python SDK

To switch to using the Together API, simply switch out the API key to your Together API key, base_url to https://api.together.xyz/v1, and model to one of our chat models.

from openai import OpenAI

client = OpenAI(
  api_key=TOGETHER_API_KEY, 
  base_url="https://api.together.xyz/v1"
)

def get_embeddings(texts, model="togethercomputer/m2-bert-80M-32k-retrieval"):
   texts = [text.replace("\n", " ") for text in texts]
   outputs = client.embeddings.create(input = texts, model=model)
   return [outputs.data[i].embedding for i in range(len(texts))]

return get_embeddings(texts)