---
title: "Build Widget with AI"
method: POST
path: "/agents/widget-builder"
tags: ["Agents"]
---

# Build Widget with AI

`POST /agents/widget-builder`

Build a widget definition using AI based on a natural language prompt. The widget is created in memory and returned without being saved to the database. The prompt and agent response are saved as ChatMessages in the specified session.

## Request body

- WidgetBuilderRequest — Mixin to delegate create, update, and destroy operations to a service class.
  - `prompt` string, required — The user prompt describing the widget to build
  - `chat_session_id` string, required — The chat session ID to use for conversation context

## Response `200`

Successfully built widget

- object
  - `widget` object — The built widget definition (unsaved, id is null)
  - `message` object — The agent response ChatMessage

## Other responses

- `400` — Bad Request - Invalid prompt or chat_session_id
- `401` — Unauthorized
- `403` — Forbidden - Chat session does not belong to user

---

[API](https://skmtc.net/cubesoftware/apis/cube-api.md) · [All operations](https://skmtc.net/cubesoftware/apis/cube-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/cubesoftware/cube-api/revisions/67d9f45bb99b/schema)
