PHPackages                             lingoda/ai-sdk - 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. lingoda/ai-sdk

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

lingoda/ai-sdk
==============

Framework-agnostic PHP SDK for AI providers with typed results and platform abstraction

1.3.0(1mo ago)112.8k↓30.6%1MITPHPPHP ^8.3CI passing

Since Aug 27Pushed 1mo agoCompare

[ Source](https://github.com/lingoda/ai-sdk)[ Packagist](https://packagist.org/packages/lingoda/ai-sdk)[ RSS](/packages/lingoda-ai-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (40)Versions (8)Used By (1)

Lingoda AI SDK
==============

[](#lingoda-ai-sdk)

Framework-agnostic PHP SDK for AI providers with typed results and platform abstraction.

🚀 Quick Start
-------------

[](#-quick-start)

```
use Lingoda\AiSdk\Platform;
use Lingoda\AiSdk\Client\OpenAI\OpenAIClientFactory;

// Create client using factory
$client = OpenAIClientFactory::createClient('your-api-key');
$platform = new Platform([$client]);

// Simple ask() method - automatically uses default model
$result = $platform->ask('Hello, AI!');
echo $result->getContent(); // TextResult

// Or specify a specific model
$result = $platform->ask('Hello, AI!', 'gpt-4o-mini');
echo $result->getContent();

// Audio capabilities
$audioResult = $platform->textToSpeech('Hello world', $audioOptions);
$transcription = $platform->transcribeAudio('/path/to/audio.mp3', $options);
```

📚 Documentation
---------------

[](#-documentation)

GuideDescription[Installation](docs/installation.md)Setup and Platform basics[Configuration](docs/configuration.md)API keys and multi-provider setup[Quick Start](docs/quick-start.md)Your first AI request[Symfony Integration](docs/symfony-integration.md)Bundle configuration and provider-specific platforms[HTTP Clients](docs/http-clients.md)Advanced HTTP configuration[Logging](docs/logging.md)Debug and monitoring setup[Advanced Usage](docs/advanced-usage.md)Complex features and patterns[Security](docs/security.md)Data protection and sanitization[API Reference](docs/api-reference.md)Complete API documentation[Audio](docs/audio.md)Speech synthesis and transcription[Interactive Examples](docs/examples.md)Live examples with real APIs✨ Key Features
--------------

[](#-key-features)

- **🔌 Framework Agnostic** - No dependencies on Symfony or other frameworks
- **🛡️ Security First** - Built-in data sanitization and attribute-based protection
- **🎯 Type Safe** - Strongly-typed results and prompt value objects
- **🌐 Multi-Provider** - OpenAI, Anthropic, Gemini support with flexible configuration
- **🎭 Capabilities** - Models declare supported features (vision, tools, audio, streaming, reasoning)
- **⚡ Performance** - Built-in rate limiting and token estimation with exponential backoff
- **📝 Rich Prompts** - Parameterized prompts and conversation management
- **🎵 Audio Support** - Text-to-speech, transcription, and translation with multiple formats
- **🔄 Streaming** - Real-time response streaming support

🏗️ Architecture
---------------

[](#️-architecture)

```
Platform → Providers → Models → Clients → AI APIs
    ↓
Results ← Security ← Capabilities ← Response

```

- **Platform**: Main entry point for AI operations
- **Providers**: Manage models for each AI service (OpenAI, Anthropic, Gemini)
- **Models**: Individual AI models with declared capabilities
- **Clients**: Handle API communication with rate limiting
- **Results**: Type-safe responses (`TextResult`, `BinaryResult`, `StreamResult`, `ObjectResult`, `ToolCallResult`)

🎨 Usage Patterns
----------------

[](#-usage-patterns)

### Simple Text Generation

[](#simple-text-generation)

```
$result = $platform->ask('Explain AI');
echo $result->getContent(); // string
print_r($result->getMetadata()); // usage, model info, etc.
```

### Parameterized Prompts

[](#parameterized-prompts)

```
$template = UserPrompt::create('Hello {{name}}, tell me about {{topic}}');
$prompt = $template->withParameters([
    'name' => 'Alice',
    'topic' => 'machine learning'
]);

// Use ask() method with prompt objects
$result = $platform->ask($prompt);
```

### Conversations with Context

[](#conversations-with-context)

```
$conversation = Conversation::withSystem(
    UserPrompt::create('What is quantum computing?'),
    SystemPrompt::create('You are a helpful physics expert')
);

// ask() method supports Conversation objects
$result = $platform->ask($conversation, 'claude-sonnet-4');
```

### Automatic Data Protection

[](#automatic-data-protection)

```
// Sensitive data is automatically sanitized
$prompt = UserPrompt::create('My email is john@example.com');
// Sent to AI as: "My email is [REDACTED_EMAIL]"
$result = $platform->ask($prompt);

// Disable sanitization if needed
$platform = new Platform([$client], enableSanitization: false);
```

🔧 Requirements
--------------

[](#-requirements)

- **PHP ^8.3**
- PSR-18 HTTP Client (Symfony HTTP Client included)
- PSR-7 HTTP Messages (nyholm/psr7 included)
- PSR-3 Logger (optional)

🎵 Audio Features
----------------

[](#-audio-features)

```
use Lingoda\AiSdk\Audio\OpenAI\AudioOptions;

// Text-to-Speech
$options = AudioOptions::textToSpeech(
    model: AudioSpeechModel::TTS_1,
    voice: AudioSpeechVoice::NOVA,
    format: AudioSpeechFormat::MP3
);
$audioResult = $platform->textToSpeech('Hello world', $options);
file_put_contents('speech.mp3', $audioResult->getContent());

// Speech-to-Text
$transcription = $platform->transcribeAudio('audio.mp3', $transcriptionOptions);
echo $transcription->getContent(); // "Hello world"

// Translation to English
$translation = $platform->translateAudio('spanish-audio.mp3', $translationOptions);
```

📦 Installation
--------------

[](#-installation)

```
composer require lingoda/ai-sdk
```

🤖 Supported Models
------------------

[](#-supported-models)

**OpenAI Models:**

- GPT-5 series: `gpt-5`, `gpt-5-mini`, `gpt-5-nano` (latest)
- GPT-4.1 series: `gpt-4.1`, `gpt-4.1-mini`, `gpt-4.1-nano` (1M context)
- GPT-4o series: `gpt-4o`, `gpt-4o-mini` (128K context)
- Audio models: `whisper-1`, `tts-1`, `tts-1-hd`

**Anthropic Models:**

- Claude 4.1: `claude-opus-4-1-20250805`
- Claude 4.0: `claude-opus-4`, `claude-sonnet-4`
- Claude 3.7: `claude-3-7-sonnet`
- Claude 3.5: `claude-3-5-haiku`

**Google Gemini Models:**

- Gemini 2.5: `gemini-2.5-pro`, `gemini-2.5-flash` (1M context)

🚦 Quick Test
------------

[](#-quick-test)

Run interactive examples to test the SDK:

```
# Offline examples (no API keys needed)
php docs/usage-example.php

# With OpenAI
OPENAI_API_KEY=your-key php docs/usage-example.php

# Multiple providers
OPENAI_API_KEY=sk-proj-... \
ANTHROPIC_API_KEY=sk-ant-... \
GEMINI_API_KEY=AIza... \
php docs/usage-example.php
```

🛠️ Development
--------------

[](#️-development)

```
# Install dependencies
composer install

# Run tests
vendor/bin/phpunit

# Static analysis
vendor/bin/phpstan analyse

# Code style
vendor/bin/ecs check --fix
```

🤝 Contributing
--------------

[](#-contributing)

1. Fork the repository
2. Create a feature branch
3. Add tests for your changes
4. Ensure all tests pass
5. Submit a pull request

📄 License
---------

[](#-license)

MIT License. See [LICENSE](LICENSE) for details.

---

**Get Started**: [Installation Guide](docs/installation.md) | **Try Examples**: [Interactive Examples](docs/examples.md) | **Join Discussion**: [GitHub Issues](https://github.com/lingoda/ai-sdk/issues)

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance89

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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

Every ~42 days

Recently: every ~52 days

Total

6

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30c0431d32647bf0f71a0dbb9d2c6b9e71f18ae88124366d07a3305dc2505114?d=identicon)[balazscsaba2006](/maintainers/balazscsaba2006)

---

Top Contributors

[![balazscsaba2006](https://avatars.githubusercontent.com/u/1202594?v=4)](https://github.com/balazscsaba2006 "balazscsaba2006 (11 commits)")

---

Tags

aiopenaimachine learningGeminiclaudeanthropicChatGpt

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lingoda-ai-sdk/health.svg)

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[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)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[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)
