Puck AI 0.5 adds a new onFinish API to track usage, and migrates to Puck 0.21 stable. See the AI overview for more information on Puck AI.
In this post, we’ll go over everything new in Puck AI 0.5 and how you can start using it:
You can also find in-depth documentation in our AI docs.
onFinishAll APIs in the @puckeditor/cloud-client package now support the onFinish() callback, which will receive usage information about the request.
// For handler
const handler = puckHandler({
ai: {
onFinish: ({ totalCost, tokenUsage }) => {
console.log(`Used ${totalCost} credit`);
},
},
});
// For generate
const page = await generate({
// ...
onFinish: ({ totalCost, tokenUsage }) => {
console.log(`Used ${totalCost} credit`);
},
});Puck AI packages now depend on Puck 0.21. You must also upgrade Puck when upgrading the AI packages, and vice versa.
npm install @puckeditor/core@0.21.0Please note, Puck 0.21 was renamed to @puckeditor/core.
Run the following command to install the latest version of Puck AI packages:
npm install @puckeditor/cloud-client@latest @puckeditor/plugin-ai@latestPuck AI is now in open beta. Sign up