ai-startup
CHAPTER 53 / 100
읽기 약 2분
FUNCTION
사용량 기반 과금: AI API 호출 단위
핵심 개념
metered billing·credits·overage·실전 모델 — AI 비용 변동 대응.
본문
사용량 기반 vs 정액제
[정액제 (Subscription)]
- 월 $19 → 무제한
- 비용 예측 가능
- 사용 적은 사용자에게 손해
[사용량 기반 (Metered)]
- $0.01 per API call
- 사용한 만큼만
- 변동성 있음
[하이브리드 (가장 인기)]
- $19/mo + 1000 calls 포함
- 추가 시 $0.005/call
- 최선의 균형Stripe Metered Billing
// 1. Stripe — Metered Price 생성
// Dashboard → Products → Add Price → Usage type: Metered
// 2. Subscription 생성 시
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{ price: 'price_metered_xxx' }],
});
// 3. 사용량 보고 (매일 또는 실시간)
await stripe.subscriptionItems.createUsageRecord(
subscription.items.data[0].id,
{
quantity: 100, // 100 API calls
timestamp: Math.floor(Date.now() / 1000),
action: 'increment', // 또는 'set' (절대값)
},
);
// → 월말에 자동으로 청구 금액 계산
// → 총 사용량 × price = 청구Credits 시스템 (자체 구현)
// 사용자가 미리 충전
async function purchaseCredits(userId: string, amount: number) {
// Stripe Checkout (one-time)
const session = await stripe.checkout.sessions.create({
mode: 'payment', // subscription 아님
line_items: [{
price_data: {
currency: 'usd',
product_data: { name: `${amount} credits` },
unit_amount: amount * 100, // $1 = 100 credits
},
quantity: 1,
}],
success_url: `${URL}/credits?added=${amount}`,
});
return session.url;
}
// 결제 webhook
case 'checkout.session.completed': {
const session = event.data.object;
const credits = parseInt(session.metadata.credits);
await db.user.update({
where: { id: userId },
data: { credits: { increment: credits } },
});
}
// AI 사용 시 차감
async function useCredits(userId: string, cost: number) {
const result = await db.user.update({
where: { id: userId, credits: { gte: cost } },
data: { credits: { decrement: cost } },
});
if (!result) throw new Error('Insufficient credits');
}토큰 사용량 → 가격 계산
const PRICING = {
'claude-sonnet-4-6': { input: 3, output: 15 }, // per 1M tokens (USD)
'claude-opus-4-7': { input: 15, output: 75 },
'gpt-4o': { input: 2.5, output: 10 },
'gemini-2.5-flash': { input: 0.10, output: 0.40 },
};
function calculateCost(model: string, inputTokens: number, outputTokens: number) {
const p = PRICING[model];
return (inputTokens / 1_000_000) * p.input + (outputTokens / 1_000_000) * p.output;
}
// 마진 추가
function calculateUserPrice(model: string, in_: number, out: number) {
const cost = calculateCost(model, in_, out);
return cost * 3; // 3x 마진 (안전·운영·이익)
}가격 페이지 — Hybrid 표시
function PricingHybrid() {
return (
<Card>
<h3>Pro</h3>
<p className="text-3xl">$19/mo</p>
<p className="text-sm">+ AI usage</p>
<ul>
<li>✓ 1,000 credits 포함</li>
<li>✓ 추가 credits: $0.005 each</li>
<li>✓ Spending limit 설정 가능</li>
</ul>
</Card>
);
}
// Spending Limit
async function setSpendingLimit(userId: string, limitUSD: number) {
await db.user.update({
where: { id: userId },
data: { monthly_limit_cents: limitUSD * 100 },
});
}
// 한도 도달 시 — API 차단 + 알림사용량 알림
// 매일 cron
async function checkUsageAlerts() {
const users = await db.user.findMany({ where: { plan: { not: 'free' } } });
for (const user of users) {
const usagePercent = (user.current_period_usage / user.monthly_limit) * 100;
if (usagePercent >= 90 && !user.notified_90) {
await sendEmail({
to: user.email,
subject: '사용량 90% 도달',
template: 'usage_warning',
data: { percent: 90, remaining: user.monthly_limit - user.current_period_usage },
});
await db.user.update({ where: { id: user.id }, data: { notified_90: true } });
}
// 80%, 90%, 100% 단계
}
}다음 챕터
CH.54 "가격 실험: A/B 테스트로 최적 가격".
AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
무료
월 $0 — 검증·시작 단계
사용량 기반 과금을 무료 도구만으로 시작하는 방법을 알려줘.
소자본
월 $20~50 — MVP·초기 운영
월 $20~50 예산으로 사용량 기반 과금을 검증·MVP 단계까지 진행하는 전략은?
프로덕션
월 $200~500 — 성장 단계
사용량 기반 과금을 프로덕션 단계로 확장할 때 필요한 도구·운영 체계는?
스택
풀스택 — 도구 조합 분석
2026년 사용량 기반 과금 관련 도구 5개를 조합한 추천 스택을 알려줘.
⭐ 이것만 기억하세요
사용량 기반 과금: AI API 호출 단위는 이 3가지만 확실히 잡으세요
1.하이브리드 (정액 + 사용량) = 1인 창업 정답
2.Credits 시스템 = 단순·예측 가능
3.사용량 80%/90% 알림 = 빌 쇼크 방지
공유하기
진행도 53 / 100