Messages is a required parameter ... but its there

I’m working on my project and I recently rejigged my chat code but I’m sure it was working after the rejig, but now its telling me that messages is required but messages is there…

This is an example of a request:

[{"model":"gpt-3.5-turbo-0613","messages":[{"role":"system","content":"You are a helpful assistant"},{"role":"user","content":"What do you remember on the night of the murder"}],"temperature":0.7,"max_tokens":256,"frequency_penalty":0,"presence_penalty":0,"functions":[],"function_call":"auto"}]

This is the code I’m using, I included the database stuff too so you can see where those requests and response come from

$request = array([
            'model' => 'gpt-3.5-turbo-0613',
            'messages' => $messages,
            'temperature' => 0.7,
            'max_tokens' => $max_tokens,
            'frequency_penalty' => 0,
            'presence_penalty' => 0,
            'functions'=>$functions,
            'function_call'=>$function_call

        ]);

        $open_ai = new OpenAi(getenv('OPEN_API_KEY'));
        $complete = json_decode($open_ai->chat($request));
        $db = new db();
        $db->connect();
        $db->query('insert into request_response set request=?, response=?', array(json_encode($request), json_encode($complete)));
This is the response:
{"error":{"message":"'messages' is a required property","type":"invalid_request_error","param":null,"code":null}}

Please learn Markdown for Discourse (ref) and format your post so it easier to read.
I will not even attempt to read this as posted.

What’s the code of $open_ai->chat($request)?

You may want to switch to a well-tested library like GitHub - openai-php/client: ⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.

I’m not a php developer, but my thought is that you are passing an array to the array() function while instead you want to pass in is just the key/value pairs. So, just remove the enclosing bracket:

$request = array(
  ‘model’ => ‘gpt-3.5-turbo-0613’,
  ‘messages’ => $messages,
  ‘temperature’ => 0.7,
  ‘max_tokens’ => $max_tokens,
  ‘frequency_penalty’ => 0,
  ‘presence_penalty’ => 0,
  ‘functions’=>$functions,
  ‘function_call’=>$function_call
);