Skip to main content
This documentation provides a concise guide for developers to integrate and use Together AI inference capabilities via the Hugging Face ecosystem.

Authentication and Billing

When using Together AI through Hugging Face, you have two options for authentication:
  • Direct Requests: Use your Together AI API key in your Hugging Face user account settings. In this mode, inference requests are sent directly to Together AI, and billing is handled by your Together AI account.
  • Routed Requests: If you don’t configure a Together AI API key, your requests will be routed through Hugging Face. In this case, you can use a Hugging Face token for authentication. Billing for routed requests is applied to your Hugging Face account at standard provider API rates. You don’t need an account on Together AI to do this, just use your HF one!
To add a Together AI API key to your Hugging Face settings, follow these steps:
  1. Go to your Hugging Face user account settings.
  2. Locate the “Inference Providers” section.
  3. You can add your API keys for different providers, including Together AI
  4. You can also set your preferred provider order, which will influence the display order in model widgets and code snippets.
You can search for all Together AI models on the hub and directly try out the available models via the Model Page widget too.

Usage Examples

The examples below demonstrate how to interact with various models using Python and JavaScript. First, ensure you have the huggingface_hub library installed (version v0.29.0 or later):

1. Text Generation - LLMs

a. Chat Completion with Hugging Face Hub library

You can swap this for any compatible LLM from Together AI, here’s a handy URL to find the list.

b. OpenAI client library

You can also call inference providers via the OpenAI python client. You will need to specify the base_url and model parameters in the client and call respectively. The easiest way is to go to a model’s page on the hub and copy the snippet.
Python

2. Text-to-Image Generation

Similar to LLMs, you can use any compatible text-to-image model from the list here. You can search for all Together AI models on the hub and directly try out the available models via the Model Page widget too. We’ll continue to increase the number of models and ways to try it out!