chenfei-wu/TaskMatrix · error
OpenAI API error.
Error message
OpenAI API error.
What it means
Returned (not raised) by executingLLM.execute when OpenAIWrapper.run reports failure. The wrapper catches every exception from openai.ChatCompletion.create and returns ('', False), so this string masks the true OpenAI error (auth, rate limit, timeout, quota, invalid deployment).
Source
Thrown at LowCodeLLM/src/executingLLM.py:42
"""
class executingLLM:
def __init__(self, temperature) -> None:
self.prefix = EXECUTING_LLM_PREFIX
self.suffix = EXECUTING_LLM_SUFFIX
self.LLM = OpenAIWrapper(temperature)
self.messages = [{"role": "system", "content": "You are a helpful assistant."},
{"role": "system", "content": self.prefix}]
def execute(self, current_prompt, history):
''' provide LLM the dialogue history and the current prompt to get response '''
messages = self.messages + history
messages.append({'role': 'user', "content": current_prompt + self.suffix})
response, status = self.LLM.run(messages)
if status:
return response
else:
return "OpenAI API error."View on GitHub (pinned to 4b7664f8d3)
Solutions
- Log the exception inside OpenAIWrapper._post_request_chat instead of swallowing it, then rerun to see the real OpenAI error.
- Verify OPENAIKEY is set and valid; if USE_AZURE=true verify API_BASE, API_VERSION, MODEL (deployment name).
- Fix malformed history (list of {'role','content'} dicts) that the API would reject.
- Retry with backoff for transient rate-limit/network errors.
Example fix
# before (openAIWrapper.py)
except Exception as e:
return "", False
# after
except Exception as e:
print('OpenAI call failed:', repr(e))
return "", False Defensive patterns
Strategy: retry
Validate before calling
import os
assert os.environ.get('OPENAIKEY'), 'OPENAIKEY not set'
if os.environ.get('USE_AZURE','').lower() == 'true':
for v in ('API_BASE','API_VERSION','MODEL'): assert os.environ.get(v), v + ' not set' Type guard
def is_llm_error(resp) -> bool:
return isinstance(resp, str) and resp.strip() == 'OpenAI API error.' Try / catch
for attempt in range(3):
out = llm.execute(prompt, history)
if not is_llm_error(out): break
time.sleep(2 ** attempt) Prevention
- Export OpenAI/Azure env vars in the process running app.py
- Validate history messages are role/content dicts
- Log wrapper exceptions instead of swallowing them
When it happens
Trigger: Calling llm.execute with any conditions that make openai.ChatCompletion.create throw: OPENAIKEY unset/invalid, USE_AZURE=true but API_BASE/API_VERSION/MODEL unset or pointing at a wrong deployment, rate limit/quota exceeded, or network unreachable. Also triggered by malformed history entries missing 'role'/'content'.
Common situations: Env vars not exported into the Flask process; Azure deployment name not matching MODEL; expired billing/quota; using the deprecated openai<1.0 API against a newer key/provider that requires it (or vice versa).
Related errors
- OpenAI API error.
- failed to get_workflow, msg:%s, request data:%s
- failed to extend_workflow, msg:%s, request data:%s
- failed to execute, msg:%s, request data:%s
- internal errors
AI-assisted analysis of chenfei-wu/TaskMatrix@4b7664f8d3 (2026-08-27).
Data as JSON: /api/errors/cd14c206820d7f00.
Report an issue: GitHub.