Tech Tip: Introduction to Error Handling in 4D AIKit
PRODUCT: 4D | VERSION: 20 R | PLATFORM: Mac & Win
Published On: December 9, 2025
When interacting with the OpenAI API through 4D AIKit, a request may fail due to invalid parameters, authentication issues, rate limits, or server-side problems.
AIKit returns a structured OpenAIError object whenever an API request does not succeed.
Detecting an Error
Every AIKit method returns an object containing a success flag:
Example :
Behavior on Failure
When success = False:
Through this unified structure, error inspection remains consistent regardless of the failure type.
AIKit returns a structured OpenAIError object whenever an API request does not succeed.
Detecting an Error
Every AIKit method returns an object containing a success flag:
- success = True → the request completed successfully
- success = False → an error occurred and the error property contains an OpenAIError instance
Example :
| var $client:=cs.AIKit.OpenAI.new("API Key") var $messages : Collection var $options : Object var $result : Object $messages:=[{role: "user"; content: "Explain quantum physics"}] $options:={model: "gpt-4o-mini"; max_tokens: 100} $result:=$client.chat.completions.create($messages; $options) If (Not($result.success)) $error:=$result.errors ALERT("Error: "+$error[0].message) End if |
Behavior on Failure
When success = False:
- No partial data is returned in the result
- The error property always contains a valid OpenAIError instance
- Error details can be extracted safely
- This provides a predictable pattern for error inspection.
Through this unified structure, error inspection remains consistent regardless of the failure type.