jonaspauleta / laravel-ai-moonshot
Moonshot AI (Kimi) provider for the Laravel AI SDK.
Package info
github.com/jonaspauleta/laravel-ai-moonshot
pkg:composer/jonaspauleta/laravel-ai-moonshot
Requires
- php: ^8.5
- illuminate/contracts: ^11.0 || ^12.0 || ^13.0
- illuminate/http: ^11.0 || ^12.0 || ^13.0
- illuminate/support: ^11.0 || ^12.0 || ^13.0
- laravel/ai: ^0.6.3
Requires (Dev)
- driftingly/rector-laravel: ^2.2
- larastan/larastan: ^3.0
- laravel/pint: ^1.25
- orchestra/testbench: ^9.0 || ^10.0 || ^11.0
- pestphp/pest: ^3.0 || ^4.0
- pestphp/pest-plugin-laravel: ^3.0 || ^4.0
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- rector/rector: ^2.2
README
Moonshot AI (Kimi K2) provider for the Laravel AI SDK.
Moonshot's API is OpenAI-compatible (POST https://api.moonshot.ai/v1/chat/completions), so this driver supports text generation, streaming, tool calling, and thinking-mode reasoning (reasoning_content deltas are surfaced as Laravel AI SDK ReasoningStart / ReasoningDelta / ReasoningEnd stream events).
Requirements
- PHP 8.5+
laravel/ai^0.6.3
Install
composer require jonaspauleta/laravel-ai-moonshot
The service provider auto-registers via Laravel package discovery.
Configure
Set the API key:
MOONSHOT_API_KEY=sk-...
In config/ai.php:
'providers' => [ // ... 'moonshot' => [ 'driver' => 'moonshot', 'name' => 'moonshot', 'key' => env('MOONSHOT_API_KEY'), // Optional per-tier model overrides — defaults shown below. 'models' => [ 'text' => [ 'default' => 'kimi-k2.6', 'cheapest' => 'kimi-k2-0905-preview', 'smartest' => 'kimi-k2-thinking', ], ], ], ],
Usage
use App\Ai\Agents\RaceEngineer; use Illuminate\Broadcasting\PrivateChannel; $agent = new RaceEngineer($user); $agent ->forUser($user) ->broadcastOnQueue( 'What is the best setup for the Nordschleife?', new PrivateChannel("agent.{$user->id}.{$requestId}"), provider: 'moonshot', model: 'kimi-k2.6', );
Thinking mode
Kimi's kimi-k2.6 supports persistent reasoning across turns with thinking.keep = all. Return the payload from your agent's providerOptions() and the gateway merges it into the chat-completions body unchanged:
public function providerOptions(Lab|string $provider): array { return $provider === 'moonshot' ? ['thinking' => ['type' => 'enabled', 'keep' => 'all']] : []; }
reasoning_content deltas then surface as ReasoningStart / ReasoningDelta / ReasoningEnd on the broadcast channel, before text streaming begins.
License
MIT © João Paulo Santos