PHPackages                             timkley/denk - 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. timkley/denk

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

timkley/denk
============

OpenAI helpers

0.5.2(3mo ago)11.7k↓50%MITPHPPHP ^8.4|^8.5

Since Nov 29Pushed 3mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (11)Versions (13)Used By (0)

Denk – a small helper package to work with the OpenAI API
=========================================================

[](#denk--a-small-helper-package-to-work-with-the-openai-api)

The package name is derived from the German word "denken" which means "to think".

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

[](#installation)

```
composer require timkley/denk
```

How to use
----------

[](#how-to-use)

Make sure that you have an OpenAI API key. You can get one [here](https://platform.openai.com/signup).

### Initialization

[](#initialization)

#### Using Laravel

[](#using-laravel)

The package comes with a service provider that will automatically register the OpenAI client. You can use the `Denk` facade to access the service.

Make sure to publish the configuration file to set your API key and/or change the API url.

```
php artisan vendor:publish --tag=config --provider="Denk\DenkServiceProvider"
```

After that, you can use the `Denk` facade to access the service like this:

```
use Denk\Facades\Denk;

$text = Denk::text()->prompt('Once upon a time')->generate();
```

#### Manually or non-Laravel projects

[](#manually-or-non-laravel-projects)

To initialize the service, you need create an OpenAI client and pass it to the DenkService.

```
use Denk\DenkService;
use OpenAI;

$client = OpenAI::client('your-api-key');
$denk = new DenkService($client);
```

### Generating text

[](#generating-text)

```
use Denk\DenkService;
use OpenAI;

$client = OpenAI::client('your-api-key');
$denk = new DenkService($client);

// using only a simple prompt
$text = $denk->text()->prompt('Once upon a time')->generate();

// Manually provide messages
use Denk\ValueObjects\DeveloperMessage;
use Denk\ValueObjects\UserMessage;
use Denk\ValueObjects\AssistantMessage;

$text = $denk->text()
    ->messages([
        new DeveloperMessage('Write as a pirate'),
        new UserMessage('Once upon a time'),
    ])
    ->generate();

// Generate a streamed response
$stream = $denk->text()
    ->prompt('Write a long story about a pirate')
    ->generateStreamed();

// Iterate over the stream to get chunks of the response as they arrive
foreach ($stream as $response) {
    echo $response->choices[0]->delta->content;
}
```

#### Available models

[](#available-models)

- `gpt-4o-mini` (default)
- `gpt-4o`
- `gpt-4-turbo`
- `gpt-4`
- `gpt-3.5-turbo`

#### Temperature

[](#temperature)

You can control the randomness of the response by setting the temperature:

```
$text = $denk->text()
    ->prompt('Once upon a time')
    ->temperature(0.5) // Between 0.0 and 2.0, default is 1.0
    ->generate();
```

### Generating JSON

[](#generating-json)

To generate [Structured Output](https://platform.openai.com/docs/guides/structured-outputs), you can use the `json()` method. Set the properties of the JSON object and provide a prompt, additionally you may also set a system prompt.

```
use Denk\DenkService;
use OpenAI;

$client = OpenAI::client('your-api-key');
$denk = new DenkService($client);

$json = $denk->json()
    ->properties([
        'title' => [
            'type' => 'string',
            'description' => 'The title of the story',
        ],
        'story' => [
            'type' => 'string',
            'description' => 'The story itself',
        ],
    ])
    ->prompt('Write a store about Chewbacca winning a game against Han Solo')
    ->generate();
```

#### Available models

[](#available-models-1)

- `gpt-4o-mini` (default)
- `gpt-4o`

#### Temperature

[](#temperature-1)

You can control the randomness of the response by setting the temperature:

```
$json = $denk->json()
    ->properties([...])
    ->prompt('...')
    ->temperature(0.5) // Between 0.0 and 2.0, default is 1.0
    ->generate();
```

### Generating Images

[](#generating-images)

To generate images, you can use the `image()` method. Set the properties of the image and provide a prompt.

```
use Denk\DenkService;
use OpenAI;

$client = OpenAI::client('your-api-key');
$denk = new DenkService($client);

$image = $denk->image()
    ->prompt('A beautiful sunset over the ocean')
    ->size('square') // or '1024x1024'
    ->quality('standard')
    ->model('dall-e-3') // optional, dall-e-3 is default
    ->generate();

// Returns the URL of the generated image
```

#### Available image sizes

[](#available-image-sizes)

- `1024x1024` (square)
- `1792x1024` (landscape)
- `1024x1792` (portrait)

Or use the convenience aliases:

- `square`
- `landscape`
- `portrait`

#### Available image qualities

[](#available-image-qualities)

- `standard`
- `hd`

#### Available image models

[](#available-image-models)

- `dall-e-3` (default)
- `dall-e-2`

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance79

Regular maintenance activity

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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 ~38 days

Recently: every ~68 days

Total

12

Last Release

111d ago

PHP version history (3 changes)0.0.1PHP ^8.3

0.2.0PHP ^8.3|^8.4

0.5.2PHP ^8.4|^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/8be5d213cbc7bca807d04aa12897c375173c29f1a6bd4f18a83cfd5de9654650?d=identicon)[timkley](/maintainers/timkley)

---

Top Contributors

[![timkley](https://avatars.githubusercontent.com/u/6104339?v=4)](https://github.com/timkley "timkley (18 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/timkley-denk/health.svg)

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

###  Alternatives

[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.5M178](/packages/illuminate-broadcasting)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[illuminate/redis

The Illuminate Redis package.

8314.0M314](/packages/illuminate-redis)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)

PHPackages © 2026

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