PHPackages                             clarifai/clarifai-php - 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. clarifai/clarifai-php

ActiveLibrary[API Development](/categories/api)

clarifai/clarifai-php
=====================

Clarifai PHP Client

0.7.0(6y ago)21133.0k↓43.2%3[1 issues](https://github.com/Clarifai/clarifai-php/issues)[1 PRs](https://github.com/Clarifai/clarifai-php/pulls)Apache-2.0PHPPHP &gt;=7.0.0CI passing

Since Jun 29Pushed 1y ago11 watchersCompare

[ Source](https://github.com/Clarifai/clarifai-php)[ Packagist](https://packagist.org/packages/clarifai/clarifai-php)[ Docs](https://clarifai.com/)[ RSS](/packages/clarifai-clarifai-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (13)Used By (0)

[![image](https://private-user-images.githubusercontent.com/445122/375442614-97876441-0d81-4ca7-81bb-abdc7dfac197.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUzNjA1NTYsIm5iZiI6MTc3NTM2MDI1NiwicGF0aCI6Ii80NDUxMjIvMzc1NDQyNjE0LTk3ODc2NDQxLTBkODEtNGNhNy04MWJiLWFiZGM3ZGZhYzE5Ny5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNDA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDQwNVQwMzM3MzZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02OWVhZGY0YjI2NzdmZWYyNDQ3N2EzNjlmNzdkY2E1MDBlZDg5ODkwYjAxNDQzZDNkYTM0NjlhM2Y0YzMwYWI0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.kDEp5vwkFFxciSHUtEClns9CmvQd4mizyoICyCdCijI)](https://private-user-images.githubusercontent.com/445122/375442614-97876441-0d81-4ca7-81bb-abdc7dfac197.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUzNjA1NTYsIm5iZiI6MTc3NTM2MDI1NiwicGF0aCI6Ii80NDUxMjIvMzc1NDQyNjE0LTk3ODc2NDQxLTBkODEtNGNhNy04MWJiLWFiZGM3ZGZhYzE5Ny5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNDA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDQwNVQwMzM3MzZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02OWVhZGY0YjI2NzdmZWYyNDQ3N2EzNjlmNzdkY2E1MDBlZDg5ODkwYjAxNDQzZDNkYTM0NjlhM2Y0YzMwYWI0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.kDEp5vwkFFxciSHUtEClns9CmvQd4mizyoICyCdCijI)

DEPRECATED
==========

[](#deprecated)

This API Client is no longer supported. Please use [Clarifai PHP gRPC](https://github.com/Clarifai/clarifai-php-grpc) instead, which is faster and more feature-rich.

Clarifai API PHP Client
=======================

[](#clarifai-api-php-client)

- Try the Clarifai demo at:
- Sign up for a free account at:
- Read the developer guide at:

[![Latest Stable Version](https://camo.githubusercontent.com/3e3528769e0f28897832682399d5a43df732d3730b89370bc9bab49d1abd245d/68747470733a2f2f706f7365722e707567782e6f72672f636c6172696661692f636c6172696661692d7068702f76657273696f6e)](https://packagist.org/packages/clarifai/clarifai-php)[![License](https://camo.githubusercontent.com/fbe3874d08f3c4afc8ac3ed30beb94c3cfd3b1296425058c6100074afc58295d/68747470733a2f2f706f7365722e707567782e6f72672f636c6172696661692f636c6172696661692d7068702f6c6963656e7365)](https://github.com/Clarifai/clarifai-php/blob/master/LICENSE)

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

[](#installation)

`composer require clarifai/clarifai-php`

> Note: If you're not using a framework (e.g Laravel), you may need to require the `autoload.php`file produced by composer: `require_once('vendor/autoload.php');`

### Prerequisites

[](#prerequisites)

PHP &gt;=7.0

> Note: This library requires the *curl* PHP extension to be enabled. This is most likely already done on your PHP host service, unless you're hosting PHP yourself, in which case you may need to uncomment (delete `;`) the line `extension=php_curl.dll` in your `php.ini` file.

Getting Started
---------------

[](#getting-started)

We're going to show three common examples of using the Clarifai API. Below are all the imports needed to run these examples. In addition, the `ClarifaiClient` object is created which is used to access all the available methods in the Clarifai API.

```
use Clarifai\API\ClarifaiClient;
use Clarifai\DTOs\Inputs\ClarifaiURLImage;
use Clarifai\DTOs\Outputs\ClarifaiOutput;
use Clarifai\DTOs\Predictions\Concept;
use Clarifai\DTOs\Searches\SearchBy;
use Clarifai\DTOs\Searches\SearchInputsResult;
use Clarifai\DTOs\Models\ModelType;

// Skip the argument to fetch the key from the CLARIFAI_API_KEY env. variable
$client = new ClarifaiClient('YOUR_API_KEY');
```

> Note: Rather than hard-coding your Clarifai API key, a better practice is to save the key in an environmental variable. If you skip the argument and do simply `new ClarifaiClient()`, the client will automatically try to read your API key from an environmental variable called `CLARIFAI_API_KEY`which you should set in your environment.

### Example #1: Prediction

[](#example-1-prediction)

The following code will recognise concepts that are contained within each of the images in a list. It uses our general public model that recognizes a wide variety of concepts.

```
$model = $client->publicModels()->generalModel();
$response = $model->batchPredict([
    new ClarifaiURLImage('https://samples.clarifai.com/metro-north.jpg'),
    new ClarifaiURLImage('https://samples.clarifai.com/wedding.jpg'),
])->executeSync();
```

If your use-case requires more specific predictions, you can use one of the more specialized public models such as the `weddingModel`, `foodModel`, `nfswModel` etc. [Here](https://clarifai.com/models/) is a list of all the available models.

> Note: You can also create your own models and train them on your own image dataset. We show how to do that in Example #2. Besides running the prediction on an URL image using `new ClarifaiURLImage`, you can also predict on a local file image by using `new ClarifaiFileImage`.

See below how to access the data from the `$response` variable. For each image, we print out all the concepts that were predicted by the model for that image.

```
/** @var ClarifaiOutput[] $outputs */
$outputs = $response->get();

foreach ($outputs as $output) {
    /** @var ClarifaiURLImage $image */
    $image = $output->input();
    echo "Predicted concepts for image at url " . $image->url() . "\n";

    /** @var Concept $concept */
    foreach ($output->data() as $concept) {
        echo $concept->name() . ': ' . $concept->value() . "\n";
    }
    echo "\n";
}
```

> Note: The value stored in `$concept->value()` is the precentage likelihood that the concept by the name of `$concept->name()` is contained within an image.

When something goes wrong, you can handle the error and inspect the details. In your program, this code below would go above the previous section of code.

```
if (!$response->isSuccessful()) {
    echo "Response is not successful. Reason: \n";
    echo $response->status()->description() . "\n";
    echo $response->status()->errorDetails() . "\n";
    echo "Status code: " . $response->status()->statusCode();
    exit(1);
}
```

See [the Clarifai Developer Guide](https://clarifai.com/developer/guide/) on how to do predict concepts in videos.

### Example #2: Custom model Creating and training a custom model on some inputs and concepts

[](#example-2-custom-model-creating-and-training-a-custom-model-on-some-inputs-and-concepts)

You can create your own model, add training data, and use the model to perform predictions on new images in the same way as in Example #1.

This is done by first creating concepts are the subject of our model. Sample inputs are then added which we associate or disassociate with certain concepts. After the model is created, we train the model, after which the model is available to performing predictions on new inputs.

```
$client->addConcepts([new Concept('boscoe')])
    ->executeSync();

$client->addInputs([
    (new ClarifaiURLImage('https://samples.clarifai.com/puppy.jpeg'))
        ->withPositiveConcepts([new Concept('boscoe')]),
    (new ClarifaiURLImage('https://samples.clarifai.com/wedding.jpg'))
        ->withNegativeConcepts([new Concept('boscoe')])
])
    ->executeSync();

$client->createModel('pets')
    ->withConcepts([new Concept('boscoe')])
    ->executeSync();

$response = $client->trainModel(ModelType::concept(), 'pets')
    ->executeSync();

if ($response->isSuccessful()) {
    echo "Response is successful.\n";
} else {
    echo "Response is not successful. Reason: \n";
    echo $response->status()->description() . "\n";
    echo $response->status()->errorDetails() . "\n";
    echo "Status code: " . $response->status()->statusCode();
}
```

### Example #3: Visual search

[](#example-3-visual-search)

An image can be used in a search to find other visually-similar images. After adding some images using `addInputs` (see Example #2), we use `searchInputs` to perform the search.

```
$response = $client->searchInputs(
        SearchBy::urlImageVisually('https://samples.clarifai.com/metro-north.jpg'))
    ->executeSync();

if ($response->isSuccessful()) {
    echo "Response is successful.\n";

    /** @var SearchInputsResult $result */
    $result = $response->get();

    foreach ($result->searchHits() as $searchHit) {
        echo $searchHit->input()->id() . ' ' . $searchHit->score() . "\n";
    }
} else {
    echo "Response is not successful. Reason: \n";
    echo $response->status()->description() . "\n";
    echo $response->status()->errorDetails() . "\n";
    echo "Status code: " . $response->status()->statusCode();
}
```

Please see [the Clarifai Developer Guide](https://clarifai.com/developer/guide/) to find out more of what the Clarifai API can give you.

Getting Help
------------

[](#getting-help)

If you need any help with using the library, please contact Support at  or our Developer Relations team at .

If you've found a bug or would like to make a feature request, please make an issue or a pull request here.

License
-------

[](#license)

This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~66 days

Recently: every ~120 days

Total

10

Last Release

2283d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/195a278eac0ca9afd0fa4f00d390204d8d962c5f7c642f43aad66afe11b2d428?d=identicon)[clarifai](/maintainers/clarifai)

---

Top Contributors

[![rok-povsic](https://avatars.githubusercontent.com/u/1495233?v=4)](https://github.com/rok-povsic "rok-povsic (69 commits)")[![rok-clarifai](https://avatars.githubusercontent.com/u/61063406?v=4)](https://github.com/rok-clarifai "rok-clarifai (4 commits)")[![bryanclarifai](https://avatars.githubusercontent.com/u/51921777?v=4)](https://github.com/bryanclarifai "bryanclarifai (2 commits)")[![alsonx](https://avatars.githubusercontent.com/u/1633588?v=4)](https://github.com/alsonx "alsonx (1 commits)")[![tot-ra](https://avatars.githubusercontent.com/u/445122?v=4)](https://github.com/tot-ra "tot-ra (1 commits)")

---

Tags

apiartificial intelligenceimage recognitionclarifaivideo recognition

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clarifai-clarifai-php/health.svg)

```
[![Health](https://phpackages.com/badges/clarifai-clarifai-php/health.svg)](https://phpackages.com/packages/clarifai-clarifai-php)
```

###  Alternatives

[clarifai/clarifai-php-grpc

Clarifai PHP gRPC client

1128.3k](/packages/clarifai-clarifai-php-grpc)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[passkit/passkit-php-grpc-sdk

PHP gRPC SDK for Apple Wallet and Google Pay Membership / Loyalty / Access Cards, Coupons, Flights &amp; Event-Tickets.

132.0k](/packages/passkit-passkit-php-grpc-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
