Friday, March 22, 2024
HomeiOS Developmentios - OpenAI axios proxy api problem with TTS endpoint

ios – OpenAI axios proxy api problem with TTS endpoint


i’m engaged on a proxy api for my ios app to make use of the openai api with out offering the API_KEY to the ios app.

Due to this fact i take advantage of firebase capabilities, begin an specific server and proxy the request through axios.
The endpoint for chat completions works as anticipated and the ios shopper will get the anticipated information.

My downside is the tts endpoint when i ship textual content and count on the audio information from the OpenAI api.
That is the code i’m utilizing in my api.

const physique = req.physique;
const url = "https://api.openai.com/v1/audio/speech";
const API_KEY = course of.env.API_KEY;
const headers = {
  "Content material-Kind": "software/json",
  "Authorization": `Bearer ${API_KEY}`,
};
const {information} = await axios.submit(url, physique, {headers: headers});
res.ship(information);

The ios code:

var req = URLRequest(url: URL(string: "https://myAPI")!)
req.httpMethod = "POST"
req.httpBody = physique
req.setValue("software/json", forHTTPHeaderField: "Content material-Kind")
let outcome = strive await self.session.information(for: req)

I’m fairly certain that the issue is within the axios code half as a result of when i add the API key as header and straight name the https://api.openai.com/v1/audio/speechin ios it really works as anticipated.

Can someone inform me why the proxy logic appears to work for textual content chat completion however not for the audio/speech endpoint?

I already tried to hardcode the content-type of the response
res.set("Content material-Kind", "audio/aac"); and that i already tried to set a unique resposne-type
const {information} = await axios.submit(url, physique, {headers: headers, responseType: "arraybuffer"});.

Each does not appear to have any influence.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments