tool( )





Pattern
Tool API Context
Pass arbitrary context from generateText/streamText to tool execution via experimental_context. Access context in tool execute functions for dynamic behavior.
BeginnerNov 2025View the full pattern on desktop


Problems solved
- Pass request-scoped values through experimental_context
- Read shared context inside tool execute without model-supplied secrets
- Customize tool behavior per user or session without forking tool definitions
Use cases
- User-preference-aware tools
- Per-tenant API credential injection
- Session-scoped tool configuration
- Context-aware tool demos
AI SDK APIs
streamTextconvertToModelMessagestool(useChatexperimental_context
Tags
aitoolsexperimental-contextcontextdynamic-behaviorai-sdktool-api
Requirements
- Node.js
- 24+
- Memory
- 512MB
- Other
- OpenAI API key
Environment variables
OPENAI_API_KEYGet key
External services
openai
Ready to use?
View the full interactive pattern with live preview and copy the source code.
View the pattern on desktopRelated patterns


Tool Input Lifecycle Hooks
Explore tool input lifecycle hooks: onInputStart, onInputDelta, and onInputAvailable. See how to track tool input generation in real-time during streaming.
aitools+7
View pattern β


Preliminary Tool Results
Return preliminary tool results using async iterables. Stream status updates during tool execution before the final result is available.
aitools+6
View pattern β



