PHPackages                             ketchalegend/laravel-together-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. [API Development](/categories/api)
4. /
5. ketchalegend/laravel-together-ai

AbandonedArchivedLibrary[API Development](/categories/api)

ketchalegend/laravel-together-ai
================================

A Laravel package for integrating with Together AI

v1.6.0(1y ago)218[1 issues](https://github.com/ketchalegend/laravel-together-ai/issues)MITPHPPHP ^7.3|^8.0

Since Sep 7Pushed 1y ago2 watchersCompare

[ Source](https://github.com/ketchalegend/laravel-together-ai)[ Packagist](https://packagist.org/packages/ketchalegend/laravel-together-ai)[ RSS](/packages/ketchalegend-laravel-together-ai/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (8)Used By (0)

Laravel Together AI
===================

[](#laravel-together-ai)

This package provides an easy integration with the Together AI API for your Laravel application.

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

[](#installation)

Install the package via Composer:

```
composer require ketchalegend/laravel-together-ai
```

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="ketchalegend\LaravelTogetherAI\TogetherAIServiceProvider" --tag="together-ai-config"
```

Then, add your Together AI API key to your `.env` file:

```
TOGETHER_AI_API_KEY=your-api-key-here

```

Usage
-----

[](#usage)

Here are various examples of how to use the Laravel Together AI package:

```
use ketchalegend\LaravelTogetherAI\Facades\TogetherAI;

// Basic chat completion
$response = TogetherAI::chat()->create([
    'messages' => [
        ['role' => 'user', 'content' => 'Hello, how are you?']
    ]
]);

// Chat completion with custom parameters
$response = TogetherAI::chat()->create([
    'messages' => [
        ['role' => 'user', 'content' => 'Explain quantum computing in simple terms.']
    ],
    'temperature' => 0.8,
    'max_tokens' => 150
]);

// Chat with system message and multiple user messages
$response = TogetherAI::chat()->create([
    'messages' => [
        ['role' => 'system', 'content' => 'You are a helpful assistant specializing in technology.'],
        ['role' => 'user', 'content' => 'What is cloud computing?'],
        ['role' => 'assistant', 'content' => 'Cloud computing is a technology that allows users to access and use computing resources over the internet instead of on their local computer.'],
        ['role' => 'user', 'content' => 'What are its main benefits?']
    ]
]);

// Streamed chat completion
$stream = TogetherAI::chat()->create([
    'messages' => [
        ['role' => 'user', 'content' => 'Tell me a short story about a robot.']
    ],
    'stream' => true
]);

foreach ($stream as $chunk) {
    if (isset($chunk['done']) && $chunk['done']) {
        echo "Story finished.\n";
        break;
    }
    echo $chunk['choices'][0]['delta']['content'] ?? '';
}

// Chat completion with function calling (if supported by Together AI)
$functions = [
    [
        'name' => 'get_current_weather',
        'description' => 'Get the current weather in a given location',
        'parameters' => [
            'type' => 'object',
            'properties' => [
                'location' => [
                    'type' => 'string',
                    'description' => 'The city and state, e.g. San Francisco, CA',
                ],
                'unit' => ['type' => 'string', 'enum' => ['celsius', 'fahrenheit']],
            ],
            'required' => ['location'],
        ],
    ]
];

$response = TogetherAI::chat()->create([
    'messages' => [
        ['role' => 'user', 'content' => 'What\'s the weather like in New York?']
    ],
    'functions' => $functions,
    'function_call' => 'auto'
]);

// Handle the response
if (isset($response['choices'][0]['function_call'])) {
    $functionCall = $response['choices'][0]['function_call'];
    // Process the function call...
} else {
    echo $response['choices'][0]['message']['content'];
}

// Error handling
try {
    $response = TogetherAI::chat()->create([
        'messages' => [
            ['role' => 'user', 'content' => 'Generate a very long response.']
        ],
        'max_tokens' => 10000 // Assuming this exceeds the API's limit
    ]);
} catch (\Exception $e) {
    echo "An error occurred: " . $e->getMessage();
}

// Using custom headers and base URI

$client = TogetherAI::factory()
    ->withApiKey($newApiKey)
    ->withBaseUri($newBaseUri)
    ->withHttpHeader('Custom-Header', 'Custom-Value');
    ->make();

$response = $client->chat()->create([
    'messages' => [
        ['role' => 'user', 'content' => 'Hello with custom configuration!']
    ]
]);
```

These examples demonstrate:

1. Basic chat completion
2. Chat with custom parameters
3. Multi-turn conversations with system and assistant messages
4. Streamed responses
5. Function calling
6. Simplified input for user messages
7. Error handling

Remember to handle API responses and errors appropriately in your application. The actual structure of the response may vary depending on the Together AI API version and the specific model used.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance23

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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

Total

7

Last Release

663d ago

### Community

Maintainers

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

---

Top Contributors

[![ketchalegend](https://avatars.githubusercontent.com/u/34584292?v=4)](https://github.com/ketchalegend "ketchalegend (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ketchalegend-laravel-together-ai/health.svg)

```
[![Health](https://phpackages.com/badges/ketchalegend-laravel-together-ai/health.svg)](https://phpackages.com/packages/ketchalegend-laravel-together-ai)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M47](/packages/tencentcloud-tencentcloud-sdk-php)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.7k1](/packages/jasara-php-amzn-selling-partner-api)

PHPackages © 2026

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