Appearance
PHP 调用示例
使用 cURL
php
<?php
$apiKey = getenv("NEWAPI_API_KEY");
$url = "https://www.51api.org";
$data = [
"model" => "gpt-4.1",
"messages" => [
["role" => "developer", "content" => "你是一个有帮助的助手。"],
["role" => "user", "content" => "你好!"]
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Authorization: Bearer " . $apiKey
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>