mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 21:19:43 -08:00
117962d473
extracted out of #7336 --------- Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Alex Grozav <alex@grozav.com>
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import type {
|
|
IAuthenticateGeneric,
|
|
ICredentialTestRequest,
|
|
ICredentialType,
|
|
INodeProperties,
|
|
} from 'n8n-workflow';
|
|
|
|
export class OpenAiApi implements ICredentialType {
|
|
name = 'openAiApi';
|
|
|
|
displayName = 'OpenAi';
|
|
|
|
documentationUrl = 'openAi';
|
|
|
|
properties: INodeProperties[] = [
|
|
{
|
|
displayName: 'API Key',
|
|
name: 'apiKey',
|
|
type: 'string',
|
|
typeOptions: { password: true },
|
|
required: true,
|
|
default: '',
|
|
},
|
|
{
|
|
displayName: 'Organization ID (optional)',
|
|
name: 'organizationId',
|
|
type: 'string',
|
|
default: '',
|
|
hint: 'Only required if you belong to multiple organisations',
|
|
description:
|
|
"For users who belong to multiple organizations, you can set which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota.",
|
|
},
|
|
];
|
|
|
|
authenticate: IAuthenticateGeneric = {
|
|
type: 'generic',
|
|
properties: {
|
|
headers: {
|
|
Authorization: '=Bearer {{$credentials.apiKey}}',
|
|
'OpenAI-Organization': '={{$credentials.organizationId}}',
|
|
},
|
|
},
|
|
};
|
|
|
|
test: ICredentialTestRequest = {
|
|
request: {
|
|
baseURL: 'https://api.openai.com',
|
|
url: '/v1/models',
|
|
},
|
|
};
|
|
}
|