1

Good evening,

I am using the Microsoft Azure OpenAI service for a GPT interface. My script looks like this:

$api_key = '7c96c21...';
$endpoint = 'https://openai24xyz.openai.azure.com/openai/deployments/Microsoft.CognitiveServicesOpenAI-202310.../completions?api-version=2023-05-15';

$data = [
    'prompt' => 'Wie geht es dir?',
    'max_tokens' => 50
];

$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $api_key
]);


$response = curl_exec($ch);
curl_close($ch);

dd($response);

API code has been shortened.

When I submit the script, I get the following response: { "statusCode": 401, "message": "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired.

But the API key is correct. Where could there be an error?

Greetings.

0

You must log in to answer this question.

Browse other questions tagged .