jazz-max/yandex-ai-laravel
Composer 安装命令:
composer require jazz-max/yandex-ai-laravel
包简介
Laravel SDK for Yandex AI Studio — Responses API, Vision OCR, Embeddings
README 文档
README
Laravel SDK for Yandex AI Studio — text generation (Responses API), Vision OCR, and Embeddings.
Installation
composer require jazz-max/yandex-ai-laravel
Publish config:
php artisan vendor:publish --tag=yandex-ai-config
Add to .env:
YANDEX_AI_API_KEY=your-api-key YANDEX_AI_FOLDER_ID=your-folder-id
Quick Start
use JazzMax\YandexAi\Facades\YandexAi; // Text generation $response = YandexAi::responses()->create([ 'model' => 'yandexgpt-5-lite', 'instructions' => 'You are a helpful assistant.', 'input' => 'Hello!', ]); echo $response->text; // OCR $result = YandexAi::vision()->recognizeText( file_get_contents('photo.jpg') ); echo $result->text(); // Embeddings $vector = YandexAi::embeddings()->embedQuery('search query');
API Clients
Responses API
$client = YandexAi::responses();
| Method | Description |
|---|---|
create(array $params) |
Text generation |
stream(array $params, Closure $onDelta) |
Streaming generation |
continue(string $prevId, array $input) |
Multi-turn dialog |
submitToolOutput(string $prevId, string $callId, string $output) |
Function calling follow-up |
createBackground(array $params) |
Background async task |
retrieve(string $id) |
Get background task status |
poll(string $id, int $timeout) |
Poll until complete |
formatModel(string $model) |
Add gpt://folder_id/ prefix |
supportsReasoning(string $model) |
Check Pro model |
calculateCostRub(...) |
Cost in RUB |
Vision OCR
$client = YandexAi::vision();
| Method | Description |
|---|---|
recognizeText(string $data, OcrModel $model) |
Sync image OCR |
recognizeDocument(string $pdfData, OcrModel $model) |
Async PDF OCR |
Available models (OcrModel enum):
Page— general textPageColumnSort— multi-column layoutsHandwritten— handwriting (ru/en only)Table— table extraction (ru/en only)Markdown/MathMarkdown— structured outputPassport— Russian passport fieldsDriverLicenseFront/DriverLicenseBack— driver licenseVehicleRegistrationFront/VehicleRegistrationBack— vehicle registrationLicensePlates— license plate numbers
Embeddings
$client = YandexAi::embeddings();
| Method | Description |
|---|---|
embedDocument(string $text) |
Document vector (for indexing) |
embedQuery(string $text) |
Query vector (for searching) |
cosineSimilarity(array $a, array $b) |
Vector similarity |
Function Calling
use JazzMax\YandexAi\Tools\FunctionTool; $tools = [ FunctionTool::make('get_weather', 'Get weather for a city.', [ 'type' => 'object', 'properties' => [ 'city' => ['type' => 'string', 'description' => 'City name'], ], 'required' => ['city'], ]), ]; $response = YandexAi::responses()->create([ 'model' => 'yandexgpt-5-lite', 'input' => 'Weather in Moscow?', 'tools' => $tools, ]); if ($response->hasFunctionCall()) { $call = $response->functionCall; // Check if function call was extracted from text (fallback parser) if ($response->isFallbackFunctionCall) { // Model returned tool call as text — consider shortening tool descriptions } // Execute function, then submit result: $final = YandexAi::responses()->submitToolOutput( $response->id, $call['id'], '{"temp": 15}' ); }
Note: Yandex models sometimes return function calls as plain text instead of proper
function_callitems. The SDK includes a fallback parser that automatically extracts them. Check$response->isFallbackFunctionCallto detect this. Disable viaYANDEX_AI_FUNCTION_CALL_FALLBACK=false.
Known Gotchas
See docs/GOTCHAS.md for production-tested pitfalls:
- Tool descriptions must be short (< 15 words, English) or models write calls as text
- Never use empty
properties— always include a dummy property - Auth header is
Api-Key, notBearer - Models require URI format:
gpt://folder_id/model - Only
gemma-3-27b-itsupports images, and only via base64 - Prices are RUB per 1000 tokens, not USD per 1M
- Cached tokens cost 50% of prompt price
- Async OCR returns JSON Lines, not JSON array
handwritten/tablemodels only support ru/en
Configuration
All options in config/yandex-ai.php:
| Key | Default | Description |
|---|---|---|
api_key |
— | API key |
folder_id |
— | Cloud folder ID |
base_url |
https://ai.api.cloud.yandex.net/v1 |
API base URL |
ocr_base_url |
https://ocr.api.cloud.yandex.net/ocr/v1 |
OCR API URL |
timeout |
120 |
HTTP timeout (seconds) |
proxy |
null |
HTTP proxy URL |
default_model |
yandexgpt-5-lite |
Default generation model |
pricing |
— | RUB per 1000 tokens per model |
ocr_pricing |
— | RUB per image per OCR model |
Examples
See examples/ directory:
simple_request.php— basic generationdialog.php— multi-turn conversationstreaming.php— streaming outputfunction_calling.php— tool usereasoning.php— Pro model reasoningvision_with_gpt.php— image analysisvision_ocr.php— OCR recognitionvision_ocr_async.php— async PDF OCRembeddings.php— semantic searchbackground.php— background tasks
Claude Code Skill
If you use Claude Code, install the companion skill (jazz-max/yandex-ai-laravel-skill) for expert guidance on this SDK:
npx skills add jazz-max/yandex-ai-laravel-skill
The skill provides full API reference, code examples, and knows all Yandex API gotchas.
Example prompts that activate the skill:
Add YandexGPT text generation to my Laravel app with streaming support
Build a document recognition feature using Yandex Vision OCR for passports and driver licenses
Implement semantic search with Yandex Embeddings and cosine similarity
Set up function calling with Yandex AI Studio in my Laravel project
Подключи Yandex AI Studio к моему Laravel-проекту и сделай artisan-команду для генерации текста через YandexGPT
Добавь распознавание документов через Yandex Vision OCR с поддержкой паспортов и водительских удостоверений
Реализуй семантический поиск по базе статей с помощью Yandex Embeddings
License
MIT
jazz-max/yandex-ai-laravel 适用场景与选型建议
jazz-max/yandex-ai-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「OCR」 「laravel」 「yandex」 「ai」 「vision」 「gpt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jazz-max/yandex-ai-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jazz-max/yandex-ai-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jazz-max/yandex-ai-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The flysystem adapter for yandex disk rest api.
Easy and complete YooKassa (previously Yandex Checkout) integration for Laravel
Scrapping TOP10 Yandex Market Reviews
Yandex map
The Best Image Ocr SDK For BAT.
The Best Image Ocr SDK For BAT.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-12