2023-11-29 03:13:55 -08:00
|
|
|
import type {
|
|
|
|
IAuthenticateGeneric,
|
|
|
|
ICredentialTestRequest,
|
|
|
|
ICredentialType,
|
|
|
|
INodeProperties,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class AnthropicApi implements ICredentialType {
|
|
|
|
name = 'anthropicApi';
|
|
|
|
|
|
|
|
displayName = 'Anthropic';
|
|
|
|
|
|
|
|
documentationUrl = 'anthropic';
|
|
|
|
|
|
|
|
properties: INodeProperties[] = [
|
|
|
|
{
|
|
|
|
displayName: 'API Key',
|
|
|
|
name: 'apiKey',
|
|
|
|
type: 'string',
|
|
|
|
typeOptions: { password: true },
|
|
|
|
required: true,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
authenticate: IAuthenticateGeneric = {
|
|
|
|
type: 'generic',
|
|
|
|
properties: {
|
|
|
|
headers: {
|
|
|
|
'x-api-key': '={{$credentials.apiKey}}',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
test: ICredentialTestRequest = {
|
|
|
|
request: {
|
|
|
|
baseURL: 'https://api.anthropic.com',
|
2024-11-19 02:29:25 -08:00
|
|
|
url: '/v1/messages',
|
2023-11-29 03:13:55 -08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'anthropic-version': '2023-06-01',
|
|
|
|
},
|
|
|
|
body: {
|
2024-11-19 02:29:25 -08:00
|
|
|
model: 'claude-3-haiku-20240307',
|
|
|
|
messages: [{ role: 'user', content: 'Hey' }],
|
|
|
|
max_tokens: 1,
|
2023-11-29 03:13:55 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|