First, register for an account to get an API key. New accounts come with $5 to get started.Once you’ve registered, set your account’s API key to an environment variable named TOGETHER_API_KEY:
Choose a model to query. In this example, we’ll use Meta Llama 3.With your selected model, use your preferred library to query one of Together’s APIs – for example, to run a chat completion with streaming:
Python
Copy
Ask AI
import osfrom together import Togetherclient = Together(api_key=os.environ.get("TOGETHER_API_KEY"))stream = client.chat.completions.create(model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",messages=[{"role": "user", "content": "What are some fun things to do in New York?"}],stream=True,)for chunk in stream:print(chunk.choices[0].delta.content or "", end="", flush=True)
Congratulations – you’ve just made your first query to Together AI!