I ran a small AI SDK 4.3 tool-calling script on ai 7.0.185 (current latest) with a mock model. Only two things throw: the MockLanguageModelV1 import and toDataStreamResponse(). The rest fails silently: maxSteps is ignored (text is '' after the tool step), tool() 'parameters' sends the model an empty schema, maxTokens is dropped, and usage.promptTokens and toolResults[].result are undefined. Exact output and the v7 replacements below.
AI SDK 4 code run on ai 7.0.185 mostly fails without throwing. maxSteps, maxTokens and tool parameters are silently ignored, so generateText stops after the first tool call with text === '' and the model gets an empty tool schema. Only MockLanguageModelV1 and toDataStreamResponse() throw. Rename to stopWhen: stepCountIs(n), maxOutputTokens, inputSchema, usage.inputTokens/outputTokens, toolResults[].output and toUIMessageStreamResponse().
TypeError: stream.toDataStreamResponse is not a functionSyntaxError: The requested module 'ai/test' does not provide an export named 'MockLanguageModelV1'Environment
- ai 4.3.19 → 7.0.185 (npm
latest;ai-v5is 5.0.294,ai-v6is 6.0.339). zod 3.25.76 was kept, and ai 7 accepts^3.25.76 || ^4.1.8. - Node v22.23.3 in Docker
node:22, reproduced 2026-11-30. No API key: a mock model fromai/test. - The script is a support-triage bot. It calls
generateTextwith alookupOrdertool andmaxSteps: 3, classifies withgenerateObject, and streams a reply withstreamText+toDataStreamResponse(). On 4.3.19 it printsanswer: Order A-17 shipped yesterday.,steps: 2,usage: 42 14(repro/01-ai4-baseline.log). - Upgrade:
npm i ai@latest, with no code changes.
1. ai 7: `MockLanguageModelV1` is gone from `ai/test`
The first run fails at import (02-ai7-unchanged.log). In ai 7.0.185, ai/test exports MockLanguageModelV3 and MockLanguageModelV4 (07-ai7-test-exports.log). The V4 mock also expects the new result shape: a content array ({ type: 'text', text }, { type: 'tool-call', toolCallId, toolName, input }), finishReason: { unified, raw }, and nested usage (inputTokens: { total, … }). Streams need stream-start, text-start, text-delta with id/delta, and text-end. Only the mock was changed for the next steps (triage.v7-mock-only.mjs).
2. ai 7: `maxSteps` is ignored and `generateText` returns empty text
With the old app code on ai 7.0.185 there is no error and no warning (03-ai7-mock-v4-app-unchanged.log):
answer: steps: 1The tool did run: steps[0].toolResults contains the result. But generation stops after that first step, so the final answer is never produced. maxSteps is no longer read. Fix: stopWhen: stepCountIs(3) (import stepCountIs from ai). With that, the output is back to steps: 2 and the real answer (05-ai7-ported.log).
3. ai 7: `tool({ parameters })` sends the model an empty schema
I logged what the model receives (04-ai7-what-model-receives.log):
v4 names (parameters, maxTokens) maxOutputTokens sent to model: undefined tool schema sent to model: {"type":"object","properties":{},"additionalProperties":false}v5+ names (inputSchema, maxOutputTokens) maxOutputTokens sent to model: 200 tool schema sent to model: {"type":"object","properties":{"orderId":{"type":"string"}},"required":["orderId"],...}With parameters, the tool is still registered, but with no properties, so a real model has no argument names to fill in. I only tested this with the mock. maxTokens is dropped, so the output limit disappears. Neither produces a warning. Fix: inputSchema: z.object({...}) and maxOutputTokens.
4. ai 7: `usage.promptTokens` and `toolResults[].result` are `undefined`
tool result: undefinedusage: undefined undefinedThe fields were renamed: usage.inputTokens / usage.outputTokens (plus totalUsage), and toolResults[i].output. Code that logs or bills tokens records undefined instead of failing.
5. ai 7: `generateObject` still works, with a deprecation warning
(node:7) [AISDK_DEP_GENERATE_OBJECT] DeprecationWarning: AI SDK Warning: Deprecated: "generateObject". Use generateText with an output setting instead.Replacement: const { output } = await generateText({ model, output: Output.object({ schema }), prompt }). This returned the same object in the ported run.
6. ai 7: `toDataStreamResponse is not a function`
streamText itself still streams, but the old response helper throws (03-…log). Fix: toUIMessageStreamResponse(), which returned content-type: text/event-stream (it was text/plain; charset=utf-8 in 4.3.19). Because the format changed, the client has to be upgraded to match. I did not test a browser client. For plain text, use toTextStreamResponse().
Final working code (ai 7.0.185)
import { generateText, streamText, tool, stepCountIs, Output } from 'ai'const tools = { lookupOrder: tool({ description: 'Look up an order by id', inputSchema: z.object({ orderId: z.string() }), execute: async ({ orderId }) => ({ orderId, status: 'shipped' }) }) }const answer = await generateText({ model, system, prompt, tools, stopWhen: stepCountIs(3), maxOutputTokens: 200 })answer.totalUsage.inputTokens; answer.steps[0].toolResults[0].outputconst { output } = await generateText({ model, output: Output.object({ schema }), prompt })streamText({ model, prompt, maxOutputTokens: 50 }).toUIMessageStreamResponse()How to detect
grep -nE "maxSteps|maxTokens|parameters:|promptTokens|completionTokens|toDataStreamResponse|\.result\b" srclists every v4 name. ai 7 ignores the first three without any warning.- In a test, assert
result.steps.length > 1andresult.text !== ''for any tool flow.
Sources
- Migration guides: https://ai-sdk.dev/docs/migration-guides/migration-guide-5-0 and https://ai-sdk.dev/docs/migration-guides/migration-guide-7-0
- vercel/ai #13460 (tool
parametersnot read,inputSchemaundefined): https://github.com/vercel/ai/issues/13460 - vercel/ai #6383 (
toDataStreamResponse is not a function): https://github.com/vercel/ai/issues/6383