Skip to content

Error with the openai library #965

Closed
@CazyKiid

Description

@CazyKiid

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

I tried a simple chat requestion and throws this error.
I have installed pip 3 and python 3.11
I have updated the environment variables with my API KEY

import os
from openai import OpenAI
#from openai.types import FunctionDefinition, FunctionParameters

client = OpenAI(
# This is the default and can be omittedpip uninstall openai
api_key=os.environ.get("OPENAI_API_KEY"),
)

chat_completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages = [
{ "role": "user", "content": "Write a tagline for an ice cream shop." }
]
)
print(chat_completion['choices'][0]['message']['content'])

ERROR

Traceback (most recent call last):
File "c:\Users\desmo\Desktop\chatAttempt1.py", line 10, in
chat_completion = client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_utils_utils.py", line 303, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai\resources\chat\completions.py", line 598, in create
return self._post(
^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_base_client.py", line 1086, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_base_client.py", line 846, in request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_base_client.py", line 884, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_base_client.py", line 956, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_base_client.py", line 884, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_base_client.py", line 956, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\desmo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\openai_base_client.py", line 898, in _request
raise self._make_status_error_from_response(err.response) from None
openai.RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

To Reproduce

Just run the code it will show an error

Code snippets

import os
from openai import OpenAI
#from openai.types import FunctionDefinition, FunctionParameters

client = OpenAI(
    # This is the default and can be omittedpip uninstall openai
    api_key=os.environ.get("OPENAI_API_KEY"),
)

chat_completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
  messages = [
      { "role": "user", "content": "Write a tagline for an ice cream shop." }
  ]
)
print(chat_completion['choices'][0]['message']['content'])

OS

Windows 11

Python version

python 3.11

Library version

1.3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions