Troubleshooting of OpenAI API
Troubleshooting of OpenAI API
If you have any questions about the OpenAI API, you can post them on the OpenAI Developer Forum under the latest API topics.
How to fix "An error occurred"[edit]
- Error message: "An error occurred. If this issue persists please contact us through our help center at help.openai.com."
- Solution: Refresh the webpage https://chat.openai.com/chat
How to fix "Bad gateway"[edit]
Error message
{
"error": {
"code": 502,
"message": "Bad gateway.",
"param": null,
"type": "cf_bad_gateway"
}
}
Solution
- Attempt to resend the API request
How to fix "messages is a required property"[edit]
- Error message: 'messages' is a required property
{
"error": {
"message": "'messages' is a required property",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
- Example Input
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
}
- Solution: Check the payload data if the messages property is exists e.g.
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
"messages": [
{"role": "system", "content": "#zh-TW You are a helpful assistant. Help me to summarize the article"},
{"role": "user", "content": "YOUR ARTICLE ... ..."}
]
}
How to fix "" is not of type 'array' - 'messages'[edit]
- Error message:
{
"error": {
"message": "'' is not of type 'array' - 'messages'",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
- Example Input
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
"messages": ""
}
- Solution: The property messages should an array e.g.
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
"messages": [
{"role": "system", "content": "#zh-TW You are a helpful assistant. Help me to summarize the article"},
{"role": "user", "content": "YOUR ARTICLE ... ..."}
]
}
How to fix '2000' is not of type 'integer' - 'max_tokens'[edit]
- Error message:
{
"error": {
"message": "'2000' is not of type 'integer' - 'max_tokens'",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Solution: Modify the "max_tokens" parameter to an integer, rather than a string.
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
"messages": ""
}
How to fix "Invalid parameter: 'response_format' of type 'json_object' is not supported with this model"[edit]
Error message
Invalid parameter: 'response_format' of type 'json_object' is not supported with this model.
Example Input
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
"messages": [
{"role": "system", "content": "#zh-TW You are a helpful assistant. Help me to summarize the article"},
{"role": "user", "content": null}
]
}
Solution:
- The model "gpt-4" was not supported. Need to use model of gpt-3.5-turbo-1106 or gpt-4-1106-preview or gpt-4o [1][2][3].
{
"model": "gpt-4-1106-preview",
"max_tokens": 1000,
"temperature": 0.9,
"response_format": { "type": "json_object" },
"messages": [
{"role": "system", "content": "#zh-TW You are a helpful assistant. Help me to summarize the article"},
{"role": "user", "content": "YOUR ARTICLE ... ..."}
]
}
How to fix "'messages' must contain the word 'json' in some form, to use 'response_format' of type 'json_object'"[edit]
Error message
"error": {
"message": "'messages' must contain the word 'json' in some form, to use 'response_format' of type 'json_object'.",
"type": "invalid_request_error",
"param": "messages",
"code": null
}
Solution
- Add "output in JSON format" to the prompt ("system message") e.g.
Output Format: Provide your analysis in the following JSON format: ...
How to fix "Missing bearer or basic authentication in header"[edit]
Command met error condition
curl https://api.openai.com/v1/threads/$THREAD_IDmessages \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "OpenAI-Beta: assistants=v2"
Error message
{
"error": {
"message": "Missing bearer or basic authentication in header",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Corrected command:
curl https://api.openai.com/v1/threads/$THREAD_IDmessages \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -H "OpenAI-Beta: assistants=v2"
Explanation:
Order of Headers: While typically the order of headers should not impact the execution, ensuring a consistent and logical ordering (e.g., placing the Authorization header first) can sometimes help avoid parsing issues in certain environments or with certain tools.
How to fix "None is not of type string - messages.1.content"[edit]
- Error message:
{
"error": {
"message": "None is not of type 'string' - 'messages.1.content'",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
- Example Input
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
"messages": [
{"role": "system", "content": "#zh-TW You are a helpful assistant. Help me to summarize the article"},
{"role": "user", "content": null}
]
}
- Solution: The property messages.1.content should not be null e.g.
{
"model": "gpt-4",
"max_tokens": 1000,
"temperature": 0.9,
"messages": [
{"role": "system", "content": "#zh-TW You are a helpful assistant. Help me to summarize the article"},
{"role": "user", "content": "YOUR ARTICLE ... ..."}
]
}
How to fix "Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out"[edit]
Error message
Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600)
Solution
- you may want to try again in a few minutes, as the server did not respond within the allotted time (600 seconds).
How to fix "The model `gtp-4` does not exist"[edit]
- Error message: "The model `gtp-4` does not exist" or "The model: `gpt-4` does not exist"
{
"error": {
"message": "The model: `gpt-4` does not exist",
"type": "invalid_request_error",
"param": null,
"code": "model_not_found"
}
}
Solution:
- Correct the typo in the model name.
- Visit the Models - OpenAI API to view the list of models. You can also go to the GPT-4 product page to join the waiting list.
How to fix "That model is currently overloaded with other requests"[edit]
Error message:
{
"error": {
"message": "That model is currently overloaded with other requests. You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID XXX in your message.)",
"type": "server_error",
"param": null,
"code": null
}
}
Solution:
- Go to OpenAI Status to check if the server is outage
- Retry your request as suggested in the message
- Send an issue to OpenAI Help Center
How to fix "The project you are requesting has been archived and is no longer accessable (accessible)"[edit]
Error message:
{
"error": {
"message": "The project you are requesting has been archived and is no longer accessable",
"type": "invalid_request_error",
"param": null,
"code": "not_authorized_invalid_project"
}
}
Solution:
- If you are the administrator, first visit https://platform.openai.com/organization/api-keys to verify which API key is associated with which project.
- Next, go to https://platform.openai.com/organization/projects to determine if the project is active or archived.
- If the project is archived, you may need to assign the API key to another active project or a new one[4].
How to fix "This model's maximum context length is 4097 tokens"[edit]
Error message:
- "The message you submitted was too long, please reload the conversation and submit something shorter." or "This model's maximum context length is 4097 tokens, however you requested 4270 tokens (3770 in your prompt; 500 for the completion). Please reduce your prompt; or completion length."
{
"error": {
"message": "This model's maximum context length is 4097 tokens. However, your messages resulted in 9324 tokens. Please reduce the length of the messages.",
"type": "invalid_request_error",
"param": "messages",
"code": "context_length_exceeded"
}
}
Solution:
- Reduce the length of an input message[5]. (Count number of characters)
- Adjust to another model which support longer text
How to fix "The server had an error while processing your request"[edit]
Error message:
The server had an error while processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID XXXX1 in your message.)
Solution:
- Go to OpenAI Status to check if the server is outage
- Send an issue to OpenAI Help Center
How to fix "We could not parse the JSON body of your request"[edit]
Error message:
{
"error": {
"message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to [email protected] and include any relevant code you'd like help with.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Solution:
- Ensure that the payload you sent to the API is properly formatted as JSON.
How to fix "RateLimitError: Rate limit reached for default-gpt-3.5-turbo"[edit]
Error message: RateLimitError: Rate limit reached for default-gpt-3.5-turbo
RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-XXX on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method.
Other similar error message:
Rate limit reached for default-gpt-4 in organization org-xxx on tokens per min. Limit: 40000 / min. Please try again in 1ms. Contact us through our help center at help.openai.com if you continue to have issues.
Solution:
- Revise the frequency of API requests. To achieve this, incorporate a Sleep function between each API request within the script. For more information on rate limits, consult OpenAI's documentation at the following link: https://platform.openai.com/docs/guides/rate-limits.
- See more details on Sleep random seconds in programming
How to fix "You exceeded your current quota, please check your plan and billing details."[edit]
Error message: You exceeded your current quota, please check your plan and billing details.
{
"error": {
"message": "You exceeded your current quota, please check your plan and billing details.",
"type": "insufficient_quota",
"param": null,
"code": null
}
}
Solution:
- Visit https://platform.openai.com/account/usage to review your API usage.
- Look for the "OpenAI API - Hard Limit Notice" email, which contains information on requesting a quota increase by completing the provided form.
- Once your quota has been increased, navigate to https://platform.openai.com/account/billing/limits to adjust your hard limit accordingly.
How to fix "zsh: command not found: -d"[edit]
Error condition when I create vector store
curl https://api.openai.com/v1/vector_stores \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v2"
-d '{
"name": "Enter your preferred name here"
}'
Corrected Command:
curl https://api.openai.com/v1/vector_stores \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v2" \
-d '{
"name": "Enter your preferred name here"
}'
Explanation: The backslash \ at the end of each line indicates that the command is not yet finished and will continue on the next line. Ensure that there are no extra characters or commands after the -d parameter or any other parameters to avoid similar errors.
Force Traditional Chinese Output[edit]
- Add #zh-TW before your question [6]
- Or say "Use Traditional Chinese commonly used in Taiwan"
``` Use Traditional Chinese commonly used in Taiwan: Rules - Use full-width punctuation marks and add spaces between Chinese and English text. - Below is a common AI terminology correspondence table (English -> Traditional Chinese): * Transformer -> Transformer * Token -> Token * LLM/Large Language Model -> 大語言模型 * Zero-shot -> 零樣本 * Few-shot -> 少樣本 * AI Agent -> AI 代理 * AGI -> 通用人工智慧 - The following is a table of common Taiwanese terms (English -> Traditional Chinese): * create -> 建立 * quality -> 質量 * information = 資訊 * message = 訊息 * store = 儲存 * search = 搜尋 * view = 檢視, 檢視表 (No 視圖 as always) * create = created = 建立 * data = 資料 * object = 物件 * queue = 佇列 * stack = 堆疊 * invocation = 呼叫 * code = 程式碼 * running = 執行 * library = 函式庫 * building = 建構 * package = 套件 * video = 影片 * class = 類別 * component = 元件 * Transaction = 交易 * Code Generation = 程式碼產生器 * Scalability = 延展性 * Metadata = Metadata * Clone = 複製 * Memory = 記憶體 * Built-in = 內建 * Global = 全域 * Compatibility = 相容性 * Function = 函式 * document = 文件 * example = 範例 * blog = 部落格 * realtime = 即時 * document = 文件 * integration = 整合 ```
Further reading[edit]
- ChatGPT prompts ( How to improve the prompt design)
- General Top FAQ | OpenAI Help Center
- OpenAI API | OpenAI Help Center
- openai-cookbook/How_to_count_tokens_with_tiktoken.ipynb at main · openai/openai-cookbook · GitHub
- Highest scored 'openai-api' questions - Stack Overflow
- Error codes - OpenAI API
- OpenAI Batch API 常見技術問題排除
- Production best practices - OpenAI API
References[edit]
- ↑ response_format error · Issue #887 · openai/openai-python
- ↑ API Reference - OpenAI API
- ↑ 🛡️ OpenAI API Guide: Using JSON Mode - API - OpenAI Developer Forum
- ↑ Managing your work in the API platform with Projects | OpenAI Help Center
- ↑ ⬛ Splitting / Chunking Large input text for Summarisation (greater than 4096 tokens....) - General API discussion - OpenAI API Community Forum
- ↑ ChatGPT: How to Force Traditional Chinese Output | Learn Technology, Save Time - Learn Technology