计算每个 SERP API 查询的有效成本需要考虑利用率、强制解决方法的功能差距、集成怪异所花费的工程时间以及详细响应带来的 LLM 令牌开销,而不仅仅是每个请求的标价。本教程构建了一个成本模型,该模型揭示了任何 SERP API 的真实每次查询价格,以便您可以进行同类比较并避免导致账单膨胀的隐藏费用。
前置条件
- 当前 SERP API 计费数据或定价页面详细信息
- Python 3.9+ 或 Node.js 18+
- 每月查询量及工程小时费率预估
操作指南
步骤 1: 收集原始定价输入
收集标价,包括查询配额、超额率以及您正在比较的每个 API 的任何最低承诺。还记录包含哪些功能(结构化数据、知识面板、SERP 功能)以及哪些功能需要额外调用。
providers = {
'provider_a': {
'plan_cost': 100,
'included_queries': 5000,
'overage_per_query': 0.025,
'has_structured_data': False,
'has_knowledge_panels': True,
'avg_response_tokens': 4200,
},
'scavio': {
'plan_cost': 100,
'included_queries': 28000, # $100/28K credits
'overage_per_query': 0.005,
'has_structured_data': True,
'has_knowledge_panels': True,
'avg_response_tokens': 1800,
},
}
monthly_queries = 15000
eng_hourly_rate = 75 # USD步骤 2: 计算每个查询的基本成本
计算每个查询的基本成本以计算利用率。如果您仅使用包含配额的 60%,则每次查询的有效价格将高于标价,因为您要为未使用的容量付费。
def base_cost_per_query(provider, monthly_queries):
included = provider['included_queries']
plan_cost = provider['plan_cost']
if monthly_queries <= included:
# Paying for unused queries
utilization = monthly_queries / included
effective = plan_cost / monthly_queries
else:
overage = monthly_queries - included
total_cost = plan_cost + (overage * provider['overage_per_query'])
effective = total_cost / monthly_queries
utilization = 1.0
return {
'effective_per_query': round(effective, 5),
'utilization': round(utilization * 100, 1),
'monthly_total': round(effective * monthly_queries, 2),
}步骤 3: 添加功能差距附加费
如果提供商缺乏结构化数据提取,您需要额外的工程时间或额外的 API 调用来获取该数据。估计每月花在解决方法上的工程时间并将其添加到成本中。
def feature_gap_cost(provider, monthly_queries, eng_hourly_rate):
hours_per_month = 0
extra_queries = 0
if not provider['has_structured_data']:
# Estimate 4 hours/month building and maintaining parsing logic
hours_per_month += 4
# 10% of queries need a follow-up call to get structured data
extra_queries += int(monthly_queries * 0.10)
eng_cost = hours_per_month * eng_hourly_rate
extra_query_cost = extra_queries * provider['overage_per_query']
return {
'eng_hours': hours_per_month,
'eng_cost': eng_cost,
'extra_queries': extra_queries,
'extra_query_cost': extra_query_cost,
'total_gap_cost': eng_cost + extra_query_cost,
}步骤 4: 估计 LLM 代币开销
如果您将 SERP 结果传输到 LLM,则详细的 API 响应会花费更多的令牌。根据平均响应大小计算每月令牌成本差异。按照典型的 LLM 输入定价为每百万代币 3 美元,这一数字会迅速增加。
def llm_token_cost(provider, monthly_queries, cost_per_million_tokens=3.0):
total_tokens = provider['avg_response_tokens'] * monthly_queries
cost = (total_tokens / 1_000_000) * cost_per_million_tokens
return {
'total_tokens': total_tokens,
'monthly_llm_cost': round(cost, 2),
'per_query_llm_cost': round(cost / monthly_queries, 6),
}步骤 5: 计算总有效成本并进行比较
将基本成本、功能差距附加费和 LLM 令牌开销相加,以获得每个查询的真实有效成本。打印一个比较表,以便您可以了解哪个提供商对于您的工作量来说实际上最便宜。
print(f'Monthly volume: {monthly_queries:,} queries\n')
print(f'{"Provider":<15} {"Base":>8} {"Gaps":>8} {"LLM":>8} {"Total":>8} {"Per-Query":>10}')
print('-' * 65)
for name, p in providers.items():
base = base_cost_per_query(p, monthly_queries)
gaps = feature_gap_cost(p, monthly_queries, eng_hourly_rate)
llm = llm_token_cost(p, monthly_queries)
total = base['monthly_total'] + gaps['total_gap_cost'] + llm['monthly_llm_cost']
per_query = total / monthly_queries
print(f'{name:<15} ${base["monthly_total"]:>7.2f} ${gaps["total_gap_cost"]:>7.2f} ${llm["monthly_llm_cost"]:>7.2f} ${total:>7.2f} ${per_query:>9.5f}')Python 示例
providers = {
'provider_a': {
'plan_cost': 100,
'included_queries': 5000,
'overage_per_query': 0.025,
'has_structured_data': False,
'has_knowledge_panels': True,
'avg_response_tokens': 4200,
},
'scavio': {
'plan_cost': 100,
'included_queries': 28000,
'overage_per_query': 0.005,
'has_structured_data': True,
'has_knowledge_panels': True,
'avg_response_tokens': 1800,
},
}
monthly_queries = 15000
eng_hourly_rate = 75
def base_cost_per_query(provider, monthly_queries):
included = provider['included_queries']
plan_cost = provider['plan_cost']
if monthly_queries <= included:
effective = plan_cost / monthly_queries
else:
overage = monthly_queries - included
total_cost = plan_cost + (overage * provider['overage_per_query'])
effective = total_cost / monthly_queries
return round(effective * monthly_queries, 2)
def feature_gap_cost(provider, monthly_queries, eng_rate):
hours = 0 if provider['has_structured_data'] else 4
extra_queries = 0 if provider['has_structured_data'] else int(monthly_queries * 0.10)
return hours * eng_rate + extra_queries * provider['overage_per_query']
def llm_token_cost(provider, monthly_queries):
tokens = provider['avg_response_tokens'] * monthly_queries
return round((tokens / 1_000_000) * 3.0, 2)
print(f'Monthly volume: {monthly_queries:,} queries')
print(f'{"Provider":<15} {"Base":>8} {"Gaps":>8} {"LLM":>8} {"Total":>8} {"Per-Query":>10}')
print('-' * 65)
for name, p in providers.items():
base = base_cost_per_query(p, monthly_queries)
gaps = feature_gap_cost(p, monthly_queries, eng_hourly_rate)
llm = llm_token_cost(p, monthly_queries)
total = base + gaps + llm
per_q = total / monthly_queries
print(f'{name:<15} ${base:>7.2f} ${gaps:>7.2f} ${llm:>7.2f} ${total:>7.2f} ${per_q:>9.5f}')JavaScript 示例
const providers = {
provider_a: {
planCost: 100,
includedQueries: 5000,
overagePerQuery: 0.025,
hasStructuredData: false,
avgResponseTokens: 4200,
},
scavio: {
planCost: 100,
includedQueries: 28000,
overagePerQuery: 0.005,
hasStructuredData: true,
avgResponseTokens: 1800,
},
};
const monthlyQueries = 15000;
const engHourlyRate = 75;
function baseCost(p, queries) {
if (queries <= p.includedQueries) return p.planCost;
const overage = queries - p.includedQueries;
return p.planCost + overage * p.overagePerQuery;
}
function featureGapCost(p, queries, engRate) {
if (p.hasStructuredData) return 0;
const engCost = 4 * engRate;
const extraQueries = Math.floor(queries * 0.1) * p.overagePerQuery;
return engCost + extraQueries;
}
function llmTokenCost(p, queries) {
const tokens = p.avgResponseTokens * queries;
return (tokens / 1_000_000) * 3.0;
}
console.log(`Monthly volume: ${monthlyQueries.toLocaleString()} queries`);
console.log('Provider Base Gaps LLM Total Per-Query');
console.log('-'.repeat(60));
for (const [name, p] of Object.entries(providers)) {
const base = baseCost(p, monthlyQueries);
const gaps = featureGapCost(p, monthlyQueries, engHourlyRate);
const llm = llmTokenCost(p, monthlyQueries);
const total = base + gaps + llm;
const perQ = total / monthlyQueries;
console.log(
`${name.padEnd(15)} $${base.toFixed(2).padStart(7)} $${gaps.toFixed(2).padStart(7)} $${llm.toFixed(2).padStart(7)} $${total.toFixed(2).padStart(7)} $${perQ.toFixed(5).padStart(9)}`
);
}预期输出
Monthly volume: 15,000 queries
Provider Base Gaps LLM Total Per-Query
-----------------------------------------------------------------
provider_a $350.00 $337.50 $189.00 $876.50 $0.05843
scavio $100.00 $0.00 $81.00 $181.00 $0.01207