PHPackages                             edgaras/cloudflare-ai - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. edgaras/cloudflare-ai

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

edgaras/cloudflare-ai
=====================

Library for integrating and interacting with Cloudflare hosted AI models, providing tools for sending requests, managing model configurations, and processing responses.

1.0.0(1y ago)06MITPHPPHP &gt;=8.1.0

Since Jan 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Edgaras7/CloudFlare-AI)[ Packagist](https://packagist.org/packages/edgaras/cloudflare-ai)[ Docs](https://github.com/Edgaras7/CloudFlare-AI)[ RSS](/packages/edgaras-cloudflare-ai/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

CloudFlare AI
=============

[](#cloudflare-ai)

Features
--------

[](#features)

This library supports the following model categories:

- Text Generation.
- Text to Image.
- Text Embeddings.
- Translation.
- Summarization.

Requirements
------------

[](#requirements)

PHP 8.1+

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

[](#installation)

1. Use the library via Composer:

```
composer require edgaras/cloudflare-ai

```

2. Include the Composer autoloader:

```
require __DIR__ . '/vendor/autoload.php';
```

Usage
-----

[](#usage)

### Text Generation

[](#text-generation)

```
use Edgaras\CloudFlareAI\AI;
use Edgaras\CloudFlareAI\TextGeneration;

$accountId = "";
$apiToken = "";
$modelName = "@cf/deepseek-ai/deepseek-math-7b-instruct"; // Define the model name

$config = new AI($accountId, $apiToken);

$textGeneration = new TextGeneration($config, $modelName);

$messages = [
    ["role" => "system", "content" => "You are a helpful assistant"],
    ["role" => "user", "content" => "2+2=?"],
];

// Options
$options = [
    'temperature' => 0.7,
    'max_tokens' => 300,
    'top_p' => 0.8,
    'frequency_penalty' => 0.2,
    'presence_penalty' => 0.3,
];

// Run Model
$response = $textGeneration->run($messages, $options, 60);
```

### Text to Image

[](#text-to-image)

```
use Edgaras\CloudFlareAI\AI;
use Edgaras\CloudFlareAI\TextToImage;

$accountId = "";
$apiToken = "";
$modelName = "@cf/black-forest-labs/flux-1-schnell"; // Define the model name

$config = new AI($accountId, $apiToken);

$textToImage = new TextToImage($config, $modelName);

$prompt = "A futuristic cityscape at night with neon lights";
$options = [
    'negativePrompt' => "blurry, low resolution",
    'height' => 768,
    'width' => 1024,
    'numSteps' => 20,
    'guidance' => 7.5,
    'seed' => 12345678,
    'timeout' => 20.0,
    'maxAttempts' => 3,
];

// Generate the image
try {
    $result = $textToImage->generate($prompt, $options);

    if (isset($result['error'])) {
        echo "Error: " . $result['error'] . PHP_EOL;
        if (isset($result['response'])) {
            print_r($result['response']);
        }
    } else {
        echo "";
    }
} catch (Exception $e) {
    echo "Exception: " . $e->getMessage() . PHP_EOL;
}
```

### Text Embeddings

[](#text-embeddings)

```
use Edgaras\CloudFlareAI\AI;
use Edgaras\CloudFlareAI\TextEmbeddings;

$accountId = "";
$apiToken = "";
$modelName = "@cf/baai/bge-large-en-v1.5"; // Define the model name

$config = new AI($accountId, $apiToken);

$embeddings = new TextEmbeddings($config, $modelName);

// Provide the text to vectorize and the maximum timeout
$embed = $embeddings->embed("Text to vectorize", 60);
```

### Translation

[](#translation)

```
use Edgaras\CloudFlareAI\AI;
use Edgaras\CloudFlareAI\Translation;

$accountId = "";
$apiToken = "";
$modelName = "@cf/meta/m2m100-1.2b"; // Define the model name

$config = new AI($accountId, $apiToken);

$translation = new Translation($config, $modelName);

$text = "Hello, how are you?";
$sourceLang = "en";
$targetLang = "lt";

$response = $translation->translate($text, $targetLang, $sourceLang); // Optional parameters: $timeout, $maxAttempts
// echo $response['result']['translated_text'];
// Sveiki, kaip jūs jaučiatės?

```

### Summarization

[](#summarization)

```
use Edgaras\CloudFlareAI\AI;
use Edgaras\CloudFlareAI\Summarization;

$accountId = "";
$apiToken = "";
$modelName = "@cf/facebook/bart-large-cnn"; // Define the model name

$config = new AI($accountId, $apiToken);

$summarization = new Summarization($config, $modelName);

$inputText = "
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.
";
$maxLength = 100;

$response = $summarization->summarize($inputText, $maxLength);
// echo $response['result']['summary'];
// Lorem Ipsum is a piece of classical Latin literature from 45 BC. The word consectetur is one of the more obscure Latin words.
```

Useful links
------------

[](#useful-links)

- [Models](https://developers.cloudflare.com/workers-ai/models/).
- [Find zone and account IDs](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/).
- [Create API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance42

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

469d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb360d69caebafdf5339cd93817328b6fa1784f023009a6c27d84151bf212b01?d=identicon)[Edgaras](/maintainers/Edgaras)

---

Top Contributors

[![Edgaras0x4E](https://avatars.githubusercontent.com/u/42358442?v=4)](https://github.com/Edgaras0x4E "Edgaras0x4E (1 commits)")

---

Tags

aicloudflareartificial intelligencedeepseekllama

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/edgaras-cloudflare-ai/health.svg)

```
[![Health](https://phpackages.com/badges/edgaras-cloudflare-ai/health.svg)](https://phpackages.com/packages/edgaras-cloudflare-ai)
```

###  Alternatives

[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.4M28](/packages/rubix-ml)[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)[ardagnsrn/ollama-php

This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.

20755.8k](/packages/ardagnsrn-ollama-php)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)

PHPackages © 2026

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