Skip to main content
The Vercel AI SDK is a powerful Typescript library designed to help developers build AI-powered applications. Using Together AI and the Vercel AI SDK, you can easily integrate AI into your TypeScript, React, or Next.js project. In this tutorial, we’ll look into how easy it is to use Together AI’s models and the Vercel AI SDK.

QuickStart: 15 lines of code

  1. Install both the Vercel AI SDK and the Together AI provider package.
  1. Import the Together AI provider and call the generateText function with Kimi K2 to generate some text.
TypeScript

Output

Streaming with the Vercel AI SDK

To stream from Together AI models using the Vercel AI SDK, simply use streamText as seen below.
TypeScript

Output

Image Generation

To generate images with Together AI models using the Vercel AI SDK, use the .image() factory method. For more on image generation with the AI SDK see generateImage().
TypeScript
You can pass optional provider-specific request parameters using the providerOptions argument.
TypeScript
Together AI image models support various image dimensions that vary by model. Common sizes include 512x512, 768x768, and 1024x1024, with some models supporting up to 1792x1792. The default size is 1024x1024. Available Models:
  • black-forest-labs/FLUX.1-schnell
  • black-forest-labs/FLUX.1.1-pro
  • black-forest-labs/FLUX.1-kontext-pro
  • black-forest-labs/FLUX.1-kontext-max
  • black-forest-labs/FLUX.1-krea-dev
Please see the Together AI models page for a full list of available image models and their capabilities.

Embedding Models

To embed text with Together AI models using the Vercel AI SDK, use the .embeddingModel() factory method. For more on embedding models with the AI SDK see embed().
TypeScript
For a complete list of available embedding models and their model IDs, see the Together AI models page.
Some available model IDs include:
  • intfloat/multilingual-e5-large-instruct