Skip to content

Incorrect error displaying when context size is larger than organization TPM #630

@asim-shrestha

Description

@asim-shrestha

Describe the bug

When you make a request to the OpenAI API and the context length exceeds your organizations allowed tokens per minute for the specific model, you will receive the following error:

Rate limit reached for default-gpt-4-large in organization org-xxxxxxxxxxxx on tokens per min. 

Limit: 150000 / min. Current: 0 / min. Contact us through our help center at help.openai.com if you continue to have issues.

This is confusing because it makes the issue appear to be at the organization level, when in fact a bug in your code is just causing your context to be too large. Instead, the following error message should appear:

This model's maximum context length is 4097 tokens, however you requested 150678 tokens (150000 in your prompt; 678 for the completion). Please reduce your prompt; or completion length."

To Reproduce

  1. Use the OpenAI python client
  2. Use any open ai chat completions endpoint with far too large a context length
  3. Observe error

Code snippets

No response

OS

macOS

Python version

^3.9

Library version

^0.27.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions