aisdk / huggingface
Official HuggingFace provider for the PHP AI SDK.
Fund package maintenance!
v0.8.1
2026-07-22 07:06 UTC
Requires
- php: ^8.3
- aisdk/core: ^0.8.0
- aisdk/openai-compatible: ^0.8.0
Requires (Dev)
- laravel/pint: ^1.18
- nyholm/psr7: ^1.8
- pestphp/pest: ^3.0 || ^4.0
- phpstan/phpstan: ^2.0
- rector/rector: ^2.0
README
Official Hugging Face provider for the PHP AI SDK. Uses Hugging Face Inference Providers' OpenAI-compatible router.
Installation
composer require aisdk/huggingface
Basic Usage
use AiSdk\Generate; use AiSdk\HuggingFace; HuggingFace::create(['apiKey' => $_ENV['HF_TOKEN']]); $result = Generate::text('Explain this code briefly.') ->model(HuggingFace::model('openai/gpt-oss-120b:fastest')) ->run();
Configuration
| Variable | Description | Default |
|---|---|---|
HF_TOKEN |
Hugging Face access token | Required |
HUGGINGFACE_BASE_URL |
Base URL for API requests | https://router.huggingface.co/v1 |
Supported Capabilities
| Capability | Support |
|---|---|
| Text generation and streaming | Native OpenAI-compatible router |
| Tool calling, structured output, reasoning, image input | Passed through for supported routed models |
The OpenAI-compatible router package is chat-only. Use a Hugging Face native client for other task types. Use providerOptions('huggingface', ['raw' => [...]]) for native router fields.