Object with headers to set in the request to the AI service API.
If the provided value is an object
, it is simply used as provided.
If you are connecting directly to the OpenAI API, use your OpenAI API key in the following way:
{
ai: {
openAI: {
requestHeaders: {
'Authorization': 'Bearer YOUR_API_KEY'
}
// ...
}
// ..
}
}
Important: use your API key ONLY in a development environment or for testing purposes!
In the production environment, pass your request through a proxy endpoint.
If you are using a proxy service to send requests to the OpenAI API, requestHeaders
can be used to implement authorization for your
requests.
If the provided value is a function, it should be a function that returns a Promise
which resolves with the headers object.
This way, you can perform an authorization request to your application and receive the authorization token (and also implement
any custom logic on the back-end side). The headers object is then used to make the actual call to the AI service.
The function is passed actionId
parameter to make it
possible to further customize the headers.
{
ai: {
openAI: {
requestHeaders: async () => {
const jwt = await fetch( 'https://example.com/jwt-endpoint' );
return {
'Authorization': 'Bearer ' + jwt
};
}
// ...
}
}
}
If the function fails for any reason, the promise should be rejected. In this case, a feature that made the request should display
an error notification.