AI SDK Rules
Rule
Scope: Projects using Vercel AI SDK 6+ (ai package).
Deprecated APIs (NEVER use)
- NEVER
maxTokens— renamed tomaxOutputTokens. - NEVER
parametersin tool definitions — renamed toinputSchema. - NEVER
generateObject()— removed. UsegenerateText()withOutput.object({ schema }). - NEVER
maxSteps— removed. UsestopWhen: stepCountIs(n)(importstepCountIsfromai). - NEVER
toDataStreamResponse()— renamed totoUIMessageStreamResponse()when usinguseChat. - NEVER
tool-invocationas a part type — use typedtool-{toolName}parts. - NEVER
part.args/part.result— renamed topart.input/part.output. - NEVER
addToolResult()— renamed toaddToolOutput()(withoutputnotresult). - NEVER
messagesincreateAgentUIStreamResponse()— renamed touiMessages.
useChat (v6 Breaking Changes)
- MUSTManage input state yourself with
useState.useChatno longer providesinput,handleInputChange, orhandleSubmit. - MUSTUse
transport: new DefaultChatTransport({ api: '/api/chat' })instead ofapiprop. - MUSTUse
sendMessage({ text })instead ofhandleSubmit.
Structured Output
- MUSTAlways use structured output when you need typed data back. Never parse JSON from
result.textmanually. - MUSTUse
Output.object({ schema }),Output.array({ element }), orOutput.choice({ options })withgenerateText. - MUSTAccess results via
result.output, notresult.text. - SHOULDUse
Output.choice({ options })for classification tasks instead of asking the model to return a string and comparing it.
Providers
- SHOULDUse OpenRouter as the default provider via
@openrouter/ai-sdk-provider. Model IDs useprovider/modelformat (e.g.,openrouter('anthropic/claude-sonnet-4.5')). - MUSTSet
OPENROUTER_API_KEYin.env.local. The provider reads it automatically. - SHOULDUse
createOpenRouter()when you need custom config (headers, extraBody, prompt caching). Use the defaultopenrouterimport for simple cases. - MUSTWhen requests hang silently, check prompt size first. OpenRouter has provider-specific context limits that may be smaller than the model's advertised limit.
Agents
- SHOULDUse
ToolLoopAgentfor agents with tool loops. - SHOULDUse
InferAgentUIMessage<typeof agent>for type-safe tool rendering inuseChat.
Prompt Engineering
- MUSTKeep prompts under 100K tokens. Large payloads cause requests to hang silently on OpenRouter and other providers. If the input is large, chunk it or use tool calling to let the model request what it needs.
- SHOULDPrefer tool calling over prompt stuffing. Instead of pasting an entire codebase/document into the prompt, give the model a tool to search/retrieve relevant sections. This is cheaper, faster, and more reliable.
- SHOULDSet
maxOutputTokensexplicitly when you know the expected output size. Prevents runaway generation and reduces cost.
Verification
- MUSTWhen unsure about an API, check
node_modules/ai/docs/andnode_modules/ai/src/before using it. Do not trust memorized APIs.
Further Reading
For complete migration patterns and code examples, reference the use-ai-sdk skill or invoke /arc:ai.