How to beginner · 3 min read

How to get Together AI API key

Quick answer
To get a Together AI API key, sign up at the Together AI website and create an account. After logging in, navigate to the API keys section in your dashboard to generate and copy your API key for use in your Python projects.

PREREQUISITES

  • Python 3.8+
  • pip install openai>=1.0
  • Together AI account

Setup

First, create a Together AI account at their official website. Once registered, log in to access your dashboard where you can generate your API key. Install the openai Python package to interact with Together AI's OpenAI-compatible API.
bash
pip install openai

Step by step

Use your Together AI API key with the OpenAI-compatible openai Python SDK by setting the TOGETHER_API_KEY environment variable. Then create a client and call the chat completion endpoint with a Together AI model.
python
import os
from openai import OpenAI

# Set your Together AI API key in environment variable TOGETHER_API_KEY
client = OpenAI(api_key=os.environ["TOGETHER_API_KEY"], base_url="https://api.together.xyz/v1")

response = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
    messages=[{"role": "user", "content": "Hello from Together AI!"}]
)

print(response.choices[0].message.content)
output
Hello from Together AI! How can I assist you today?

Common variations

You can use different Together AI models by changing the model parameter. For asynchronous calls, use an async client pattern with asyncio. Streaming responses are supported by setting stream=True in the request.
python
import os
import asyncio
from openai import OpenAI

async def main():
    client = OpenAI(api_key=os.environ["TOGETHER_API_KEY"], base_url="https://api.together.xyz/v1")
    
    stream = client.chat.completions.create(
        model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
        messages=[{"role": "user", "content": "Stream a response from Together AI."}],
        stream=True
    )

    async for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="", flush=True)

asyncio.run(main())
output
Streaming response text printed token-by-token...

Troubleshooting

  • If you get authentication errors, verify your TOGETHER_API_KEY environment variable is set correctly.
  • Check your account dashboard to ensure your API key is active and has usage quota.
  • Use the correct base URL https://api.together.xyz/v1 for the Together AI API.

Key Takeaways

  • Sign up on Together AI website to generate your API key in the dashboard.
  • Use the OpenAI-compatible openai Python SDK with base_url="https://api.together.xyz/v1" to call Together AI models.
  • Set your API key securely in the TOGETHER_API_KEY environment variable before running code.
  • Together AI supports async and streaming calls via the OpenAI SDK pattern.
  • Verify API key and base URL if you encounter authentication or connection errors.
Verified 2026-04 · meta-llama/Llama-3.3-70B-Instruct-Turbo
Verify ↗