Moderations endpoint returns insufficient_quota

I’ve been trying to use the moderations endpoint for the first time, with no success.

I have a credit balance, and I’m able to successfully create chat completions. However every time I hit the moderations endpoint, using the instructions provided in the API docs, either via curl or the python library, I get “You exceeded your current quota, please check your plan and billing details.”

Any idea why this might be happening?

2 Likes

I have this problem too. The API doesn’t work. The tutorials make it seem simple. The error messages are wrong. This is a bug for two reasons: 429 is the wrong code. insufficient_quota is not true.

completion = client.chat.completions.create(
model=“gpt-4”,
messages=[
{“role”: “system”, “content”: “You are a poetic assistant, skilled in explaining complex programming concepts with creative flair.”},
{“role”: “user”, “content”: “Compose a poem that explains the concept of recursion in programming.”}
]
)

print(completion.choices[0].message)

stream = client.chat.completions.create(
model=“gpt-4”,
messages=[{“role”: “user”, “content”: “Say this is a test”}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end=“”)

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’}}

1 Like

Similarly, I am continuing to receive insufficient_quota error like you. There is another thread open right now where an OpenAI Dev Relations team member explains that the issue is still ongoing for some folks.

1 Like

I don’t have this issue.

I also have not just recently activated my account and made my first payment, which was who was affected by payment system issues earlier today, which apparently still needs attention.

What is peculiar is that the moderations API should be without cost and doesn’t consume credits. If a completions endpoint works for you, yet moderations gives a “please check your plan and billing details”, that certainly seems like some part of your recent credit purchase still has not taken effect or been repaired across all systems.

There’s a few things you can do (short of paying in another $5) to see if you can get a clear account status:

  • in the account “limits” page there are monthly limits. Glitches before this one were occasionally cleared by altering those values.
  • you can generate a new API key and see that it works in both code for chatcompletions and then moderations.
  • visit the billing settings and see that your personal preferences are filled out and re-save.

If using Python, and you’ve placed your OPENAI_API_KEY as an environment variable, the last code box in this post will give you a bit of immediate feedback to know it’s not your method:

Thanks @_j , a lot of helpful tips. I think some people continued to experience the issue besides having addressed each of the points you mentioned. No matter now, because the issue seems to have resolved automatically for me. Maybe it will have resolved for the others in this thread?

Did you resolve this issue, and did you find out how?
I am facing the same issue, with similar circumstances.

Same issue here, and we’re a tier 5 customer.

Same issue on something that happened at the start of the month is likely not “same issue”.

You can check a few things:

You are using the same API key in both application of chat completions and moderations code. The best way is via environment variable if the code also doesn’t have different virtual environments. You can make sure the funded organization is selected in your platform.openai.com (click on the name at the bottom, some have a “personal” org that has also been added. Then make a new API key, then deliberately place it in both moderations and chat completions code together to see that this is specific to moderations and specific to an account that might not be funded to use API at all.


Here’s python I whipped up to check moderations and get any error, and then also send to chat for any error.

import os, json, urllib.request, urllib.error

# replace {os.environ.get('OPENAI_API_KEY')} with actual key to hard-code
headers = {"Content-Type": "application/json",
           "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}"}
model = "gpt-3.5-turbo"
system = [{"role": "system", "content": f"You are ChatAPI"}]
user = [{"role": "user", "content": "Provide brief introduction."}]
chat = []
params_template = {"model": model, "max_tokens": 666, "top_p":0.9,}

while not user[0]['content'] == "exit":
    to_moderate =  {"input" : ', '.join([str(d) for d in (chat[-2:] + user)])}
    try:
        req = urllib.request.Request("https://api.openai.com/v1/moderations", \
          headers=headers, data=json.dumps(to_moderate).encode())
        scores = urllib.request.urlopen(req)
        print(json.loads(scores.read().decode())["results"][0]["categories"])
    except urllib.error.HTTPError as e:
        print(f"mod error {e.code}: {e.read().decode()}")
        pass

    request = {**params_template, **{"messages": system + chat[-10:] + user}}
    try:
        req = urllib.request.Request("https://api.openai.com/v1/chat/completions", \
          headers=headers, data=json.dumps(request).encode())
        response = urllib.request.urlopen(req)
    except urllib.error.HTTPError as e:
        print(f"chat error {e.code}: {e.read().decode()}")
        user = [{"role": "user", "content": input("\nPrompt: ")}]
        continue
    except Exception as e:
        print(f"Error: {e}")
        continue
    else:
        response_body = json.loads(response.read().decode())
        reply = response_body['choices'][0]['message']['content']
        print(reply)
    chat += user + [{"role": "assistant", "content": reply}]
    user = [{"role": "user", "content": input("\nPrompt: ")}]

That would let you ultimately see if only moderations is at fault.

Just flagged this to the team to take a look. I am not sure what would be causing the insufficient quota message if the rest of the API works okay.

2 Likes

I had unexpected quota issue yesterday. Root cause was OpenAI changing my account to prepaid on 20-FEB with “no action required” via email - which turned out to be not true.
Solution: manually loading some money from the CC into my account. An hour later the issue was gone. I then activated the auto reload feature.

Do you have any update from the development team about the insufficient quota message?

Logan won’t be offering any updates, as the update is he’s off to other opportunities.

If you are experiencing the same concern, it is your update that is needed. :wink:

me too, the request show code was 200, but the error is insufficinet_quota