generateImage method
Implementation
@override
Future<String> generateImage(String input) async {
final apiRequest = ApiRequest(
size: '1024x1024',
prompt: input,
numImages: 1,
responseFormat: 'url',
);
SecurePrint.log(apiRequest.toString());
final response = await http.post(
_apiUrl,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $_apiKey',
},
body: apiRequest.toJson(),
);
if (response.statusCode == 200) {
final responseJson = ApiResponse.fromJson(json.decode(response.body));
SecurePrint.log(responseJson.data.toString());
return responseJson.data.first.url;
} else {
throw Exception('Failed to generate image');
}
}