
openai
#10039
invalid_role_error
Invalid role specified: input value is not one of the allowed roles ["system", "assistant", "user", "function"]. Please ensure the role is correctly defined.
This error has been identified and solved.
Reason
The error you are encountering, "SYSTEM is not one of ['system', 'assistant', 'user', 'function'] - 'messages.0.role'," indicates that the role specified in your API request is not supported by the specific OpenAI model you are using.
This issue arises because different OpenAI models have varying levels of support for different message roles. Specifically:
Some models, like the
o1-mini
, do not support thesystem
role, whereas other models might.The valid roles for messages can be limited to
SYSTEM
,USER
,ASSISTANT
,FUNCTION
, and sometimes additional roles likeTOOL
,CHATBOT
, orMODEL
, depending on the model and framework being used.
Solution
To fix the "Invalid role specified" error in the OpenAI API, you need to ensure that the role you are specifying is one of the allowed roles for the particular model you are using. Here are the steps to correct this:
Verify the model you are using and its supported roles.
Ensure the role in your request matches one of the allowed roles:
system
,assistant
,user
, orfunction
.If your model supports additional roles like
tool
,chatbot
, ormodel
, make sure to use those correctly if applicable.
Key points to check:
Model compatibility with the specified role.
Correct capitalization of the role (e.g.,
system
instead ofSYSTEM
).Adherence to the specific role constraints of the OpenAI model being used.