mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(OpenAI Node): Support custom headers for model requests (#17835)
Co-authored-by: Idir Ouhab <ouhab.idir@gmail.com> Co-authored-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type {
|
||||
IAuthenticateGeneric,
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialTestRequest,
|
||||
ICredentialType,
|
||||
IHttpRequestOptions,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
@@ -37,17 +38,38 @@ export class OpenAiApi implements ICredentialType {
|
||||
default: 'https://api.openai.com/v1',
|
||||
description: 'Override the default base URL for the API',
|
||||
},
|
||||
];
|
||||
|
||||
authenticate: IAuthenticateGeneric = {
|
||||
type: 'generic',
|
||||
properties: {
|
||||
headers: {
|
||||
Authorization: '=Bearer {{$credentials.apiKey}}',
|
||||
'OpenAI-Organization': '={{$credentials.organizationId}}',
|
||||
},
|
||||
{
|
||||
displayName: 'Add Custom Header',
|
||||
name: 'header',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
};
|
||||
{
|
||||
displayName: 'Header Name',
|
||||
name: 'headerName',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
header: [true],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Header Value',
|
||||
name: 'headerValue',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
password: true,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
header: [true],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
|
||||
test: ICredentialTestRequest = {
|
||||
request: {
|
||||
@@ -55,4 +77,23 @@ export class OpenAiApi implements ICredentialType {
|
||||
url: '/models',
|
||||
},
|
||||
};
|
||||
|
||||
async authenticate(
|
||||
credentials: ICredentialDataDecryptedObject,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
requestOptions.headers = {
|
||||
Authorization: 'Bearer ' + credentials.apiKey,
|
||||
'OpenAI-Organization': credentials.organizationId,
|
||||
};
|
||||
if (
|
||||
credentials.header &&
|
||||
typeof credentials.headerName === 'string' &&
|
||||
credentials.headerName &&
|
||||
typeof credentials.headerValue === 'string'
|
||||
) {
|
||||
requestOptions.headers[credentials.headerName] = credentials.headerValue;
|
||||
}
|
||||
return requestOptions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user