I'm trying to get this azure proxy url to work for days but nothing I do works. Most guides I see online involve either just regular openai or azure openai with azure identity not api key. I'm looking to pass this proxy url to my client app but calling it from the client app shows the same error as testing it with firebaseFunctions:shell.
The url is being truncated for some reason and I don't know why.
import { onRequest } from "firebase-functions/v2/https";
import axios, { isAxiosError } from "axios";
export const azureOpenaiProxy = onRequest(async (request, response) => {
try {
const apiKey = "[REDACTED]";
const baseURL = "https://[REDACTED].azure.com/openai/deployments";
const endpoint = "/gpt-4o/chat/completions?api-version=2024-08-01-preview";
const axiosInstance = axios.create({ baseURL });
const openaiResponse = await axiosInstance.post(endpoint, request.body, {
headers: {
"api-key": apiKey,
"Content-Type": "application/json",
},
});
if (isAxiosError(openaiResponse)) {
response.status(500).json({
error: "Internal server error",
message: openaiResponse.message,
});
} else {
response.status(200).send(openaiResponse.data);
}
} catch (error) {
response.status(500).json({
error: "Internal server error",
message: error instanceof Error ? error.message : "Unknown error",
});
}
});
Getting this error
{
"severity": "ERROR",
"message": "Proxy error: AxiosError: Request failed with status code 404",
"code": "ERR_BAD_REQUEST",
"config": {
"method": "post",
"url": "https://[REDACTED].azure.com/openai/deployments?api-version=2024-08-01-preview",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
"api-key": "[REDACTED]",
"User-Agent": "axios/1.7.7"
},
"data": "{}"
},
"response": {
"status": 404,
"statusText": "Resource Not Found",
"headers": {
"content-length": "56",
"content-type": "application/json"
},
"data": { "error": "[REDACTED]" }
},
"status": 404
}
In the error, it's like my url is bring truncated
However this curl request works just fine
curl -X POST \
'https://[REDACTED].azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview' \
-H 'api-key: [REDACTED]' \
-H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":"Tell me a joke about ice cream"}]}'
Does azure openai have some specific request style that I'm not aware of?
My actual code does indeed have the api key and the url.
Unlike openai azure openai doesn't accept a store param