PHPackages                             codewithkyrian/huggingface - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. codewithkyrian/huggingface

ActiveLibrary[API Development](/categories/api)

codewithkyrian/huggingface
==========================

Hugging Face Hub client for PHP. Manage repositories, run inference, and access thousands of models and datasets with a robust, type-safe API.

1.0.0(3mo ago)1611MITPHPPHP ^8.2CI passing

Since Feb 4Pushed 3mo agoCompare

[ Source](https://github.com/CodeWithKyrian/huggingface-php)[ Packagist](https://packagist.org/packages/codewithkyrian/huggingface)[ RSS](/packages/codewithkyrian-huggingface/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (1)

Hugging Face PHP
================

[](#hugging-face-php)

 [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/373716c6fdf57e41645fca3595e34898ffe7c7499a8876e5351defd3b5e196cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f6465776974686b797269616e2f68756767696e67666163652d7068702f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/codewithkyrian/huggingface-php/actions) [![Total Downloads](https://camo.githubusercontent.com/fa780ed8f3c646777051cb40f820cf552e7fb3873d3535aeff205d29d28d59a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6465776974686b797269616e2f68756767696e67666163653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codewithkyrian/huggingface) [![Latest Version](https://camo.githubusercontent.com/0b76eda3db8b0563020d71f34cb627c0008f029f68502f6ddb2b49e730d5fdd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6465776974686b797269616e2f68756767696e67666163653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codewithkyrian/huggingface) [![License](https://camo.githubusercontent.com/ec8292490dfd0a8ef7a7e57738d226c6a0d4520e0c72a99e24f8afd46c07ef6c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f6465776974686b797269616e2f68756767696e67666163652d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codewithkyrian/huggingface)

A comprehensive PHP client for the [Hugging Face Hub](https://huggingface.co). Access thousands of machine learning models, datasets, run inference, and more, all from your PHP application.

- **Hub API**: Full CRUD support for Repositories (Models, Datasets, Spaces), Files, and Collections.
- **Inference API**: Run inference on over 100,000+ models using Hugging Face's serverless abstraction. Automatically resolves the best provider for you.
- **Smart Caching**: Built-in, OS-aware caching system with support for generic file caching and optimization.
- **Type-Safe**: Fully typed DTOs for strict typing and better developer experience.
- **Utilities**: Includes specific utilities for various tasks like token classification, zero-shot classification, and more.

```
use Codewithkyrian\HuggingFace\HuggingFace;

$hf = HuggingFace::client();

// Download a model config
$config = $hf->hub()->repo('bert-base-uncased')
    ->download('config.json')
    ->json();

// List models
$models = $hf->hub()->models()
    ->search('sentiment')
    ->limit(5)
    ->get();

// Chat with an LLM
$response = $hf->inference()
    ->chatCompletion('meta-llama/Llama-3.1-8B-Instruct')
    ->system('You are a helpful assistant.')
    ->user('What is PHP?')
    ->generate();

// Generate embeddings
$embeddings = $hf->inference()
    ->featureExtraction('sentence-transformers/all-MiniLM-L6-v2')
    ->normalize()
    ->execute('Hello world');
```

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Hub API](#hub-api)
    - [Repository Basics](#repository-basics)
    - [Repository Info](#repository-info)
    - [Creating Repositories](#creating-repositories)
    - [Updating Repositories](#updating-repositories)
    - [Repository Operations](#repository-operations)
    - [Branch Management](#branch-management)
    - [File Operations](#file-operations)
    - [Downloading Files](#downloading-files)
    - [Downloading Entire Repositories](#downloading-entire-repositories)
    - [Uploading Files](#uploading-files)
    - [Deleting Files](#deleting-files)
    - [Listing Commits](#listing-commits)
    - [Collections](#collections)
    - [Searching Models, Datasets, and Spaces](#searching-models-datasets-and-spaces)
- [Inference API](#inference-api)
    - [Provider Configuration](#provider-configuration)
    - [Chat Completion](#chat-completion)
    - [Text Generation](#text-generation)
    - [Feature Extraction (Embeddings)](#feature-extraction-embeddings)
    - [Text Classification](#text-classification)
    - [Token Classification](#token-classification)
    - [Summarization](#summarization)
    - [Question Answering](#question-answering)
    - [Translation](#translation)
    - [Fill Mask](#fill-mask)
    - [Sentence Similarity](#sentence-similarity)
    - [Text to Image](#text-to-image)
    - [Image Classification](#image-classification)
    - [Object Detection](#object-detection)
    - [Image to Text](#image-to-text)
    - [Text to Speech](#text-to-speech)
    - [Automatic Speech Recognition](#automatic-speech-recognition)
- [Caching](#caching)
- [Error Handling](#error-handling)
- [Examples](#examples)
- [API Reference](#api-reference)

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require codewithkyrian/huggingface
```

### Requirements

[](#requirements)

- PHP 8.2 or higher
- A PSR-18 HTTP client (e.g., Guzzle, Symfony HttpClient)

If you don't have a PSR-18 client installed, add Guzzle:

```
composer require guzzlehttp/guzzle
```

Quick Start
-----------

[](#quick-start)

The client works without authentication for public resources:

```
