📄 ai-sdk/docs/reference/ai-sdk-core/default-settings-middleware

File: default-settings-middleware.md | Updated: 11/15/2025

Source: https://ai-sdk.dev/docs/reference/ai-sdk-core/default-settings-middleware

AI SDK

Menu

v5 (Latest)

AI SDK 5.x

AI SDK by Vercel

AI SDK 6 Beta

Foundations

Overview

Providers and Models

Prompts

Tools

Streaming

Getting Started

Navigating the Library

Next.js App Router

Next.js Pages Router

Svelte

Vue.js (Nuxt)

Node.js

Expo

Agents

Agents

Building Agents

Workflow Patterns

Loop Control

AI SDK Core

Overview

Generating Text

Generating Structured Data

Tool Calling

Model Context Protocol (MCP) Tools

Prompt Engineering

Settings

Embeddings

Image Generation

Transcription

Speech

Language Model Middleware

Provider & Model Management

Error Handling

Testing

Telemetry

AI SDK UI

Overview

Chatbot

Chatbot Message Persistence

Chatbot Resume Streams

Chatbot Tool Usage

Generative User Interfaces

Completion

Object Generation

Streaming Custom Data

Error Handling

Transport

Reading UIMessage Streams

Message Metadata

Stream Protocols

AI SDK RSC

Advanced

Reference

AI SDK Core

generateText

streamText

generateObject

streamObject

embed

embedMany

generateImage

transcribe

generateSpeech

tool

dynamicTool

experimental_createMCPClient

Experimental_StdioMCPTransport

jsonSchema

zodSchema

valibotSchema

ModelMessage

UIMessage

validateUIMessages

safeValidateUIMessages

createProviderRegistry

customProvider

cosineSimilarity

wrapLanguageModel

LanguageModelV2Middleware

extractReasoningMiddleware

simulateStreamingMiddleware

defaultSettingsMiddleware

stepCountIs

hasToolCall

simulateReadableStream

smoothStream

generateId

createIdGenerator

AI SDK UI

AI SDK RSC

Stream Helpers

AI SDK Errors

Migration Guides

Troubleshooting

Copy markdown

defaultSettingsMiddleware()

=====================================================================================================================================

defaultSettingsMiddleware is a middleware function that applies default settings to language model calls. This is useful when you want to establish consistent default parameters across multiple model invocations.

import { defaultSettingsMiddleware } from 'ai';
const middleware = defaultSettingsMiddleware({  settings: {    temperature: 0.7,    maxOutputTokens: 1000,    // other settings...  },});

Import


import { defaultSettingsMiddleware } from "ai"

API Signature


Parameters

The middleware accepts a configuration object with the following properties:

  • settings: An object containing default parameter values to apply to language model calls. These can include any valid LanguageModelV2CallOptions properties and optional provider metadata.

Returns

Returns a middleware object that:

  • Merges the default settings with the parameters provided in each model call
  • Ensures that explicitly provided parameters take precedence over defaults
  • Merges provider metadata objects

Usage Example

import { streamText } from 'ai';import { wrapLanguageModel } from 'ai';import { defaultSettingsMiddleware } from 'ai';import { openai } from 'ai';
// Create a model with default settingsconst modelWithDefaults = wrapLanguageModel({  model: openai.ChatTextGenerator({ model: 'gpt-4' }),  middleware: defaultSettingsMiddleware({    settings: {      temperature: 0.5,      maxOutputTokens: 800,      providerMetadata: {        openai: {          tags: ['production'],        },      },    },  }),});
// Use the model - default settings will be appliedconst result = await streamText({  model: modelWithDefaults,  prompt: 'Your prompt here',  // These parameters will override the defaults  temperature: 0.8,});

How It Works


The middleware:

  1. Takes a set of default settings as configuration
  2. Merges these defaults with the parameters provided in each model call
  3. Ensures that explicitly provided parameters take precedence over defaults
  4. Merges provider metadata objects from both sources

On this page

defaultSettingsMiddleware()

Import

API Signature

Parameters

Returns

Usage Example

How It Works

Deploy and Scale AI Apps with Vercel.

Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.

Trusted by industry leaders:

  • OpenAI
  • Photoroom
  • leonardo-ai Logoleonardo-ai Logo
  • zapier Logozapier Logo

Talk to an expert