Quickstart

👋 Welcome to the Together AI docs! Together AI makes it easy to run or fine-tune leading open source models with only a few lines of code.

  • Inference - Use the API or Playgrounds to evaluate serverless models
  • Fine-Tuning - Fine-tune with a few commands and deploy your fine-tuned model for inference.
  • GPU Clusters - If you're interested in private, state of the art clusters with A100 or H100 GPUs, contact us.

Get started with Inference

  1. Register for an account to access your API key (we give you $25 to get started).
  2. Run your first model:
from openai import OpenAI
import os

TOGETHER_API_KEY = os.environ.get("TOGETHER_API_KEY")

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

chat_completion = client.chat.completions.create(
  messages=[
    {
      "role": "system",
      "content": "You are an AI assistant",
    },
    {
      "role": "user",
      "content": "Tell me about San Francisco",
    }
  ],
  model="mistralai/Mixtral-8x7B-Instruct-v0.1",
  max_tokens=1024
)

print(chat_completion.choices[0].message.content)
const url = 'https://api.together.xyz/v1/chat/completions';
const apiKey = 'TOGETHER_API_KEY';

const headers = new Headers({
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${apiKey}`
});

const data = {
    model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
    max_tokens: 1024,
    messages: [
    {
        role: 'system',
        content: 'You are an AI assistant'
    },
    {
        role: 'user',
        content: 'Who won the world series in 2020?'
    }
    ]
};

const options = {
    method: 'POST',
    headers,
    body: JSON.stringify(data)
};

fetch(url, options)
    .then(response => response.json())
    .then(result => {
    console.log(result);
    })
    .catch(error => {
    console.error('Error:', error);
    });

You can choose from any of our many supported models to generate chat, images, language, or code. We can't wait to see what you build!

Next steps

Resources