Skip to main content

Core Hooks

useWidgetProps()

Access data returned from your MCP tool’s execute() method.
How it works:
  • 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.
How it works:
  • Maps to window.openai.widgetState and setWidgetState()
  • State persists in ChatGPT’s conversation context
  • Survives page refreshes and widget re-renders
  • Accepts initial state as default value
Advanced usage:

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 to useOpenAiGlobal('displayMode').
Display modes:
  • inline - Default mode, widget appears inline with the conversation
  • pip - Picture-in-picture mode (mobile may coerce to fullscreen)
  • fullscreen - Full screen takeover

useMaxHeight()

Convenience hook for accessing the maximum height constraint. Equivalent to useOpenAiGlobal('maxHeight').
Best practices:
  • Always respect the maxHeight constraint
  • Use overflow: auto to enable scrolling
  • Consider the user’s viewport size when designing layouts

Available Globals

Use useOpenAiGlobal(key) to access:

TypeScript Support

All hooks include full TypeScript type definitions:

Creating Custom Convenience Hooks

You can easily create your own convenience hooks for frequently accessed globals:

Next Steps

Widget Basics

Back to Widget Basics

Advanced Patterns

Explore Advanced Patterns