訂閱制 API 使用指南
訂閱制讓你將某個 API Key 升級為付費方案,享有更高的 RPM(每分鐘請求數)、Token 配額上限,以及指定方案才能呼叫的獨家模型。
訂閱費用在訂閱當下從帳戶餘額(Credits)立即扣除,不收週期性自動扣款。配額依方案設定的週期(每日 / 每週 / 每月)自動重置。
查詢可用方案
公開端點,無需驗證,回傳所有啟用中的訂閱方案,包含價格、速率限制、Token 配額、可用模型清單。
/api/v1/plansResponse
[
{
"slug": "standard",
"priceUsd": 20,
"rpmLimit": 60,
"tokenLimit": 2000000, // null = unlimited
"tokenLimitPeriod": "day", // "5h" | "day" | "week" | "month"
"dailyPoints": 3700,
"newAccountDailyPoints": 500,
"newAccountCooldownHrs": 72,
"models": [
{ "modelId": "openai/gpt-4o", "basePoints": 15 },
{ "modelId": "anthropic/claude-sonnet-4", "basePoints": 25 }
]
}
]Example
curl https://bazaarlink.ai/api/v1/plans
訂閱 API Key
將指定 API Key 升級為某個方案。訂閱費用在呼叫當下立即從帳戶餘額扣除,回應中包含扣款後的剩餘餘額 remainingCredits。
/api/v1/keys/:id/subscriptionRequest Body
Response
{
"ok": true,
"remainingCredits": 80.0000, // balance after deduction
"subscriptionPlan": {
"id": "clxxxxx",
"slug": "standard",
"priceUsd": 20,
"rpmLimit": 60,
"tokenLimit": 2000000,
"tokenLimitPeriod": "day"
}
}Error Codes
Example
# Login first to obtain a session cookie
curl -X POST https://bazaarlink.ai/api/v1/keys/KEY_ID/subscription \
-H "Content-Type: application/json" \
-H "Cookie: next-auth.session-token=YOUR_SESSION" \
-d '{"planSlug": "standard"}'可呼叫模型
訂閱方案可能包含一組「獨家模型」,只有訂閱該方案的 Key 才能呼叫。從 GET /api/v1/plans 的 models 陣列取得完整清單。
若方案的 models 陣列為空([]),表示該方案可呼叫所有一般模型(免費方案也能用的模型),以方案的 RPM 與 Token 配額為限制。
# List models included in the standard plan
curl https://bazaarlink.ai/api/v1/plans \
| jq '.[] | select(.slug == "standard") | .models[] | {modelId, basePoints}'呼叫訂閱制模型
使用訂閱了該方案的 API Key 發送請求即可,與一般呼叫方式完全相同:
curl https://bazaarlink.ai/api/v1/chat/completions \
-H "Authorization: Bearer sk-bl-YOUR_SUBSCRIBED_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'查詢剩餘額度
帳戶餘額(Credits)是訂閱費用與 API 使用費的共用資金池。可透過以下端點即時查詢:
/api/v1/creditsResponse
{
"data": {
"total_credits": 80.0000, // current remaining balance (USD)
"total_usage": 42.1234 // lifetime API spend since account creation
}
}Example
curl https://bazaarlink.ai/api/v1/credits \ -H "Authorization: Bearer sk-bl-YOUR_API_KEY"
Token 配額與重置時間
每個方案設有 Token 配額(tokenLimit)與重置週期(tokenLimitPeriod)。重置以 UTC 時間為基準:
查詢方案 Token 配額
# Query quota settings for all plans
curl https://bazaarlink.ai/api/v1/plans \
| jq '.[] | {slug, tokenLimit, tokenLimitPeriod}'
# Example output:
# {
# "slug": "standard",
# "tokenLimit": 2000000,
# "tokenLimitPeriod": "day"
# }計算下次重置時間(範例)
from datetime import datetime, timezone, timedelta
def next_reset(period: str) -> datetime:
now = datetime.now(timezone.utc)
if period == "day":
return (now + timedelta(days=1)).replace(
hour=0, minute=0, second=0, microsecond=0)
elif period == "week":
days_ahead = 7 - now.weekday() # Monday = 0
return (now + timedelta(days=days_ahead)).replace(
hour=0, minute=0, second=0, microsecond=0)
elif period == "month":
if now.month == 12:
return now.replace(year=now.year+1, month=1, day=1,
hour=0, minute=0, second=0, microsecond=0)
return now.replace(month=now.month+1, day=1,
hour=0, minute=0, second=0, microsecond=0)
elif period == "5h":
current_block = now.hour // 5
next_block_hour = (current_block + 1) * 5
if next_block_hour >= 24:
next_day = (now + timedelta(days=1)).replace(
hour=0, minute=0, second=0, microsecond=0)
return next_day
return now.replace(hour=next_block_hour, minute=0,
second=0, microsecond=0)
plan_period = "day" # from GET /api/v1/plans
print(f"Next reset: {next_reset(plan_period).isoformat()}")取消訂閱
取消後 API Key 立即回到免費方案(標準速率限制),訂閱費用不退款。
/api/v1/keys/:id/subscriptionResponse
{ "ok": true }Example
curl -X DELETE https://bazaarlink.ai/api/v1/keys/KEY_ID/subscription \ -H "Cookie: next-auth.session-token=YOUR_SESSION"
完整流程範例
// 1. Query available plans
const plans = await fetch("/api/v1/plans").then(r => r.json());
// 2. Check account balance
const { data: credits } = await fetch("/api/v1/credits", {
headers: { Authorization: "Bearer sk-bl-YOUR_KEY" },
}).then(r => r.json());
// 3. Confirm balance then subscribe
const plan = plans.find(p => p.slug === "standard");
if (credits.total_credits < plan.priceUsd) {
throw new Error(`Insufficient balance: need $${plan.priceUsd}, current $${credits.total_credits}`);
}
const sub = await fetch("/api/v1/keys/KEY_ID/subscription", {
method: "POST",
credentials: "include",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ planSlug: "standard" }),
}).then(r => r.json());
console.log("Subscribed! Remaining balance:", sub.remainingCredits);
console.log("Plan:", sub.subscriptionPlan.slug);
console.log("RPM:", sub.subscriptionPlan.rpmLimit);
console.log("Token quota:", sub.subscriptionPlan.tokenLimit, "/", sub.subscriptionPlan.tokenLimitPeriod);
// 4. Cancel subscription (optional)
// await fetch("/api/v1/keys/KEY_ID/subscription", {
// method: "DELETE", credentials: "include"
// });AI 點數系統
每個訂閱方案包含每日 AI 點數額度。不同模型每次請求消耗不同點數。
每日點數
Loading plans…
點數分級規則
模型依 API 定價(input + output 每百萬 token)分級,每次請求扣除對應級別的點數。
Loading tier rules…
查詢點數餘額
/api/v1/points/balance// GET /api/v1/points/balance
// Authorization: Bearer sk-bl-xxx
{
"dailyLimit": 3700,
"dailyUsed": 1250,
"dailyRemaining": 2450,
"resetAt": "2026-03-18T00:00:00+08:00"
}curl https://bazaarlink.ai/api/v1/points/balance \ -H "Authorization: Bearer sk-bl-YOUR_API_KEY"
API Response Headers
Every chat completion response includes point usage headers:
# Example response headers: # x-points-used: 25 # x-points-remaining: 2425 # x-points-daily-limit: 3700