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
26 changes: 12 additions & 14 deletions containers/api-proxy/providers/anthropic.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ function createAnthropicAdapter(env, deps = {}) {
// Build the composed transform once at construction time to avoid
// re-allocating the wrapper function on every request.
const composedBodyTransform = composeBodyTransforms(depsBodyTransform, optimisationsTransform);
const buildOidcBearerAuthHeaders = (token) => ({ 'Authorization': 'Bearer ' + token });
const buildStaticAuthHeaders = () => ({ [authHeaderName]: apiKey });
const resolveAuthHeadersForValidationAndModels = () => resolveAuthHeadersWithFallback({
oidcProvider,
awsOidcProvider: null,
buildOidcHeaders: buildOidcBearerAuthHeaders,
staticHeaders: buildStaticAuthHeaders(),
});
const adapterMethods = createAdapterMethods({
apiKey,
rawTarget,
Expand All @@ -127,12 +135,7 @@ function createAnthropicAdapter(env, deps = {}) {
validationMethod: 'POST',
validationBody: '{}',
validationHeaders: () => ({
...resolveAuthHeadersWithFallback({
oidcProvider,
awsOidcProvider: null,
buildOidcHeaders: (token) => ({ 'Authorization': `Bearer ${token}` }),
staticHeaders: { [authHeaderName]: apiKey },
}),
...resolveAuthHeadersForValidationAndModels(),
'anthropic-version': '2023-06-01',
'content-type': 'application/json',
}),
Expand All @@ -145,12 +148,7 @@ function createAnthropicAdapter(env, deps = {}) {
skipModelsFetch: () => oidcConfigured && !oidcProvider?.isReady(),
modelsPath: '/v1/models',
modelsFetchHeaders: () => ({
...resolveAuthHeadersWithFallback({
oidcProvider,
awsOidcProvider: null,
buildOidcHeaders: (token) => ({ 'Authorization': `Bearer ${token}` }),
staticHeaders: { [authHeaderName]: apiKey },
}),
...resolveAuthHeadersForValidationAndModels(),
'anthropic-version': '2023-06-01',
}),
reflectionConfigured: !!apiKey || oidcRequested,
Expand All @@ -176,7 +174,7 @@ function createAnthropicAdapter(env, deps = {}) {
const oidcHeaders = resolveOidcAuthHeaders({
oidcProvider,
awsOidcProvider: null,
buildOidcHeaders: (token) => ({ 'Authorization': 'Bearer ' + token }),
buildOidcHeaders: buildOidcBearerAuthHeaders,
});

// oidcHeaders === null → OIDC not configured; fall through to static key.
Expand All @@ -187,7 +185,7 @@ function createAnthropicAdapter(env, deps = {}) {
return {};
}

const headers = oidcHeaders !== null ? { ...oidcHeaders } : { [authHeaderName]: apiKey };
const headers = oidcHeaders !== null ? { ...oidcHeaders } : buildStaticAuthHeaders();

if (!req.headers['anthropic-version']) {
headers['anthropic-version'] = '2023-06-01';
Expand Down
7 changes: 4 additions & 3 deletions containers/api-proxy/providers/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function createGeminiAdapter(env, deps = {}) {
basePathEnvVar: GEMINI_ENV.BASE_PATH,
defaultTarget: 'generativelanguage.googleapis.com',
});
const buildAuthHeaders = () => ({ 'x-goog-api-key': apiKey });

const adapterMethods = createAdapterMethods({
apiKey,
Expand All @@ -40,9 +41,9 @@ function createGeminiAdapter(env, deps = {}) {
port: 10003,
defaultTarget: 'generativelanguage.googleapis.com',
validationPath: '/v1beta/models',
validationHeaders: () => ({ 'x-goog-api-key': apiKey }),
validationHeaders: buildAuthHeaders,
modelsPath: '/v1beta/models',
modelsFetchHeaders: () => ({ 'x-goog-api-key': apiKey }),
modelsFetchHeaders: buildAuthHeaders,
});

return buildProviderAdapter({
Expand All @@ -51,7 +52,7 @@ function createGeminiAdapter(env, deps = {}) {
isManagementPort: false,
adapterMethods,
getAuthHeaders() {
return { 'x-goog-api-key': apiKey };
return buildAuthHeaders();
},
bodyTransform,
isEnabled() { return !!apiKey; },
Expand Down
20 changes: 7 additions & 13 deletions containers/api-proxy/providers/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,13 @@ function createOpenAIAdapter(env, deps = {}) {
skipModelsFetch,
resolveAuthHeaders,
} = createProviderOidcAuth(env, { staticAuthToken: apiKey });
/**
* Build a static-key auth header object.
* When AWF_OPENAI_AUTH_HEADER is set, uses that header name with the raw key.
* Otherwise uses the standard `Authorization: Bearer <key>` format.
*/
function buildStaticAuthHeaders(key) {
function buildTokenAuthHeaders(key) {
if (customAuthHeader) {
return { [customAuthHeader]: key };
}
return { 'Authorization': `Bearer ${key}` };
return { 'Authorization': 'Bearer ' + key };
}
const buildStaticAuthHeaders = () => buildTokenAuthHeaders(apiKey);

const adapterMethods = createAdapterMethods({
apiKey,
Expand All @@ -90,11 +86,11 @@ function createOpenAIAdapter(env, deps = {}) {
port: 10000,
defaultTarget: 'api.openai.com',
validationPath: '/v1/models',
validationHeaders: () => buildStaticAuthHeaders(apiKey),
validationHeaders: buildStaticAuthHeaders,
validationSkip,
skipModelsFetch,
modelsPath: '/v1/models',
modelsFetchHeaders: () => buildStaticAuthHeaders(apiKey),
modelsFetchHeaders: buildStaticAuthHeaders,
reflectionConfigured: !!apiKey || oidcConfigured,
reflectionModelsPath: '/v1/models',
reflectionExtra: () => ({
Expand All @@ -109,10 +105,8 @@ function createOpenAIAdapter(env, deps = {}) {
adapterMethods,
getAuthHeaders() {
return resolveAuthHeaders(
(token) => (customAuthHeader
? { [customAuthHeader]: token }
: { 'Authorization': ['Bearer', token].join(' ') }),
buildStaticAuthHeaders(apiKey),
buildTokenAuthHeaders,
buildStaticAuthHeaders(),
);
},
bodyTransform,
Expand Down
Loading