Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

createTogetherAI

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.

How it works

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.

Syntax

createTogetherAI(options?: { apiKey?: string; baseURL?: string }): TogetherAIProvider

Parameters

NameTypeDescription
apiKeystring, optionalAPI key sent in the Authorization header; defaults to the TOGETHER_API_KEY environment variable.
baseURLstring, optionalURL prefix for API calls; defaults to https://api.together.xyz/v1.

Returns

A configured Together.ai provider instance that can be called with a model identifier.

Key points

  • Import createTogetherAI from @ai-sdk/togetherai.
  • Use the factory when the default provider instance is not enough and custom settings are required.
  • The factory accepts optional provider configuration rather than requiring every setting.
  • apiKey configures the credential transmitted through the Authorization header.
  • baseURL lets applications route Together.ai requests through a proxy or alternate API prefix.
  • The provider exposes Together.ai's broad catalog of open-source models.

Common mistakes

  • If apiKey is omitted, authentication uses the TOGETHER_API_KEY environment variable.
  • A custom baseURL replaces the provider's default API endpoint prefix, so set it only when using another endpoint or proxy.

Example: Create a Together.ai provider

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.

When to use it

Select Together.ai models

An application needs to use Together.ai models through the AI SDK.

Route through a proxy

Requests must pass through an organization-owned gateway.

Use environment-based authentication

Credentials should come from deployment configuration.

Interview questions

QWhat is createTogetherAI used for?

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.

QHow does authentication work?

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.

QWhy would you configure baseURL?

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/togetherai
  • Together.ai API
  • TOGETHER_API_KEY
  • baseURL
  • apiKey

Source: Together.ai - AI SDK. Checked 2026-10-15.