Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/providers/anthropic/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import { ProviderAPIConfig } from '../types';

const AnthropicAPIConfig: ProviderAPIConfig = {
getBaseURL: () => 'https://api.anthropic.com/v1',
headers: ({ providerOptions, fn }) => {
headers: ({ providerOptions, fn, gatewayRequestBody }) => {
const headers: Record<string, string> = {
'X-API-Key': `${providerOptions.apiKey}`,
};

// Accept anthropic_beta and anthropic_version in body to support enviroments which cannot send it in headers.
const betaHeader =
providerOptions?.['anthropicBeta'] ?? 'messages-2023-12-15';
const version = providerOptions?.['anthropicVersion'] ?? '2023-06-01';
providerOptions?.['anthropicBeta'] ??
gatewayRequestBody?.['anthropic_beta'] ??
'messages-2023-12-15';
const version =
providerOptions?.['anthropicVersion'] ??
gatewayRequestBody?.['anthropic_version'] ??
'2023-06-01';

if (fn === 'chatComplete') {
headers['anthropic-beta'] = betaHeader;
Expand Down
3 changes: 3 additions & 0 deletions src/types/requestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ export interface Params {
};
// Google Vertex AI specific
safety_settings?: any;
// Anthropic specific
anthropic_beta?: string;
anthropic_version?: string;
}

interface Examples {
Expand Down
Loading