AI SDK 6

Model Method

How to select and configure a model in AI SDK 6.

Model Method

The model call creates a typed model instance you pass to any generation function. It doesn't make a network request by itself.

Syntax

import { openai } from "@ai-sdk/openai";

const model = openai("gpt-4o-mini");

That's it. The string is the model name exactly as the provider defines it.

Optional Settings

Pass a second argument to override defaults:

const model = openai("gpt-4o-mini", {
  temperature: 0.7,    // creativity (0 = deterministic, 1 = random)
  maxTokens: 1024,     // max tokens in the response
});

Using Other Providers

import { anthropic } from "@ai-sdk/anthropic";
import { google }    from "@ai-sdk/google";

const claude = anthropic("claude-sonnet-4-5");
const gemini = google("gemini-2.0-flash");

The generation API (generateText, streamText, etc.) is identical regardless of provider — just swap the model.

Reusing a Model

You can define the model once and use it across many calls:

// model.ts
import { openai } from "@ai-sdk/openai";
export const model = openai("gpt-4o-mini");
// anywhere else
import { model } from "./model";
const result = await generateText({ model, prompt: "..." });