Initial commit: Runware-powered content generator foundation
Laravel app with a cost-tracked Runware.ai integration (image, video, text generation), a hard monthly EUR budget cap with live USD/EUR FX conversion, and a locally-maintained model/pricing table since Runware's model-search API doesn't expose pricing.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Runware;
|
||||
|
||||
use App\Models\RunwareModel;
|
||||
|
||||
/**
|
||||
* Pre-flight cost estimation used by BudgetGuard before a Runware call is
|
||||
* made. Deliberately conservative — the real cost is always reconciled
|
||||
* afterward from Runware's response `cost` field (or, for text, `usage.cost`).
|
||||
*/
|
||||
class CostEstimator
|
||||
{
|
||||
protected const DEFAULT_VIDEO_DURATION_SECONDS = 5;
|
||||
|
||||
protected const DEFAULT_TEXT_TOKEN_BUDGET = 2048;
|
||||
|
||||
public function estimateUsd(RunwareModel $model, array $params): float
|
||||
{
|
||||
return match ($model->unit) {
|
||||
'per_image' => (float) $model->price_usd * (int) ($params['numberResults'] ?? 1),
|
||||
'per_second' => (float) $model->price_usd * (int) ($params['duration'] ?? self::DEFAULT_VIDEO_DURATION_SECONDS),
|
||||
'per_million_tokens' => (float) $model->price_usd
|
||||
* (((int) ($params['max_completion_tokens'] ?? self::DEFAULT_TEXT_TOKEN_BUDGET)) / 1_000_000),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user