Skip to content

providers: add opt-out build tags to reduce binary size#222

Draft
ljuti wants to merge 1 commit intocharmbracelet:mainfrom
ljuti:feat/provider-build-tags
Draft

providers: add opt-out build tags to reduce binary size#222
ljuti wants to merge 1 commit intocharmbracelet:mainfrom
ljuti:feat/provider-build-tags

Conversation

@ljuti
Copy link
Copy Markdown
Contributor

@ljuti ljuti commented Apr 30, 2026

Add opt-out build tags so users can exclude providers they don't use, reducing binary size significantly.

All providers compile by default — no breaking change. Pass -tags to exclude heavy dependency trees:

go build -tags "nogoogle,noaws,noazure,novercel,noopenrouter,nokronk" ./...

Tags

Tag Excludes
nogoogle providers/google + anthropic vertex support
noaws providers/bedrock + anthropic bedrock support
noazure providers/azure
novercel providers/vercel
noopenrouter providers/openrouter
nokronk providers/kronk

Implementation

  • Every .go file in each optional provider package gets //go:build !no<name>
  • providertests/ files that import optional providers get matching tags
  • Anthropic's bedrock.go / google.go gated behind !noaws / !nogoogle
  • Bedrock/Vertex LanguageModel configuration extracted into build-tagged files (bedrock_lm.go, vertex_lm.go) with error-returning stubs for when excluded
  • anthropic.go heavy imports (AWS SDK, Google OAuth) removed from main file

Binary size impact

Stripped -ldflags="-s -w" binary with anthropic + openai + openaicompat:

Size
All providers compiled 32 MB
Core only (all tags set) 12 MB
Savings 20 MB (63%)

Add opt-out build tags so users can exclude providers they don't use.
All providers compile by default (no breaking change). Pass -tags to
exclude heavy dependency trees:

  go build -tags "nogoogle,noaws,noazure,novercel,noopenrouter,nokronk"

Tags:
  nogoogle    — google provider + anthropic vertex support
  noaws       — bedrock provider + anthropic bedrock support
  noazure     — azure provider
  novercel    — vercel provider
  noopenrouter — openrouter provider
  nokronk     — kronk provider

Anthropic's bedrock.go and google.go are gated behind !noaws and
!nogoogle respectively. Bedrock/Vertex configuration is extracted
from anthropic.go into build-tagged files with error-returning stubs.

Binary size impact (stripped, anthropic+openai+openaicompat only):
  Before: 32 MB
  After:  12 MB  (63% reduction)
@ljuti ljuti force-pushed the feat/provider-build-tags branch from e01f1ec to 32c5d69 Compare April 30, 2026 19:53
@ljuti
Copy link
Copy Markdown
Contributor Author

ljuti commented Apr 30, 2026

@andreynering Opening this as a draft PR because I'm not sure if this is a direction that you want to go with the library. Feel free to reject and close if not aligned with project goals.

I'm building and maintaining an internal toolset that uses Fantasy and I'd like to keep the dependencies as clean as possible. Currently, my plan is to internally support only anthropic and openai-compat providers, and that is the reasoning behind this proposed modification. I'm happy to maintain my own fork with these modifications if this will not be accepted to the project.

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.

1 participant