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)
- MUST: Manage input state yourself with
useState.useChatno longer providesinput,handleInputChange, orhandleSubmit. - MUST: Use
transport: new DefaultChatTransport({ api: '/api/chat' })instead ofapiprop. - MUST: Use
sendMessage({ text })instead ofhandleSubmit.
Structured Output
- MUST: Always use structured output when you need typed data back. Never parse JSON from
result.textmanually. - MUST: Use
Output.object({ schema }),Output.array({ element }), orOutput.choice({ options })withgenerateText. - MUST: Access results via
result.output, notresult.text. - SHOULD: Use
Output.choice({ options })for classification tasks instead of asking the model to return a string and comparing it.
Providers
- SHOULD: Use OpenRouter as the default provider via
@openrouter/ai-sdk-provider. Model IDs useprovider/modelformat (e.g.,openrouter('anthropic/claude-sonnet-4.5')). - MUST: Set
OPENROUTER_API_KEYin.env.local. The provider reads it automatically. - SHOULD: Use
createOpenRouter()when you need custom config (headers, extraBody, prompt caching). Use the defaultopenrouterimport for simple cases. - MUST: When requests hang silently, check prompt size first. OpenRouter has provider-specific context limits that may be smaller than the model's advertised limit.
Agents
- SHOULD: Use
ToolLoopAgentfor agents with tool loops. - SHOULD: Use
InferAgentUIMessage<typeof agent>for type-safe tool rendering inuseChat.
Prompt Engineering
- MUST: Keep 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.
- SHOULD: Prefer 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.
- SHOULD: Set
maxOutputTokensexplicitly when you know the expected output size. Prevents runaway generation and reduces cost.
Verification
- MUST: When 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.