KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Preventing UI Freezes When Using AIKit in 4D
PRODUCT: 4D | VERSION: 20 R | PLATFORM: Mac & Win
Published On: December 19, 2025
The use of 4D AIKit relies on API calls. These calls take time, sometimes a few hundred milliseconds, sometimes several seconds, depending on the request and the network. When such operations run in the main process, the User Interface pauses until the response arrives, which can make the user experience bad.

A simple way to avoid this behavior is to run the API call in a Worker. A Worker executes code in the background, independently from the UI. This keeps the interface active while the long-running task completes.

// --- Main process method: RequestAI ---
var $params : Object

$params := New object
$params.prompt := "Write a short motivational quote."

// Send task to Worker
CALL WORKER("AIWorker"; "DoAIRequest"; $params)