Make upstream provider SDKs optional#132
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
anbuzin
approved these changes
May 14, 2026
There was a problem hiding this comment.
Pull request overview
This PR makes upstream provider SDKs (openai, anthropic) optional for the ai package by moving them to extras and switching provider implementations to import those SDKs lazily only when the corresponding provider is instantiated/used.
Changes:
- Move
openai/anthropicfrom required dependencies to optional extras (ai[openai],ai[anthropic]) and keep them available in the dev dependency group. - Add an
InstallationErrorplus shared optional-import helper, and refactor OpenAI/Anthropic providers/protocols/errors to avoid importing SDKs at import time. - Add tests that assert a clear installation error is raised when a provider SDK is missing; update docs and example runners accordingly.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Reflects dependency changes: SDKs moved to optional extras and included in dev group. |
| pyproject.toml | Moves openai/anthropic to [project.optional-dependencies] and adds them to the dev dependency group. |
| src/ai/providers/_optional.py | Adds shared helper to import optional SDK modules and raise a user-facing InstallationError. |
| src/ai/errors.py | Introduces InstallationError in the public error hierarchy and exports it. |
| src/ai/init.py | Re-exports InstallationError from the top-level ai package API. |
| src/ai/providers/openai/_sdk.py | Centralizes lazy OpenAI SDK imports behind a typed protocol wrapper. |
| src/ai/providers/openai/provider.py | Removes eager OpenAI SDK import; loads SDK via _sdk when needed. |
| src/ai/providers/openai/protocol.py | Removes eager OpenAI SDK import; uses _sdk for runtime exception types and schema helper import. |
| src/ai/providers/openai/errors.py | Removes eager OpenAI SDK import; maps errors using lazily imported SDK types. |
| src/ai/providers/anthropic/_sdk.py | Centralizes lazy Anthropic SDK imports behind a typed protocol wrapper. |
| src/ai/providers/anthropic/provider.py | Removes eager Anthropic SDK import; loads SDK via _sdk when needed. |
| src/ai/providers/anthropic/protocol.py | Removes eager Anthropic SDK import; uses _sdk for runtime exception types. |
| src/ai/providers/anthropic/errors.py | Removes eager Anthropic SDK import; maps errors using lazily imported SDK types. |
| tests/providers/openai/test_provider.py | Adds coverage asserting InstallationError when OpenAI SDK cannot be imported. |
| tests/providers/anthropic/test_provider.py | Adds coverage asserting InstallationError when Anthropic SDK cannot be imported. |
| README.md | Documents optional extras required for direct OpenAI/Anthropic-compatible providers. |
| skills/ai/SKILL.md | Updates skill docs to mention provider extras and gateway behavior. |
| examples/samples/explicit_client.py | Moves explicit provider creation into main() to align with optional dependency behavior. |
| examples/samples/builtin_web_search.py | Defers provider/model setup into main() and avoids sys.exit for skip behavior. |
| examples/run-examples.py | Runs examples with the dev dependency group so optional SDKs are available. |
| examples/check-examples.py | Runs mypy for examples with the dev dependency group so optional SDKs are available. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+13
to
+14
| from . import _sdk, errors, protocol | ||
| from . import tools as tools_module |
Comment on lines
+13
to
+14
| from . import _sdk, errors, protocol | ||
| from . import tools as tools_module |
The `ai` package no longer depends on `openai` and `anthropic` directly and instead loads the SDKs lazily when a corresponding provider is instantiated. Upstream SDKs can be pulled-in via appropriately named optional dependency groups.
86d91d1 to
b1fba0f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
aipackage no longer depends onopenaiandanthropicdirectlyand instead loads the SDKs lazily when a corresponding provider is
instantiated. Upstream SDKs can be pulled-in via appropriately named
optional dependency groups.