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
Tool API Context preview

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

External services

openai

Ready to use?

View the full interactive pattern with live preview and copy the source code.

View the pattern on desktop

Related patterns