SDKs overview
Together AI offers Software Development Kits (SDKs) to facilitate interaction with its platform, which is designed for running and fine-tuning open-source large language models (LLMs). These SDKs abstract the underlying Together AI API reference, allowing developers to integrate LLM capabilities into their applications using familiar programming language constructs rather than direct HTTP requests. The primary benefits of using an SDK include simplified API call construction, integrated authentication mechanisms, and native data type handling, which can reduce development time and potential errors.
The Together AI platform supports a range of tasks, including generative text, chat completions, embeddings, and fine-tuning custom models. The SDKs are designed to provide access to these functionalities, enabling developers to prompt models, manage conversational contexts, generate embeddings for semantic search or retrieval-augmented generation (RAG) systems, and programmatically manage the fine-tuning process for specialized applications. The platform emphasizes performance and cost efficiency for deploying and scaling LLMs.
The SDKs aim to provide a consistent interface across different programming environments, reducing the learning curve for developers already familiar with the respective languages. By offering official libraries, Together AI seeks to enhance the developer experience, making it easier to build applications that leverage their accelerated compute infrastructure for AI workloads.
Official SDKs by language
Together AI provides officially supported SDKs for key programming languages, ensuring direct access to their inference and fine-tuning APIs. These libraries are maintained by Together AI and are the recommended method for integrating with their services. They offer type hints, error handling, and structured access to API endpoints, aligning with the conventions of each language.
| Language | Package Name | Install Command | Maturity | Documentation |
|---|---|---|---|---|
| Python | together-ai |
pip install together-ai |
Stable | Together AI Python SDK documentation |
| JavaScript | together-ai |
npm install together-ai or yarn add together-ai |
Stable | Together AI JavaScript SDK documentation |
Installation
Installing the Together AI SDKs involves using the standard package managers for Python and JavaScript environments. Before installation, it is recommended to ensure your development environment is set up with the appropriate language runtime and package manager.
Python SDK
The Python SDK can be installed using pip, the Python package installer. It is advisable to install the SDK within a virtual environment to manage dependencies effectively and avoid conflicts with other projects.
# Create a virtual environment (optional but recommended)
python -m venv together_env
source together_env/bin/activate # On Windows, use `together_env\Scripts\activate`
# Install the Together AI Python SDK
pip install together-ai
After installation, you can verify the installation by attempting to import the together module in a Python interpreter.
JavaScript SDK
The JavaScript SDK can be installed using npm (Node Package Manager) or yarn, common package managers for Node.js projects. This SDK is compatible with both Node.js environments and modern web browsers that support module bundling.
# Using npm
npm install together-ai
# Or using yarn
yarn add together-ai
Once installed, the library can be imported into your JavaScript or TypeScript files using ES modules syntax.
Quickstart example
This quickstart example demonstrates how to use the Together AI Python SDK to perform a basic text completion request. This requires an API key, which can be obtained from the Together AI user interface. Ensure your API key is set as an environment variable (TOGETHER_API_KEY) or passed directly, though environment variables are recommended for security.
Python Quickstart: Text Completion
This Python example uses the together-ai library to generate text using the mistralai/Mixtral-8x7B-Instruct-v0.1 model. The model parameter specifies the LLM to use, and prompt provides the input text for generation.
import os
import together
# Ensure your API key is set as an environment variable or uncomment and replace 'YOUR_API_KEY'
# together.api_key = "YOUR_API_KEY"
def get_completion(prompt_text: str):
try:
response = together.chat.completions.create(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
messages=[
{
"role": "user",
"content": prompt_text,
}
],
max_tokens=50,
temperature=0.7,
)
return response.choices[0].message.content
except Exception as e:
return f"An error occurred: {e}"
if __name__ == "__main__":
user_prompt = "Explain the concept of large language models in a simple way."
generated_text = get_completion(user_prompt)
print(f"Prompt: {user_prompt}")
print(f"Generated Text: {generated_text}")
This script initializes the Together AI client and sends a chat completion request. The response object contains the generated text, which is then extracted and printed to the console. The max_tokens parameter limits the length of the generated output, and temperature influences the randomness of the output.
JavaScript Quickstart: Text Completion
This JavaScript example demonstrates a similar text completion task using the together-ai npm package. It assumes a Node.js environment where together-ai has been installed and an API key is available, ideally as an environment variable.
import Together from 'together-ai';
// Initialize the Together AI client (API key can be loaded from process.env.TOGETHER_API_KEY)
const together = new Together({
apiKey: process.env.TOGETHER_API_KEY, // Ensure this environment variable is set
});
async function getCompletion(promptText) {
try {
const response = await together.chat.completions.create({
model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
messages: [
{
role: 'user',
content: promptText,
},
],
max_tokens: 50,
temperature: 0.7,
});
return response.choices[0].message.content;
} catch (error) {
return `An error occurred: ${error.message}`;
}
}
(async () => {
const userPrompt = "Describe the benefits of using serverless GPUs for AI inference.";
const generatedText = await getCompletion(userPrompt);
console.log(`Prompt: ${userPrompt}`);
console.log(`Generated Text: ${generatedText}`);
})();
This JavaScript code uses an asynchronous function to call the chat.completions.create method. It passes the model name, user prompt within a messages array, and configuration parameters. The generated content is then extracted from the response object.
Community libraries
While Together AI provides official SDKs, the broader developer community often contributes additional libraries, connectors, and integrations that extend the platform's utility. These community-driven projects can offer specialized functionalities, alternative language bindings, or integrations with popular frameworks and tools not officially covered. Examples might include custom wrappers for specific use cases, integrations with data processing pipelines, or user interface components.
Developers often explore community libraries when seeking solutions tailored to niche requirements or when working in programming languages for which an official SDK is not yet available. These contributions are typically hosted on platforms like GitHub and may vary in maturity, documentation quality, and ongoing support. Users should evaluate community libraries based on their specific needs, examining factors such as active maintenance, community engagement, and security practices.
For instance, an application requiring stream processing of LLM outputs might benefit from a community library optimized for event-driven architectures. Another example could be a library that integrates Together AI with a specific web framework, simplifying tasks like token management or response parsing within that framework's ecosystem. While Together AI focuses on its core offerings, the open-source nature of many AI development tools encourages external contributions that can broaden adoption and use cases. For up-to-date information on community projects, developers can often consult the official Together AI documentation extras or community forums and repositories.
Beyond Together AI-specific community projects, developers may also utilize general-purpose libraries that interact with RESTful APIs, given that Together AI's platform is accessible via standard HTTP requests. For example, a developer might use a generic HTTP client library in a language without an official SDK to directly call the HTTP-based Together AI API. This approach requires manual handling of authentication, request formatting, and response parsing, but offers maximum flexibility. Such general-purpose tools are fundamental for interacting with many web services.