PHPackages                             eseperio/yii2-openai-responses - 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. eseperio/yii2-openai-responses

ActiveYii2-extension[API Development](/categories/api)

eseperio/yii2-openai-responses
==============================

Yii2 component wrapper around openai-php client responses API.

1.0.0(8mo ago)011MITPHPPHP &gt;=8.1

Since Aug 17Pushed 6mo agoCompare

[ Source](https://github.com/Eseperio/yii2-openai-responses)[ Packagist](https://packagist.org/packages/eseperio/yii2-openai-responses)[ RSS](/packages/eseperio-yii2-openai-responses/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

yii2-openai-responses
=====================

[](#yii2-openai-responses)

Easily integrate AI features into any Yii2 application. This library provides a drop‑in component to interact with OpenAI's Responses API.

Wrapper for the [openai-php/client](https://github.com/openai-php/client) focused on the Responses API.

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

[](#installation)

```
composer require eseperio/yii2-openai-responses
```

Configuration
-------------

[](#configuration)

Register the component in the application configuration:

```
return [
    'components' => [
        'openai' => [
            'class' => eseperio\openai\responses\OpenAiComponent::class,
            'apiKey' => 'YOUR_API_KEY',
            'model' => eseperio\openai\responses\enums\OpenAiModel::GPT_4_1_MINI,
            // optional defaults
            'instructions' => 'Always answer politely.',
            'instructionsPolicy' => eseperio\openai\responses\OpenAiComponent::INSTRUCTIONS_COMPLEMENTARY,
        ],
    ],
];
```

`apiKey` and `instructions` are write-only properties to avoid exposing sensitive values.

Available OpenAI models are exposed through the `OpenAiModel` enum for convenient access.

Usage
-----

[](#usage)

### Basic request

[](#basic-request)

```
$content = Yii::$app->openai->ask('Explain gravity.');
```

### With instructions and metadata

[](#with-instructions-and-metadata)

```
$content = Yii::$app->openai->ask(
    'Explain gravity.',
    'Provide examples',
    ['topic' => 'physics']
);
```

### Handling instructions

[](#handling-instructions)

`OpenAiComponent` supports a policy for default instructions:

- **required** – user instructions are ignored. If the caller provides instructions, an exception is thrown.
- **complementary** – user instructions are appended to the default ones.
- **optional** – user instructions override the defaults.

### Creating custom requests

[](#creating-custom-requests)

To override default configuration for a single call, create an `AskRequest` model:

```
$request = Yii::$app->openai->createAskRequest();
$request->model = eseperio\\openai\\responses\\enums\\OpenAiModel::GPT_4_1;
$request->input = 'Explain gravity.';
$request->instructions = 'Use simple terms.';

$content = Yii::$app->openai->ask($request);
```

The model is validated before sending the request. If validation fails an exception is thrown.

### Retrieve last response

[](#retrieve-last-response)

```
$response = Yii::$app->openai->getLastResponse();
```

The component returns only the text content of the first item in the response. The full response object can be obtained via `getLastResponse()`.

Tests
-----

[](#tests)

Functional tests are included. Run them with:

```
vendor/bin/codecept run functional
```

License
-------

[](#license)

MIT

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance65

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

259d ago

### Community

Maintainers

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

---

Top Contributors

[![Eseperio](https://avatars.githubusercontent.com/u/5459366?v=4)](https://github.com/Eseperio "Eseperio (16 commits)")

---

Tags

openaiyii2responses

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/eseperio-yii2-openai-responses/health.svg)

```
[![Health](https://phpackages.com/badges/eseperio-yii2-openai-responses/health.svg)](https://phpackages.com/packages/eseperio-yii2-openai-responses)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[theodo-group/llphant

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

1.5k311.5k5](/packages/theodo-group-llphant)[dotzero/yii2-amocrm

Расширение для Yii Framework 2 реализующее клиент для работы с API amoCRM

1639.7k](/packages/dotzero-yii2-amocrm)[conquer/services

Yii2 soap wsdl web services

1632.5k](/packages/conquer-services)[skeeks/yii2-google-api

Component for work with google api based on google/apiclient

1243.1k1](/packages/skeeks-yii2-google-api)[apexwire/yii2-restclient

Tools to use API as ActiveRecord for Yii2

143.5k](/packages/apexwire-yii2-restclient)

PHPackages © 2026

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