@@ -15,6 +15,7 @@ import (
1515 "github.com/anthropics/anthropic-sdk-go"
1616 "github.com/anthropics/anthropic-sdk-go/bedrock"
1717 "github.com/anthropics/anthropic-sdk-go/option"
18+ "github.com/anthropics/anthropic-sdk-go/vertex"
1819 "github.com/charmbracelet/catwalk/pkg/catwalk"
1920 "github.com/charmbracelet/crush/internal/config"
2021 "github.com/charmbracelet/crush/internal/llm/tools"
@@ -26,21 +27,30 @@ var contextLimitRegex = regexp.MustCompile(`input length and ` + "`max_tokens`"
2627
2728type anthropicClient struct {
2829 providerOptions providerClientOptions
29− useBedrock bool
30+ tp AnthropicClientType
3031 client anthropic.Client
3132 adjustedMaxTokens int // Used when context limit is hit
3233}
3334
3435type AnthropicClient ProviderClient
3536
36−func newAnthropicClient(opts providerClientOptions, useBedrock bool) AnthropicClient {
37+type AnthropicClientType string
38+
39+const (
40+ AnthropicClientTypeNormal AnthropicClientType = "normal"
41+ AnthropicClientTypeBedrock AnthropicClientType = "bedrock"
42+ AnthropicClientTypeVertex AnthropicClientType = "vertex"
43+)
44+
45+func newAnthropicClient(opts providerClientOptions, tp AnthropicClientType) AnthropicClient {
3746 return &anthropicClient{
3847 providerOptions: opts,
39− client: createAnthropicClient(opts, useBedrock),
48+ tp: tp,
49+ client: createAnthropicClient(opts, tp),
4050 }
4151}
4252
43−func createAnthropicClient(opts providerClientOptions, useBedrock bool) anthropic.Client {
53+func createAnthropicClient(opts providerClientOptions, tp AnthropicClientType) anthropic.Client {
4454 anthropicClientOptions := []option.RequestOption{}
4555
4656 // Check if Authorization header is provided in extra headers
@@ -67,8 +77,13 @@ func createAnthropicClient(opts providerClientOptions, useBedrock bool) anthropi
6777 } else if hasBearerAuth {
6878 slog.Debug("Skipping X-Api-Key header because Authorization header is provided")
6979 }
70− if useBedrock {
80+ switch tp {
81+ case AnthropicClientTypeBedrock:
7182 anthropicClientOptions = append(anthropicClientOptions, bedrock.WithLoadDefaultConfig(context.Background()))
83+ case AnthropicClientTypeVertex:
84+ project := opts.extraParams["project"]
85+ location := opts.extraParams["location"]
86+ anthropicClientOptions = append(anthropicClientOptions, vertex.WithGoogleAuth(context.Background(), location, project))
7287 }
7388 for key, header := range opts.extraHeaders {
7489 anthropicClientOptions = append(anthropicClientOptions, option.WithHeaderAdd(key, header))
@@ -478,7 +493,7 @@ func (a *anthropicClient) shouldRetry(attempts int, err error) (bool, int64, err
478493 if err != nil {
479494 return false, 0, fmt.Errorf("failed to resolve API key: %w", err)
480495 }
481− a.client = createAnthropicClient(a.providerOptions, a.useBedrock)
496+ a.client = createAnthropicClient(a.providerOptions, a.tp)
482497 return true, 0, nil
483498 }
484499