Chapter 3: Building LLM Platforms
Platform Architecture
Cost Allocation
class CostAllocator:
def __init__(self, pricing: dict):
self.pricing = pricing
self.usage = {}
def track_usage(self, team_id: str, model: str, tokens: int):
"""Track usage by team."""
if team_id not in self.usage:
self.usage[team_id] = {}
if model not in self.usage[team_id]:
self.usage[team_id][model] = 0
self.usage[team_id][model] += tokens
def calculate_cost(self, team_id: str) -> dict:
"""Calculate cost for a team."""
team_usage = self.usage.get(team_id, {})
costs = {}
total = 0
for model, tokens in team_usage.items():
cost = (tokens / 1000) * self.pricing[model]
costs[model] = cost
total += cost
return {"breakdown": costs, "total": total}
def generate_report(self) -> dict:
"""Generate monthly cost report."""
report = {}
for team_id in self.usage:
report[team_id] = self.calculate_cost(team_id)
return report
Governance Framework
| Aspect | Policy | Implementation |
|---|---|---|
| Access Control | Role-based access | IAM, API keys |
| Usage Limits | Quotas per team | Rate limiting, budgets |
| Model Access | Approved models only | Model allowlist |
| Data Handling | PII restrictions | Input/output filtering |
| Audit | All interactions logged | Centralized logging |
Next: Module 14 Quiz