# 第一步:视觉模型提取要素(结构化,可审核)
elements = gateway.chat(
model="vision-model",
messages=[{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": image_url}},
{"type": "text", "text": "提取品类/颜色/可见瑕疵/成色,以JSON输出,不确定的字段填null"}
]
}],
temperature=0.1
)
elements = validate_schema(elements) # 结构校验,缺失字段兜底
第二步:合规校验(独立于模型)
if contains_banned_words(elements):
return fallback_manual_review()
第三步:文本模型按平台模板生成
desc = gateway.chat(
model="text-model",
messages=build_prompt(elements, category_hint),
temperature=0.3
)
return compliance_filter(desc) # 发布前最后一道闸
## IV. Why We Insisted on a Unified AI API Gateway
This is the decision I explained the most when making the call internally. Calling model APIs directly from business code looks fast in the short term, but long-term maintenance costs spiral out of control, for four reasons:
**Centralized keys and security**. API keys are configured only on the gateway side; business servers and clients never touch them. Otherwise, every staff change, server migration, or mini-program launch means redistributing keys — multiplying leakage risk.
**Model replacement without touching business code**. Models iterate fast — we've already swapped the vision model once during gray release. Because business code only talks to the gateway's unified interface, replacement was just a one-line routing config change on the gateway side, with zero changes in the business layer. If we had hardcoded model names at every call site, this swap would have touched at least five modules.
**Manageable usage and costs**. Call volumes per department and per scenario are uniformly tracked and rate-limited at the gateway. If this high-frequency description generation scenario ever gets hit by anomalous traffic, the quota mechanism automatically trips the circuit — bills won't spiral out of control. This is the "visibility" a manager needs most.
**Comprehensive logging and auditing by default**. All requests have unified logs, which combined with the audit trail requirements mentioned above provides the data foundation for dispute tracing and performance analysis.
## V. A Few Lessons Learned
Since this pipeline launched, the proportion of listings with empty descriptions has dropped significantly, and the seller edit rate has stabilized in an acceptable range, indicating the generation quality passes. Looking back, the technology wasn't hard — what truly determined success were three things: rule documents before code, seller confirmation to contain risk, and a gateway layer making models swappable and manageable. For indie developers and small teams, my advice: the gap in shipping AI applications isn't about knowing how to call APIs — it's about whether you've designed the process, collaboration, and risk control properly.
If you're about to start, begin by connecting to a unified AI API gateway that handles key management, model routing, and usage monitoring in one step: 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.Vous voulez essayer Token.AI ?
Créez une API Key au niveau du projet, activez les canaux dans la console et configurez le routage, les budgets et les journaux d'audit.
注册 ThisToken.AI 并获取 API Key