diff --git a/CHANGELOG.md b/CHANGELOG.md index ef3b02021..eb1165be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Upgraded Vercel AI SDK from v5 to v6. [#969](https://github.com/sourcebot-dev/sourcebot/pull/969) +- Added support for using bearer tokens with anthropic. [#967](https://github.com/sourcebot-dev/sourcebot/pull/967) ## [4.13.1] - 2026-02-28 diff --git a/docs/docs/configuration/language-model-providers.mdx b/docs/docs/configuration/language-model-providers.mdx index d888fd39f..91aab43de 100644 --- a/docs/docs/configuration/language-model-providers.mdx +++ b/docs/docs/configuration/language-model-providers.mdx @@ -89,9 +89,14 @@ For a detailed description of all the providers, please refer to the [schema](ht "provider": "anthropic", "model": "YOUR_MODEL_HERE", "displayName": "OPTIONAL_DISPLAY_NAME", + // Auth can be provided via a API key that is sent using the `x-api-key` header... "token": { "env": "ANTHROPIC_API_KEY" }, + // ...or via a auth token sent using the `Authorization: Bearer` header. + "authToken": { + "env": "ANTHROPIC_AUTH_TOKEN" + }, "baseUrl": "OPTIONAL_BASE_URL" } ] diff --git a/docs/snippets/schemas/v3/index.schema.mdx b/docs/snippets/schemas/v3/index.schema.mdx index d5e6721d1..4e857ee8c 100644 --- a/docs/snippets/schemas/v3/index.schema.mdx +++ b/docs/snippets/schemas/v3/index.schema.mdx @@ -1769,7 +1769,38 @@ "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", @@ -3198,7 +3229,38 @@ "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", diff --git a/docs/snippets/schemas/v3/languageModel.schema.mdx b/docs/snippets/schemas/v3/languageModel.schema.mdx index 40758fdbe..7d3eff422 100644 --- a/docs/snippets/schemas/v3/languageModel.schema.mdx +++ b/docs/snippets/schemas/v3/languageModel.schema.mdx @@ -222,7 +222,38 @@ "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", @@ -1651,7 +1682,38 @@ "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", diff --git a/packages/schemas/src/v3/index.schema.ts b/packages/schemas/src/v3/index.schema.ts index 52685c591..da6546ca6 100644 --- a/packages/schemas/src/v3/index.schema.ts +++ b/packages/schemas/src/v3/index.schema.ts @@ -1768,7 +1768,38 @@ const schema = { "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", @@ -3197,7 +3228,38 @@ const schema = { "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", diff --git a/packages/schemas/src/v3/index.type.ts b/packages/schemas/src/v3/index.type.ts index ac5c5d0c0..f60dd68f4 100644 --- a/packages/schemas/src/v3/index.type.ts +++ b/packages/schemas/src/v3/index.type.ts @@ -715,7 +715,7 @@ export interface AnthropicLanguageModel { */ displayName?: string; /** - * Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable. + * Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable. */ token?: | { @@ -730,6 +730,22 @@ export interface AnthropicLanguageModel { */ googleCloudSecret: string; }; + /** + * Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable. + */ + authToken?: + | { + /** + * The name of the environment variable that contains the token. + */ + env: string; + } + | { + /** + * The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets + */ + googleCloudSecret: string; + }; /** * Optional base URL. */ diff --git a/packages/schemas/src/v3/languageModel.schema.ts b/packages/schemas/src/v3/languageModel.schema.ts index 7e9e9c6bc..5832ddfcb 100644 --- a/packages/schemas/src/v3/languageModel.schema.ts +++ b/packages/schemas/src/v3/languageModel.schema.ts @@ -221,7 +221,38 @@ const schema = { "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", @@ -1650,7 +1681,38 @@ const schema = { "additionalProperties": false } ], - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "anyOf": [ + { + "type": "object", + "properties": { + "env": { + "type": "string", + "description": "The name of the environment variable that contains the token." + } + }, + "required": [ + "env" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "googleCloudSecret": { + "type": "string", + "description": "The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets" + } + }, + "required": [ + "googleCloudSecret" + ], + "additionalProperties": false + } + ], + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string", diff --git a/packages/schemas/src/v3/languageModel.type.ts b/packages/schemas/src/v3/languageModel.type.ts index 1bc86ec95..fad8f6cc7 100644 --- a/packages/schemas/src/v3/languageModel.type.ts +++ b/packages/schemas/src/v3/languageModel.type.ts @@ -124,7 +124,7 @@ export interface AnthropicLanguageModel { */ displayName?: string; /** - * Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable. + * Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable. */ token?: | { @@ -139,6 +139,22 @@ export interface AnthropicLanguageModel { */ googleCloudSecret: string; }; + /** + * Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable. + */ + authToken?: + | { + /** + * The name of the environment variable that contains the token. + */ + env: string; + } + | { + /** + * The resource name of a Google Cloud secret. Must be in the format `projects//secrets//versions/`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets + */ + googleCloudSecret: string; + }; /** * Optional base URL. */ diff --git a/packages/shared/src/env.server.ts b/packages/shared/src/env.server.ts index 15ba17cc9..f3627ad9b 100644 --- a/packages/shared/src/env.server.ts +++ b/packages/shared/src/env.server.ts @@ -202,6 +202,7 @@ export const env = createEnv({ REVIEW_AGENT_REVIEW_COMMAND: z.string().default('review'), ANTHROPIC_API_KEY: z.string().optional(), + ANTHROPIC_AUTH_TOKEN: z.string().optional(), ANTHROPIC_THINKING_BUDGET_TOKENS: numberSchema.default(12000), AZURE_API_KEY: z.string().optional(), diff --git a/packages/web/src/features/chat/actions.ts b/packages/web/src/features/chat/actions.ts index 3889a3a2f..6d646f6fb 100644 --- a/packages/web/src/features/chat/actions.ts +++ b/packages/web/src/features/chat/actions.ts @@ -764,6 +764,9 @@ export const _getAISDKLanguageModelAndOptions = async (config: LanguageModel): P apiKey: config.token ? await getTokenFromConfig(config.token) : env.ANTHROPIC_API_KEY, + authToken: config.authToken + ? await getTokenFromConfig(config.authToken) + : env.ANTHROPIC_AUTH_TOKEN, headers: config.headers ? await extractLanguageModelKeyValuePairs(config.headers) : undefined, diff --git a/schemas/v3/languageModel.json b/schemas/v3/languageModel.json index e56df4cee..7d2b261e7 100644 --- a/schemas/v3/languageModel.json +++ b/schemas/v3/languageModel.json @@ -71,7 +71,11 @@ }, "token": { "$ref": "./shared.json#/definitions/Token", - "description": "Optional API key to use with the model. Defaults to the `ANTHROPIC_API_KEY` environment variable." + "description": "Optional API key to use with the model, sent as the `x-api-key` header. Defaults to the `ANTHROPIC_API_KEY` environment variable." + }, + "authToken": { + "$ref": "./shared.json#/definitions/Token", + "description": "Optional auth token to use with the model, sent as the `Authorization: Bearer` header. Defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable." }, "baseUrl": { "type": "string",