I am trying to call the chat gpt api (image generation) using the ASYNC Http client> in Android studio I am trying to generate an image based on text input. However i still get a failure whenever i try to call the api. I am still unsure how to go about this and help would be appreciated.
fun getaiimage(prompt:String) {
val client = AsyncHttpClient()
val params = RequestParams()
//apikey
val apikey = "API_KEY"
//Api parameters
params["prompt"] = prompt
params["size"] ="256x256"
params.put("n",1)
params["response_format"] = "https://api.openai.com/v1/images/generations"
params["model"] = "image-beta-003"
params["Authorization"] = "Bearer $apikey"
client["https://api.openai.com/v1/images/generations",params, object :
JsonHttpResponseHandler() {
override fun onFailure(
statusCode: Int,
headers: Headers?,
response: String?,
throwable: Throwable?
) {
Log.d("Image Failed","Big Errors")
}
override fun onSuccess(statusCode: Int, headers: Headers?, response: JSONObject) {
Log.d("Image Received","No Errors")
}
}]
}
I tried reformatting the code several times to no avail