Core Hooks
useWidgetProps()
Access data returned from your MCP tool’sexecute()
method.
- Maps to
window.openai.toolOutput
- Data comes from your MCP tool’s
return
statement - Updates automatically on new tool calls
useWidgetState()
Manage persistent state that survives across ChatGPT sessions.- Maps to
window.openai.widgetState
andsetWidgetState()
- State persists in ChatGPT’s conversation context
- Survives page refreshes and widget re-renders
- Accepts initial state as default value
useOpenAiGlobal()
Access ChatGPT environment information like theme, layout, and locale. This is the base hook for accessing any global property.Convenience Hooks
useDisplayMode()
Convenience hook for accessing the current display mode. Equivalent touseOpenAiGlobal('displayMode')
.
inline
- Default mode, widget appears inline with the conversationpip
- Picture-in-picture mode (mobile may coerce to fullscreen)fullscreen
- Full screen takeover
useMaxHeight()
Convenience hook for accessing the maximum height constraint. Equivalent touseOpenAiGlobal('maxHeight')
.
- Always respect the
maxHeight
constraint - Use
overflow: auto
to enable scrolling - Consider the user’s viewport size when designing layouts
Available Globals
UseuseOpenAiGlobal(key)
to access:
Key | Type | Description | Example |
---|---|---|---|
theme | 'light' | 'dark' | ChatGPT’s current theme | 'dark' |
displayMode | 'inline' | 'pip' | 'fullscreen' | Current display mode | 'inline' |
locale | string | User’s preferred locale (IETF BCP 47) | 'en-US' , 'fr-FR' |
maxHeight | number | Maximum height constraint in pixels | 600 |
safeArea | SafeArea | Safe area insets for mobile layouts | { insets: { top: 20, ... }} |
userAgent | UserAgent | Device and capability information | { device: { type: 'mobile' }, ... } |
toolInput | object | Input parameters passed to your tool | { city: 'NYC' } |
toolOutput | object | Current tool output (same as useWidgetProps() ) | { message: 'Hello' } |
widgetState | object | Current persistent state (same as useWidgetState() ) | { count: 5 } |