Select Together.ai models
An application needs to use Together.ai models through the AI SDK.
AI Tools · Function
createTogetherAI creates a customized Together.ai provider for the AI SDK. Configure its optional API key or API URL, then use the returned provider with Together.ai model identifiers.
createTogetherAI constructs a customized Together.ai provider instance. Pass an optional API key and/or base URL; the resulting provider can then be called with a Together.ai model identifier to obtain a language model.
createTogetherAI(options?: { apiKey?: string; baseURL?: string }): TogetherAIProvider| Name | Type | Description |
|---|---|---|
apiKey | string, optional | API key sent in the Authorization header; defaults to the TOGETHER_API_KEY environment variable. |
baseURL | string, optional | URL prefix for API calls; defaults to https://api.together.xyz/v1. |
A configured Together.ai provider instance that can be called with a model identifier.
import { createTogetherAI } from '@ai-sdk/togetherai';
const togetherai = createTogetherAI({
apiKey: process.env.TOGETHER_API_KEY ?? '',
});
const model = togetherai('meta-llama/Meta-Llama-3.3-70B-Instruct-Turbo');Creates a configured Together.ai provider and selects a model from it.
An application needs to use Together.ai models through the AI SDK.
Requests must pass through an organization-owned gateway.
Credentials should come from deployment configuration.
createTogetherAI is the factory for a customized Together.ai provider instance. It is imported from @ai-sdk/togetherai and accepts provider settings such as apiKey and baseURL.
Follow-up: How would you avoid hard-coding credentials? Omit apiKey or read it from process.env.TOGETHER_API_KEY, which is the documented default.
The apiKey setting supplies the key sent in the Authorization header. When it is not supplied, the provider reads TOGETHER_API_KEY from the environment.
Follow-up: What happens if the environment variable is absent? The provider receives no default key, so authentication must be supplied through configuration or the request cannot authenticate.
baseURL changes the URL prefix used for API calls. Its documented default is https://api.together.xyz/v1, and it can be changed for proxy servers or another endpoint.
Follow-up: When should baseURL remain unchanged? Keep the default when requests should go directly to Together.ai's standard API endpoint.
togetherai@ai-sdk/togetheraiTogether.ai APITOGETHER_API_KEYbaseURLapiKey