Skip to main content
The Vercel AI SDK is a TypeScript library for building AI-powered applications in TypeScript, React, or Next.js. The @ai-sdk/togetherai provider gives it native access to Together AI models.

Quickstart

  1. Install the Vercel AI SDK and the Together AI provider package.
  1. Import the Together AI provider and call generateText with Kimi K3.
TypeScript
Anything inside providerOptions.togetherai is passed through to the Together API as request body fields, so you can set Together-specific parameters the AI SDK doesn’t model itself. Kimi K3 reasons by default, and reasoning: { enabled: false } turns that off for tasks that don’t need it.

Streaming

To stream responses, use streamText:
TypeScript

Tool use

Define tools with the tool helper and a Zod schema. The SDK calls your execute function and feeds the result back to the model. Use stopWhen to let the model take the follow-up step after the tool result arrives:
TypeScript
For patterns beyond a single tool call, see function calling.

Structured outputs

To get a typed object back instead of free text, pass an Output.object with a Zod schema to generateText:
TypeScript
Use generateText with Output.object rather than generateObject. The Together provider doesn’t support the AI SDK’s JSON schema response format, so generateObject fails with a schema validation error.
For schema details and model support, see structured outputs.

Image generation

To generate images with Together AI models, 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
Supported image dimensions vary by model. Common sizes include 512x512, 768x768, and 1024x1024, with some models supporting up to 1792x1792. The default size is 1024x1024. See the Together AI models page for the full list of image models and their capabilities.