Last active
November 7, 2022 18:39
-
-
Save BetterProgramming/0df042841eb7ca03cc2a3afc7c604ea7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public async Task<IActionResult> GenerateImage([FromBody] input input) | |
{ | |
var resp = new ResponseModel(); | |
using (var client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Clear(); | |
client.DefaultRequestHeaders.Authorization = | |
new AuthenticationHeaderValue("Bearer", APIKEY); | |
var Message= await client. | |
PostAsync("https://api.openai.com/v1/images/generations", | |
new StringContent(JsonConvert.SerializeObject(input), | |
Encoding.UTF8, "application/json"));if (Message.IsSuccessStatusCode) | |
{ | |
var content = await Message.Content.ReadAsStringAsync(); | |
resp = JsonConvert.DeserializeObject<ResponseModel>(content); | |
} | |
} | |
return Json(resp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment