Skip to content

Upgrade Anthropic provider from beta SDK to stable v1.4.0 #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ksylvan
Copy link
Contributor

@ksylvan ksylvan commented Jun 5, 2025

Upgrade Anthropic provider from beta SDK to stable v1.4.0

Summary

This PR updates the Anthropic SDK integration from beta version 0.2.0-beta.2 to stable version 1.4.0, along with necessary code changes to accommodate the SDK's API updates. The changes also include documentation updates to add the Claude 4 models to the supported model list.

Files Changed

README.md

Added Claude 4 Sonnet and Claude 4 Opus to the list of supported Anthropic models in the documentation.

cmd/schema/README.md

Minor formatting fix - removed extra newline at end of file.

go.mod and go.sum

Updated the Anthropic SDK dependency from v0.2.0-beta.2 to v1.4.0.

internal/llm/provider/anthropic.go

Updated code to match the new SDK API:

  • Changed field references from OfRequestTextBlock to OfText for text content blocks
  • Updated tool use block creation to use NewToolUseBlock helper function
  • Simplified thinking configuration parameter creation using ThinkingConfigParamOfEnabled helper

Code Changes

Text Block Cache Control Updates

// Before
content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
    Type: "ephemeral",
}

// After
content.OfText.CacheControl = anthropic.CacheControlEphemeralParam{
    Type: "ephemeral",
}

Tool Use Block Creation

// Before
anthropic.ContentBlockParamOfRequestToolUseBlock(toolCall.ID, inputMap, toolCall.Name)

// After
anthropic.NewToolUseBlock(toolCall.ID, inputMap, toolCall.Name)

Thinking Configuration Simplification

// Before
thinkingParam = anthropic.ThinkingConfigParamUnion{
    OfThinkingConfigEnabled: &anthropic.ThinkingConfigEnabledParam{
        BudgetTokens: int64(float64(a.providerOptions.maxTokens) * 0.8),
        Type:         "enabled",
    },
}

// After
thinkingParam = anthropic.ThinkingConfigParamOfEnabled(int64(float64(a.providerOptions.maxTokens) * 0.8))

Reason for Changes

  1. SDK Stability: Moving from a beta version to a stable release ensures better reliability and support
  2. API Compatibility: The SDK's API has changed between the beta and stable versions, requiring code updates to maintain functionality
  3. Documentation Accuracy: Adding Claude 4 models to the documentation ensures users are aware of all available model options

Impact of Changes

  • Improved Stability: Using a stable SDK version reduces the risk of breaking changes and improves overall reliability
  • No Functional Changes: The updates maintain the same functionality while adapting to the new SDK API
  • Better Developer Experience: The new SDK provides cleaner helper functions (like ThinkingConfigParamOfEnabled) that simplify the code

Test Plan

  • Verify that all Anthropic model interactions work correctly with the new SDK

  • Test message conversion with cache control enabled and disabled

  • Ensure tool use functionality continues to work as expected

  • Validate that thinking mode triggers correctly based on message content

  • Used compiled go binary to do major refactoring of an existing code repository:

image

Additional Notes

The changes are primarily mechanical updates to accommodate the SDK's API changes. The core logic and behavior remain unchanged. The addition of Claude 4 models to the documentation suggests these models are now available for use, though no code changes were needed to support them.

### CHANGES

- Upgrade Anthropic Go SDK dependency to version 1.4.0.
- Adapt provider code to breaking changes in the SDK.
- Update constructors for tool use and thinking parameters.
- Use new `OfText` field for accessing message content.
- Add Claude 4 Opus and Sonnet to documentation.
Copy link
Collaborator

@kujtimiihoxha kujtimiihoxha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like everything is working, thanks for the PR

@kujtimiihoxha kujtimiihoxha merged commit 05b0570 into opencode-ai:main Jun 7, 2025
@ksylvan
Copy link
Contributor Author

ksylvan commented Jun 7, 2025

Looks like everything is working, thanks for the PR

My pleasure.

@ksylvan ksylvan deleted the 0605-update-anthopic-sdk-and-support-claude4 branch June 7, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants