ApiGateway
API gateway infrastructure β pricing calculation + usage extraction (token policy evaluation lives in Core).
Statusβ
| Key | Value |
|---|---|
| Layer | core |
| Tier | L1 |
| Status | wip |
| Version | 0.9.0 |
| Price | Free (free) |
| Category | Infrastructure |
Overviewβ
Overviewβ
ApiGateway is the Layer 1 Core Plugin of multi-saas-kit. Token policy validation (ApiAccessKeyPolicyEvaluator) already lives in Core/Base/Security/ApiAccess, so this plugin focuses on the layer above: Pricing (cost calculation) + Usage (quantity extraction).
Core Componentsβ
PricingCalculator (Pure)β
- price_usd + unit + quantity β USD cost
calculate(priceUsd, unit, quantity),calculateFor(entry, quantity),calculateBreakdown(segments)- Standard units:
1m_chars,1m_tokens,1k_tokens,minute,second,hour,request - Unknown unit β
UnknownPricingUnitException - Configurable decimal precision (default 6)
UsageQuantityExtractor (Pure)β
- Per-service quantity extraction rules (config-based)
ttsβchar_countsttβaudio_duration_ms(withms_to_minutetransform)llmβinput_tokens(input) +output_tokens(output)- Adding a new service = config edit only
Interfacesβ
Projects implement PricingEntryInterface on their pricing Eloquent model and PricingLookupInterface on their lookup service.
Configuration (config/api-gateway.php)β
return [
'enabled' => env('PLG_API_GATEWAY_ENABLED', true),
'pricing' => [
'unit_divisors' => [
'1m_chars' => 1_000_000,
'1m_tokens' => 1_000_000,
'1k_tokens' => 1_000,
'minute' => 1,
'request' => 1,
],
'precision' => 6,
],
'usage' => [
'extractors' => [
'tts' => [['field' => 'char_count', 'unit_hint' => '1m_chars']],
'llm' => [
['field' => 'input_tokens', 'direction' => 'input', 'unit_hint' => '1m_tokens'],
['field' => 'output_tokens', 'direction' => 'output', 'unit_hint' => '1m_tokens'],
],
],
],
];
Usageβ
use App\Plugins\ApiGateway\Services\PricingCalculator;
use App\Plugins\ApiGateway\Services\UsageQuantityExtractor;
$calc = PricingCalculator::fromConfig(config('api-gateway.pricing'));
$cost = $calc->calculate(16.0, '1m_chars', 500_000); // $8.00
$ext = UsageQuantityExtractor::fromConfig(config('api-gateway.usage'));
$segments = $ext->extract('llm', ['input_tokens' => 1000, 'output_tokens' => 500]);
Originβ
Extracted from apis.how's ApiPricing::calculateCost() / unitDivisor() and ApiUsageLog payload structure. LiteLLMActualCostSynchronizer cost sync flow is planned for Phase 3.
Roadmap (Phase 3+)β
- Standard
ApiToken/ApiUsageLog/ApiPricingModel + Migration (opt-in) - Filament Resource (Token CRUD + Pricing editor + Usage Dashboard)
- ApiUsageAnalytics Plugin integration (Phase 3 Composite)
- LiteLLM-style actual cost sync adapter
Dependenciesβ
- Core/Base/Security/ApiAccess (
ApiAccessKeyPolicyEvaluator) - Plugin itself has no model dependency (Pure Service + Interface)
Licenseβ
MIT
Demosβ
- Platform κ΄λ¦¬μ ν¨λμμ λ©ν νμΈ π Login required
- μ¬μ© μμ (PHP)
π View on Plugin Store: store.codebase.how/plugins/api-gateway