OpenAI API Streaming Issue Occurs with Error Code 50001
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 39.5k
- Forks
- 4.8k
- PR merge metrics
- No merged PRs in 30d
Description
When a request exceeds the allowable token count, the system generates the following response:
{"text": "YOUR INPUT VIOLATES OUR CONTENT MODERATION GUIDELINES. PLEASE FIX YOUR INPUT AND TRY AGAIN.\n\n(max_tokens must be at least 1, got -37938.)", "error_code": 50001}
The format shown above can cannot be correctly parsed as per the script at https://github.com/openai/openai-python/blob/main/src/openai/_streaming.py#L64
The correct format should look like this
{"id": "chatcmpl-NACKJsrvmTbrX4xKvjnVZG", "model": "xxxxxx", "choices": [{"index": 0, "delta": {"role": "assistant"}, "finish_reason": null}], "error": "xxxx"}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading openai-python's src/openai/_streaming.py around line 64, then trace the FastChat streaming response path that produces the shown JSON. Reproduce the over-token request and compare its response with the expected streaming format; done means the error response can be parsed consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100