@@ -9,6 +9,7 @@ import (
99 "time"
1010
1111 "github.com/anthropics/anthropic-sdk-go"
12+ "github.com/anthropics/anthropic-sdk-go/bedrock"
1213 "github.com/anthropics/anthropic-sdk-go/option"
1314 "github.com/kujtimiihoxha/termai/internal/llm/models"
1415 "github.com/kujtimiihoxha/termai/internal/llm/tools"
@@ -21,6 +22,8 @@ type anthropicProvider struct {
2122 maxTokens int64
2223 apiKey string
2324 systemMessage string
25+ useBedrock bool
26+ disableCache bool
2427}
2528
2629type AnthropicOption func(*anthropicProvider)
@@ -49,6 +52,18 @@ func WithAnthropicKey(apiKey string) AnthropicOption {
4952 }
5053}
5154
55+func WithAnthropicBedrock() AnthropicOption {
56+ return func(a *anthropicProvider) {
57+ a.useBedrock = true
58+ }
59+}
60+
61+func WithAnthropicDisableCache() AnthropicOption {
62+ return func(a *anthropicProvider) {
63+ a.disableCache = true
64+ }
65+}
66+
5267func NewAnthropicProvider(opts ...AnthropicOption) (Provider, error) {
5368 provider := &anthropicProvider{
5469 maxTokens: 1024,
@@ -62,7 +77,16 @@ func NewAnthropicProvider(opts ...AnthropicOption) (Provider, error) {
6277 return nil, errors.New("system message is required")
6378 }
6479
65− provider.client = anthropic.NewClient(option.WithAPIKey(provider.apiKey))
80+ anthropicOptions := []option.RequestOption{}
81+
82+ if provider.apiKey != "" {
83+ anthropicOptions = append(anthropicOptions, option.WithAPIKey(provider.apiKey))
84+ }
85+ if provider.useBedrock {
86+ anthropicOptions = append(anthropicOptions, bedrock.WithLoadDefaultConfig(context.Background()))
87+ }
88+
89+ provider.client = anthropic.NewClient(anthropicOptions...)
6690 return provider, nil
6791}
6892
@@ -338,7 +362,7 @@ func (a *anthropicProvider) convertToAnthropicTools(tools []tools.BaseTool) []an
338362 },
339363 }
340364
341− if i == len(tools)-1 {
365+ if i == len(tools)-1 && !a.disableCache {
342366 toolParam.CacheControl = anthropic.CacheControlEphemeralParam{
343367 Type: "ephemeral",
344368 }
@@ -358,7 +382,7 @@ func (a *anthropicProvider) convertToAnthropicMessages(messages []message.Messag
358382 switch msg.Role {
359383 case message.User:
360384 content := anthropic.NewTextBlock(msg.Content().String())
361− if cachedBlocks < 2 {
385+ if cachedBlocks < 2 && !a.disableCache {
362386 content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
363387 Type: "ephemeral",
364388 }
@@ -370,7 +394,7 @@ func (a *anthropicProvider) convertToAnthropicMessages(messages []message.Messag
370394 blocks := []anthropic.ContentBlockParamUnion{}
371395 if msg.Content().String() != "" {
372396 content := anthropic.NewTextBlock(msg.Content().String())
373− if cachedBlocks < 2 {
397+ if cachedBlocks < 2 && !a.disableCache {
374398 content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
375399 Type: "ephemeral",
376400 }
@@ -404,4 +428,3 @@ func (a *anthropicProvider) convertToAnthropicMessages(messages []message.Messag
404428
405429 return anthropicMessages
406430}
407−