Skip to content

Together AI

Install

To use Together AI, you need to either install pydantic-ai, or install pydantic-ai-slim with the openai optional group (as it uses an OpenAI-compatible API):

pip install 'pydantic-ai-slim[openai]'
uv add 'pydantic-ai-slim[openai]'

Configuration

Go to Together.ai and create an API key in your account settings.

You can set the TOGETHER_API_KEY environment variable and use TogetherProvider by name:

from pydantic_ai import Agent

agent = Agent('together:meta-llama/Llama-3.3-70B-Instruct-Turbo-Free')
...

Or initialise the model and provider directly:

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.together import TogetherProvider

model = OpenAIChatModel(
    'meta-llama/Llama-3.3-70B-Instruct-Turbo-Free',  # model library available at https://www.together.ai/models
    provider=TogetherProvider(api_key='your-together-api-key'),
)
agent = Agent(model)
...