# Map:分块摘要,走长上下文模型
chunks = split_by_section(text, max_tokens=6000)
partials = []
for chunk in chunks:
partials.append(call_gateway(
model="long-context-model",
messages=[{"role": "user",
"content": f"提炼以下章节的核心结论与关键数据:\n{chunk}"}],
timeout=60, retries=2,
))
Reduce:汇总,同样走网关,模型在网关侧可配置切换
final = call_gateway(
model="long-context-model",
messages=[{"role": "user",
"content": "合并以下分章摘要为一页结论:\n" + "\n".join(partials)}],
)
质检:轻量模型做遗漏检查,控制成本
check = call_gateway(
model="light-model",
messages=[{"role": "user",
"content": f"对比原文摘要与结论,列出遗漏的关键数字:\n{final}"}],
)
if check.strip() not in ("无", "none"):
final = refine(final, check) # 补一轮重试
log_usage(doc_id) # 审计留痕:模型、token、耗时
return {"doc_id": doc_id, "summary": final}
Note that the code contains no model vendor SDK—every request goes to the same gateway endpoint. When models are upgraded or replaced, only the gateway configuration changes; not a single line of business code moves.
## 4. Why a Unified Gateway Slashes Maintenance Costs
Here's the accounting I walked the team through during design review:
- **Integration cost goes from N to 1**. Direct connections to multiple vendors mean a separate auth scheme, error codes, rate-limit rules, and SDK version dependencies for each. With a unified gateway, the business side maintains only one endpoint and one error-handling layer—vendor-side differences are shielded by the gateway.
- **Centralized key governance**. Keys used to be scattered across scripts and environment variables—you might not even know if one leaked. With gateway hosting, key rotation, permission tiering, and call logs are managed in one place, giving legal and security a single point of control for compliance checks.
- **Model replaceability**. Summarization models get replaced every three months, with significant price volatility. With gateway routing, switching models is a configuration change, not a code change—two developers won't be held hostage by model migration schedules.
- **Cost visibility**. The gateway's usage statistics break out billing by department and task type. Finance no longer suffers through month-end reconciliation, and budget overrun warning signs show up in weekly reports.
Three months after launch, two IT staff maintain the entire pipeline with ease, and ops time on the model side is nearly zero—the saved effort all goes into summary quality and business integration.
## 5. Final Thoughts
From a manager's perspective, the deciding factor in shipping AI applications is often not the prompts, but whether permissions, cost, and audit were designed into the architecture from day one. A unified AI API gateway is precisely the approach that consolidates these management concerns into a single technical lever.
If your team is planning a similar AI application, start building your foundation with unified access: https://api.thistoken.ai/register
---
Every example in this post runs with a single API key — get yours at https://api.thistoken.ai/register and start in minutes.Хотите попробовать Token.AI?
Создайте API Key уровня проекта, включите каналы в консоли и настройте маршрутизацию, бюджеты и журналы аудита.
注册 ThisToken.AI 并获取 API Key