Skip to content

⚡️ A robust and developer-friendly, and community-driven PHP Client that provides a clean, extensible interface for integrating with the DeepSeek AI API.

License

Notifications You must be signed in to change notification settings

deepseek-php/deepseek-php-client

Repository files navigation

DeepSeek PHP Client

🚀 Community-Driven PHP Client for DeepSeek AI API Integration

Latest Version Total Downloads PHP Version License GitHub Stars

AR | CN

Table of Contents


✨ Features

  • Seamless API Integration: PHP-first interface for DeepSeek's AI capabilities.
  • Fluent Builder Pattern: Chainable methods for intuitive request building.
  • Enterprise Ready: PSR-18 compliant HTTP client integration.
  • Model Flexibility: Support for multiple DeepSeek models (Coder, Chat, etc.).
  • Streaming Ready: Built-in support for real-time response handling.
  • Many Http Clients: easy to use Guzzle http client (default) , or symfony http client.
  • Framework Friendly: Laravel & Symfony packages available.

📦 Installation

Require the package via Composer:

composer require deepseek-php/deepseek-php-client

Requirements:

  • PHP 8.1+

🚀 Quick Start

Basic Usage

Get started with just two lines of code:

use DeepSeek\DeepSeekClient;

$response = DeepSeekClient::build('your-api-key')
    ->query('Explain quantum computing in simple terms')
    ->run();

echo $response;

📌 Defaults used:

  • Model: deepseek-chat
  • Temperature: 0.8

Advanced Configuration

use DeepSeek\DeepSeekClient;
use DeepSeek\Enums\Models;

$client = DeepSeekClient::build(apiKey:'your-api-key', baseUrl:'https://api.deepseek.com/v3', timeout:30, clientType:'guzzle');

$response = $client
    ->withModel(Models::CODER->value)
    ->withStream()
    ->setTemperature(1.2)
    ->setMaxTokens(8192)
    ->setResponseFormat('text') // or "json_object"  with careful .
    ->query('Explain quantum computing in simple terms')
    ->run();

echo 'API Response:'.$response;

⚠️ DeepSeek JSON Mode Requirement

When using:

->setResponseFormat('json_object')

Your prompt must contain the word "json" in some form. Otherwise, the API will reject the request with the following error:

"Prompt must contain the word 'json' in some form to use 'response_format' of type 'json_object'"


🚫 Incorrect Usage

->setResponseFormat('json_object')
->query('Explain quantum computing in simple terms')

✅ Correct Usage

->setResponseFormat('json_object')
->query('Respond in valid JSON format. Explain quantum computing in simple terms.')

Tip: For best results, also provide a JSON example or explicitly say: "Respond only in valid JSON."


Use with Symfony HttpClient

the package already built with symfony Http client, if you need to use package with symfony Http Client , it is easy to achieve that, just pass clientType:'symfony' with build function.

ex with symfony:

//  with defaults baseUrl and timeout
$client = DeepSeekClient::build('your-api-key', clientType:'symfony')
// with customization
$client = DeepSeekClient::build(apiKey:'your-api-key', baseUrl:'https://api.deepseek.com/v3', timeout:30, clientType:'symfony');

$client->query('Explain quantum computing in simple terms')
       ->run();

Get Models List

use DeepSeek\DeepSeekClient;

$response = DeepSeekClient::build('your-api-key')
    ->getModelsList()
    ->run();

echo $response; // {"object":"list","data":[{"id":"deepseek-chat","object":"model","owned_by":"deepseek"},{"id":"deepseek-reasoner","object":"model","owned_by":"deepseek"}]}

Function Calling

Function Calling allows the model to call external tools to enhance its capabilities.[1]

You Can check the documentation for function calling in FUNCTION-CALLING.md

🛠 Framework Integration


🚧 Migration Guide

Upgrading from v1.x? Check our comprehensive Migration Guide for breaking changes and upgrade instructions.


📝 Changelog

Detailed release notes available in CHANGELOG.md


🧪 Testing

./vendor/bin/pest

Test coverage coming in v2.1.


🐘✨ DeepSeek PHP Community ✨🐘

Click the button bellow or join here to be part of our growing community!

Join Telegram

Channel Structure 🏗️

  • 🗨️ General - Daily chatter
  • 💡 Ideas & Suggestions - Shape the community's future
  • 📢 Announcements & News - Official updates & news
  • 🚀 Releases & Updates - Version tracking & migration support
  • 🐞 Issues & Bug Reports - Collective problem-solving
  • 🤝 Pull Requests - Code collaboration & reviews

🔒 Security

Report Vulnerabilities: to omaralwi2010@gmail.com


🤝 Contributors

A huge thank you to these amazing people who have contributed to this project! 🎉💖

Omar AlAlwi
Omar AlAlwi

🏆 Creator
Ayman Alhattami
Ayman Alhattami

⭐ Contributor
Mohammad Asaad
Mohammad Asaad

⭐ Contributor
Opada Alzaiede
Opada Alzaiede

⭐ Contributor
Hisham Bin Ateya
Hisham Bin Ateya

⭐ Contributor
Vinchan
Vinchan

⭐ Contributor

Want to contribute? Check out the contributing guidelines and submit a pull request! 🚀


📄 License

This package is open-source software licensed under the MIT License.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy