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, and model to one of our chat models.

import os
from openai import OpenAI

client = OpenAI(

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 [[i].embedding for i in range(len(texts))]

embeddings = get_embeddings(texts)