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

Skip to content

openai.Audio.transcribe's api_key does not work; openai.error.AuthenticationError is raised #303

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

Closed
ftnext opened this issue Mar 13, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ftnext
Copy link
Contributor

ftnext commented Mar 13, 2023

Describe the bug

When passing the API Key to the api_key parameter of the openai.Audio.transcribe() method, an openai.error.AuthenticationError is thrown.

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/.../venv/lib/python3.10/site-packages/openai/api_resources/audio.py", line 55, in transcribe
    requestor, files, data = cls._prepare_request(file, file.name, model, **params)
  File "/.../venv/lib/python3.10/site-packages/openai/api_resources/audio.py", line 28, in _prepare_request
    requestor = api_requestor.APIRequestor(
  File "/.../venv/lib/python3.10/site-packages/openai/api_requestor.py", line 130, in __init__
    self.api_key = key or util.default_api_key()
  File "/.../venv/lib/python3.10/site-packages/openai/util.py", line 186, in default_api_key
    raise openai.error.AuthenticationError(
openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email [email protected] if you have any questions.

Upon inspecting the trace back, it seems that the cause is that the api_key is not passed to the _prepare_request method.

requestor, files, data = cls._prepare_request(file, file.name, model, **params)

When making the following modification, the AuthenticationError is not thrown and the transcription result is obtained.

-        requestor, files, data = cls._prepare_request(file, file.name, model, **params)
+        requestor, files, data = cls._prepare_request(file, file.name, model, api_key=api_key, **params)

To Reproduce

  1. pip install openai
  2. Create sample.wav (example: say 親譲りの無鉄砲で子供の時から損ばかりしている -o sample.wav --data-format=LEF32@16000)
  3. Run the following snippets

Code snippets

>>> OPENAI_API_KEY = "sk-***"
>>> import openai
>>> with open("sample.wav", "rb") as audio_file:
...   transcript = openai.Audio.transcribe("whisper-1", audio_file, api_key=OPENAI_API_KEY)

OS

macOS

Python version

Python 3.10.9

Library version

openai-python 0.27.2

@tanpinxi
Copy link
Contributor

Hi @ftnext, I have opened a PR to fix this bug

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