Skip to content
Docs
Generative UI
getAIState

getAIState

getAIState

getAIState is called within a Server Action to get the current AI state. If key is provided, it will return the value of the specified key in the AI state if it's an object. If it's not an object, it will throw an error.

The AI state returned is read-only so if you want to make updates to it, you should use getMutableAIState.

Example

const state = getAIState(); // Get the entire AI state
const field = getAIState('key'); // Get the value of the key. This is equivalent to `getAIState().key`.

© 2023 Vercel Inc.