Logo

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 the system role, whereas other models might.

  • The valid roles for messages can be limited to SYSTEM, USER, ASSISTANT, FUNCTION, and sometimes additional roles like TOOL, CHATBOT, or MODEL, 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, or function.

  • If your model supports additional roles like tool, chatbot, or model, 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 of SYSTEM).

  • Adherence to the specific role constraints of the OpenAI model being used.

Original Error Message

Raw

Invalid role specified: input value is not one of the allowed roles ["system", "assistant", "user", "function"]. Please ensure the role is correctly defined.

Original Error Message

Raw

Invalid role specified: input value is not one of the allowed roles ["system", "assistant", "user", "function"]. Please ensure the role is correctly defined.

Suggested Links

© 2024 Portkey, Inc. All rights reserved

HIPAA

COMPLIANT

GDPR

Transform Your AI app prototypes to be production-ready

Talk to us →