Hey!
In the code snippet shared by you, the apiKey is expected to have the API KEY of the provider and
not the virtualKey
If you want it to work with virtualKey you can try this implementation.
const openai = new OpenAI({
apiKey: "", <- Can be left like this
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
apiKey: "PORKTKEY_API_KEY",
virtualKey: "PROVIDER_VIRTUAL_KEY"
})
});
Just notice that the apiKey in OpenAI client can be an empty string as well. Since this field is mandatory from the OpenAI SDK. It makes no difference tho.