Deepseek PHP API
<?php class DeepSeekChat { private $url = 'https://api.deepseek.com/v1/chat/completions'; private $apiKey = 'YOUR_API_KEY'; // 替换为你的API Key public function chat($prompt) { $headers = [ 'Content-Type: application/json', 'Authorization: Bearer '.$this->apiKey ]; $data = [ 'model' => 'deepseek-chat', 'messages' => [ ['role' => 'user', 'content' => $prompt] ], 'temperature' => 0.7, 'max_tokens' => 2048 ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); return json_decode($response, true); } } ?>