2023-01-27 03:22:44 -08:00
import type {
2022-12-15 16:05:42 -08:00
IAuthenticateGeneric ,
ICredentialTestRequest ,
ICredentialType ,
INodeProperties ,
} from 'n8n-workflow' ;
export class OpenAiApi implements ICredentialType {
name = 'openAiApi' ;
displayName = 'OpenAi' ;
2022-12-22 02:44:11 -08:00
documentationUrl = 'openAi' ;
2022-12-15 16:05:42 -08:00
properties : INodeProperties [ ] = [
{
displayName : 'API Key' ,
name : 'apiKey' ,
type : 'string' ,
typeOptions : { password : true } ,
required : true ,
default : '' ,
} ,
{
2023-11-28 07:47:28 -08:00
displayName : 'Organization ID (optional)' ,
2022-12-15 16:05:42 -08:00
name : 'organizationId' ,
type : 'string' ,
default : '' ,
2023-11-28 07:47:28 -08:00
hint : 'Only required if you belong to multiple organisations' ,
2022-12-15 16:05:42 -08:00
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' ,
} ,
} ;
}