@@ -157,6 +157,15 @@ func (a *anthropicClient) finishReason(reason string) message.FinishReason {
160+func (a *anthropicClient) isThinkingEnabled() bool {
162+ modelConfig := cfg.Models[config.SelectedModelTypeLarge]
163+ if a.providerOptions.modelType == config.SelectedModelTypeSmall {
164+ modelConfig = cfg.Models[config.SelectedModelTypeSmall]
166+ return a.Model().CanReason && modelConfig.Think
160func (a *anthropicClient) preparedMessages(messages []anthropic.MessageParam, tools []anthropic.ToolUnionParam) anthropic.MessageNewParams {
169func (a *anthropicClient) preparedMessages(messages []anthropic.MessageParam, tools []anthropic.ToolUnionParam) anthropic.MessageNewParams {
161 model := a.providerOptions.model(a.providerOptions.modelType)
170 model := a.providerOptions.model(a.providerOptions.modelType)
162 var thinkingParam anthropic.ThinkingConfigParamUnion
171 var thinkingParam anthropic.ThinkingConfigParamUnion
@@ -171,7 +180,7 @@ func (a *anthropicClient) preparedMessages(messages []anthropic.MessageParam, to
171 if modelConfig.MaxTokens > 0 {
180 if modelConfig.MaxTokens > 0 {
172 maxTokens = modelConfig.MaxTokens
181 maxTokens = modelConfig.MaxTokens
174− if a.Model().CanReason && modelConfig.Think {
183+ if a.isThinkingEnabled() {
175 thinkingParam = anthropic.ThinkingConfigParamOfEnabled(int64(float64(maxTokens) * 0.8))
184 thinkingParam = anthropic.ThinkingConfigParamOfEnabled(int64(float64(maxTokens) * 0.8))
176 temperature = anthropic.Float(1)
185 temperature = anthropic.Float(1)
@@ -216,9 +225,14 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message,
216 slog.Debug("Prepared messages", "messages", string(jsonData))
225 slog.Debug("Prepared messages", "messages", string(jsonData))
228+ var opts []option.RequestOption
229+ if a.isThinkingEnabled() {
230+ opts = append(opts, option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"))
219 anthropicResponse, err := a.client.Messages.New(
232 anthropicResponse, err := a.client.Messages.New(
221 preparedMessages,
234 preparedMessages,
223 // If there is an error we are going to see if we can retry the call
237 // If there is an error we are going to see if we can retry the call
224 if err != nil {
238 if err != nil {
@@ -268,10 +282,15 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
268 slog.Debug("Prepared messages", "messages", string(jsonData))
282 slog.Debug("Prepared messages", "messages", string(jsonData))
285+ var opts []option.RequestOption
286+ if a.isThinkingEnabled() {
287+ opts = append(opts, option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"))
271 anthropicStream := a.client.Messages.NewStreaming(
290 anthropicStream := a.client.Messages.NewStreaming(
273 preparedMessages,
292 preparedMessages,
274− option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"),
293+ opts...,
276 accumulatedMessage := anthropic.Message{}
295 accumulatedMessage := anthropic.Message{}