postRaw method

Future<List<int>> postRaw(
  1. String endpoint,
  2. Map<String, dynamic> body
)

Make a POST request and return raw bytes

Implementation

Future<List<int>> postRaw(
  String endpoint,
  Map<String, dynamic> body,
) async {
  if (config.apiKey.isEmpty) {
    throw const AuthError('Missing OpenAI API key');
  }

  try {
    final response = await dio.post(
      endpoint,
      data: body,
      options: Options(responseType: ResponseType.bytes),
    );

    if (response.statusCode != 200) {
      _handleErrorResponse(response, endpoint);
    }

    return response.data as List<int>;
  } on DioException catch (e) {
    throw handleDioError(e);
  } catch (e) {
    throw GenericError('Unexpected error: $e');
  }
}