Implementation of OpenAI PHP Client via curl?

I’m currently building my own site via PHP, not sure if I can juse use curl to interact with the API?

All tutorials seem to be via laravel which I can’t use due to the scope of my project

Welcome to the community!

Of course! Almost all of the documentation comes with curl examples: https://platform.openai.com/docs/api-reference/chat?lang=curl

While that’s shell curl, you can always ask chatgpt to rewrite that into PHP curl for you. :slight_smile:

Yes I have implemented a PHP-cURL solution for my site recently and works fine

Thank you for the warm welcome, I have tried to go ahead and implement openai api in my php site but to no avail. Any chance do you think you can take a look at it?

$yourApiKey = getenv(‘YOUR_API_KEY’);
$client = OpenAI::client($yourApiKey);

$result = $client->chat()->create([
‘model’ => ‘gpt-4’,
‘messages’ => [
[‘role’ => ‘user’, ‘content’ => ‘Hello!’],
],
]);

echo $result->choices[0]->message->content; // Hello! How can I assist you today?

:thinking:

what did you do? how did you come up with that?

Definitely possible, my code is not reachable but simple prompting is possible with php. The hard part is assistant and custom. Regular prompting to an engine of choice is possible. I’ll try to post the code later tonight if I get to that system. Keep asking GPT how to do this. It failed for hours but after rephrasing and fixing glitches it worked.