Thanks to visit codestin.com
Credit goes to github.com

Skip to content

module openai has no attribute resources #2349

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

Open
1 task done
DamianB-BitFlipper opened this issue May 9, 2025 · 6 comments
Open
1 task done

module openai has no attribute resources #2349

DamianB-BitFlipper opened this issue May 9, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@DamianB-BitFlipper
Copy link

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

With the latest version 1.78.0, openai.resources no longer exists.

Simply doing:

import openai
openai.resources

yields AttributeError: module 'openai' has no attribute 'resources'

I use the resources to import openai.resources.chat.Completions

In the previous version 1.77.0, this worked just fine. I am unsure if this intended behavior or a bug that slipped through. I'd appreciate your timely input!

To Reproduce

import openai
openai.resources

Code snippets

OS

macOS 15.3.1

Python version

Python 3.13.1

Library version

1.78.0

@DamianB-BitFlipper DamianB-BitFlipper added the bug Something isn't working label May 9, 2025
@RobertCraigie
Copy link
Collaborator

Ah this was likely because of a change we made to make imports faster, for now you should be able to workaround this with import openai.resources, can you let me know if that fixes the issue?

@RobertCraigie
Copy link
Collaborator

Could you also share what you're using the openai.resources import for? Trying to assess how common this breakage could be.

@DamianB-BitFlipper
Copy link
Author

DamianB-BitFlipper commented May 9, 2025

We're hooking in to openai.resources.chat.Completions.create and intercepting arguments

        original_create = openai.resources.chat.Completions.create

        def intercepted_create(_self: openai.resources.chat.Completions, **kwargs: Any) -> Any:
            ...

        # Replace the original method with our intercepted version
        openai.resources.chat.Completions.create = intercepted_create

as well as type hinting

completions: openai.resources.chat.Completions

The former usage is a bit obscure, but the latter is common and surprising not to work in my opinion.

Thanks for looking in to this.

@RobertCraigie
Copy link
Collaborator

Can you try this?

python -m pip install git+https://github.com/openai/openai-python@robert/fix-imports

@DamianB-BitFlipper
Copy link
Author

Works! Thanks again.

@liffiton
Copy link

liffiton commented May 9, 2025

Just another use case: I have tests that monkeypatch openai.resources.chat.Completions/AsyncCompletions to not send actual requests during most tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants