Getting started overview
This guide outlines the process for new Together AI users to set up their environment and execute an initial API request. Together AI provides an API for running open-source large language models (LLMs) and for fine-tuning custom models (Together AI documentation). The process involves creating an account, generating an API key, and using the key to authenticate requests. Together AI supports direct HTTP requests and offers official SDKs for Python and JavaScript (Together AI SDKs documentation).
Before making an API call, developers typically need to establish an account and secure an API key. This key acts as a credential for authenticating requests and is essential for accessing Together AI's services, including its inference and fine-tuning capabilities (Together AI API reference).
Quick Reference Guide
| Step | What to Do | Where |
|---|---|---|
| 1. Create Account | Register on the Together AI platform. | Together AI login page |
| 2. Generate API Key | Access the API key management section in your dashboard. | Together AI dashboard > API Keys |
| 3. Install SDK (Optional) | Install the Python or JavaScript SDK. | pip install together or npm install together-ai |
| 4. Make Request | Use your API key to send an inference request. | cURL or Python script |
| 5. Review Responses | Examine the API's JSON response for model output. | Terminal or application logs |
Create an account and get keys
Access to Together AI's API requires an account and an associated API key. This key serves as a unique identifier and authentication credential for all API interactions. Together AI offers a free credit allocation for new users, which can be utilized for initial testing and development (Together AI pricing details).
Account Creation Process
- Navigate to the Together AI login page.
- Select the option to sign up for a new account. Typically, this involves providing an email address and creating a password, or using a third-party authentication provider such as Google or GitHub.
- Follow any on-screen prompts to verify your email address or complete your profile.
Generating an API Key
Once your account is active, you can generate an API key from your Together AI dashboard:
- Log in to your Together AI account.
- Locate the 'API Keys' section within your user dashboard. The exact navigation may vary but is typically found under 'Settings' or a dedicated 'API' menu item (Together AI API Keys documentation).
- Click on the option to 'Create New Key' or a similar button.
- A new API key will be generated. Copy this key immediately and store it securely. Together AI keys, like other API credentials, grant access to your account and associated resources and should be treated confidentially (OAuth.net on Bearer Tokens). Do not embed API keys directly in client-side code or public repositories.
Your first request
After obtaining an API key, you can make your first API call to Together AI. This section demonstrates how to perform a basic text generation request using cURL and Python. These examples utilize the Together AI Inference API, which allows for interaction with various open-source large language models (Together AI Inference API reference).
cURL Example
The following cURL command sends a request to the Together AI Inference API to generate a response from a specified model. Replace YOUR_API_KEY with your actual Together AI API key.
curl https://api.together.xyz/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{ "model": "mistralai/Mixtral-8x7B-Instruct-v0.1", "messages": [{ "role": "user", "content": "What is the capital of France?" }] }'
This command specifies the mistralai/Mixtral-8x7B-Instruct-v0.1 model and provides a user message. The Authorization header carries the API key as a Bearer token, a common method for authenticating API requests (IETF RFC 6750 for Bearer Token Usage).
Python Example
To use the Python SDK, first ensure it's installed:
pip install together
Then, you can make an API call as follows. Replace YOUR_API_KEY with your API key.
import together
together.api_key = "YOUR_API_KEY"
response = together.Complete.create(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
prompt="What is the capital of France?",
max_tokens=100,
temperature=0.7
)
print(response)
This Python script initializes the Together AI client with your API key and then calls the Complete.create method. It requests a completion from the specified model, similar to the cURL example. Note that the Python SDK typically handles the correct formatting of requests and headers internally (Together AI Python SDK documentation).
Common next steps
After successfully making your first API call, you can explore more advanced features and integrations offered by Together AI:
- Explore different models: Together AI supports a variety of open-source models for different use cases. Review the available models and their capabilities within the Together AI model catalog to find one that best suits your needs.
- Integrate into an application: Incorporate the API calls into your existing applications, whether they are web services, mobile apps, or backend processes. Consider using the official SDKs for Python or JavaScript to streamline integration (Together AI SDKs documentation).
- Fine-tuning custom models: If pre-trained models don't meet specific requirements, Together AI offers a fine-tuning API. This allows you to adapt models using your own datasets, potentially improving performance on specialized tasks.
- Monitor usage and costs: Regularly check your Together AI dashboard to monitor API usage, credit consumption, and estimated costs. This helps manage your budget and optimize API calls (Together AI pricing page).
- Review rate limits: Understand the API rate limits to design your application to handle them gracefully, preventing errors due to too many requests. Implementing retry logic with exponential backoff is a common strategy for handling rate limits (Google Cloud API rate limit best practices).
- Secure API keys: Reinforce the security of your API keys. Avoid hardcoding them directly into source code. Use environment variables or a secure secret management system to store and retrieve them.
Troubleshooting the first call
Encountering issues during your first API call is common. Here are some troubleshooting steps:
- Check API Key: Ensure your API key is correct and has not expired or been revoked. Double-check for typos or extra spaces. API keys are case-sensitive (Together AI API Keys security).
- Verify Authorization Header: For cURL requests, confirm the
Authorization: Bearer YOUR_API_KEYheader is correctly formatted. The word "Bearer" is required before your key. - Content-Type Header: Ensure the
Content-Type: application/jsonheader is present for JSON payloads. - Model Name Accuracy: Verify that the model name used in your request (e.g.,
mistralai/Mixtral-8x7B-Instruct-v0.1) exactly matches an available model in the Together AI model list. Minor discrepancies can lead to errors. - JSON Payload Syntax: If using cURL or direct HTTP requests, validate that your JSON payload is syntactically correct. Tools like online JSON validators can help identify missing commas, brackets, or incorrect data types.
- Network Connectivity: Confirm that your local environment has active internet connectivity and is not blocked by a firewall from reaching
api.together.xyz. - Rate Limits: Although unlikely for a first call, if you are making multiple rapid requests, you might encounter rate limiting errors. Check the error message for indications of rate limiting (Together AI rate limits documentation).
- Consult Together AI Documentation: The official Together AI documentation provides detailed error code explanations and further troubleshooting guides.
- Review Server Status: Check the Together AI status page for any ongoing service disruptions or outages that might affect API availability.