AuthenticationException class
Exception thrown when authentication fails (HTTP 401).
This typically indicates an invalid or expired API key.
Example
try {
await client.chat.completions.create(...);
} on AuthenticationException catch (e) {
print('Invalid API key: ${e.message}');
}
- Inheritance
-
- Object
- OpenAIException
- ApiException
- AuthenticationException
- Annotations
-
- @immutable
Constructors
-
AuthenticationException({required String message, String? type, String? code, String? param, String? requestId, Map<
String, dynamic> ? body, Object? cause}) -
Creates a new AuthenticationException.
const
Properties
-
body
→ Map<
String, dynamic> ? -
The raw response body, if available.
finalinherited
- cause → Object?
-
The underlying cause of this exception, if any.
finalinherited
- code → String?
-
The error code returned by the API.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- message → String
-
A human-readable description of the error.
finalinherited
- param → String?
-
The parameter that caused the error, if applicable.
finalinherited
- requestId → String?
-
The request ID for debugging purposes.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- statusCode → int
-
The HTTP status code returned by the API.
finalinherited
- type → String?
-
The error type returned by the API (e.g., 'invalid_request_error').
finalinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited