chenfei-wu/TaskMatrix · error
OpenAI API error.
Error message
OpenAI API error.
What it means
Returned by planningLLM.get_workflow when the underlying OpenAI chat completion call fails. OpenAIWrapper catches all exceptions and returns status=False, so this string hides the actual cause (auth, quota, Azure misconfig, network).
Source
Thrown at LowCodeLLM/src/planningLLM.py:63
class planningLLM:
def __init__(self, temperature) -> None:
self.prefix = PLANNING_LLM_PREFIX
self.suffix = PLANNING_LLM_SUFFIX
self.LLM = OpenAIWrapper(temperature)
self.messages = [{"role": "system", "content": "You are a helpful assistant."}]
def get_workflow(self, task_prompt):
'''
- input: task_prompt
- output: workflow (json)
'''
messages = self.messages + [{'role': 'user', "content": PLANNING_LLM_PREFIX+'\nThe task is:\n'+task_prompt+PLANNING_LLM_SUFFIX}]
response, status = self.LLM.run(messages)
if status:
return self._txt2json(response)
else:
return "OpenAI API error."
def extend_workflow(self, task_prompt, current_workflow, step):
messages = self.messages + [{'role': 'user', "content": PLANNING_LLM_PREFIX+'\nThe task is:\n'+task_prompt+PLANNING_LLM_SUFFIX}]
messages.append({'role': 'user', "content": EXTEND_PREFIX+
'The current SOP is:\n'+current_workflow+
'\nThe step needs to be extended is:\n'+step+
PLANNING_LLM_SUFFIX})
response, status = self.LLM.run(messages)
if status:
return self._txt2json(response)
else:
return "OpenAI API error."
def _txt2json(self, workflow_txt):
''' convert the workflow in natural language to json format '''
workflow = []
try:
steps = workflow_txt.split('\n')
View on GitHub (pinned to 4b7664f8d3)
Solutions
- Add logging of the exception in OpenAIWrapper._post_request_chat to surface the real error.
- Check OPENAIKEY and Azure variables (USE_AZURE, API_BASE, API_VERSION, MODEL) in the server environment.
- Confirm the installed openai package still exposes openai.ChatCompletion (0.x API); pin openai<1.0 or migrate to openai.ChatCompletion -> client.chat.completions.create.
- Retry on transient rate-limit errors.
Example fix
# before
response, status = self.LLM.run(messages)
if status: return self._txt2json(response)
else: return "OpenAI API error."
# after - surface wrapper exception and retry once
response, status = self.LLM.run(messages)
if not status:
response, status = self.LLM.run(messages) # simple retry
if status: return self._txt2json(response)
else: raise RuntimeError('OpenAI call failed in get_workflow') Defensive patterns
Strategy: retry
Validate before calling
import os
missing = [v for v in ('OPENAIKEY',) if not os.environ.get(v)]
if os.environ.get('USE_AZURE','').lower()=='true':
missing += [v for v in ('API_BASE','API_VERSION','MODEL') if not os.environ.get(v)]
assert not missing, f'missing env: {missing}' Type guard
def is_workflow_json(w) -> bool:
if not isinstance(w, str) or w == 'OpenAI API error.': return False
import json; json.loads(w); return True Try / catch
result = llm.get_workflow(task)
if result == 'OpenAI API error.':
# fix config or retry with backoff; do not parse it as workflow JSON Prevention
- Pre-check env config at startup and fail fast
- Retry transient OpenAI failures with exponential backoff
- Pin openai<1.0 since the code uses the ChatCompletion 0.x API
When it happens
Trigger: POST /api/get_workflow where openai.ChatCompletion.create throws: missing/invalid OPENAIKEY, USE_AZURE=true with missing/wrong API_BASE/API_VERSION/MODEL, rate limits, or network failure.
Common situations: Server started without exporting OpenAI/Azure env vars; Azure deployment name mismatch; openai library version newer than the 0.x ChatCompletion API the code uses; exhausted quota.
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/39c234f4b312d90f.
Report an issue: GitHub.