An Embarrassing Moment Every Manager Knows
Anyone who has led a small team has probably seen this scene: the frontend dev @-mentions the backend dev in the group chat, "What exactly is in the data field of this API?" The backend replies, "Just look at the response sample." Then the frontend dev stares at a screenshot, hand-writing type definitions for twenty minutes—only to discover during integration testing three days later that a nested field was missed, forcing a rework.
This is nobody's fault; it's the process's fault. API documentation always lags behind code, type definitions are scattered and maintained separately on each end, and when problems arise, nobody can say which version is the "correct" one. As a manager, I see three layers of risk:
- Collaboration risk: Frontend and backend each guess at fields, leading to repeated rework during integration, burning time away;
- Quality risk: Hand-written types easily miss optional fields or misjudge null, blowing up only in production;
- Compliance risk: When APIs contain sensitive fields (phone numbers, internal IDs), no one can quickly inventory "what data this API actually exposes."
Later, we handed this task to AI: give it an API response sample and let it reverse-engineer the complete type definitions. Three months on, this process has become the team's standard step before integration testing.
What AI Can Actually Do Here
Let me be clear about AI's role: it is not the one writing APIs for you—it's the one doing the mechanical "sample → type" translation. Specifically, it can do four things:
First, reverse-engineer structured types from a JSON sample. Whether you need TypeScript interfaces, JSON Schema, or Go structs, it can derive field names and hierarchy from a single response sample and generate compilable code.
Second, flag areas of uncertainty. Good prompts make the AI explicitly say "this field is null in the sample, so I can't tell whether it's string | null or a nested object," rather than silently guessing. This is the key to risk control—it doesn't matter if the AI guesses wrong; what matters is that it tells you it's uncertain.
Third, standardize the team's type conventions. Naming style, comment format, whether to generate mock data—all can be codified in the prompt. New hires don't need to read documentation; they just run the template.
Fourth, perform cross-validation. Have the AI compare the backend's actual responses against the new type definitions to find fields that "exist in the sample but not in the types"—this step specifically cures "documentation lag."
Our Rollout Process
What managers care about most isn't how flashy the demo is, but whether the process can be standardized. We settled on four steps:
- Collect samples: Backend runs one real request in the staging environment and pastes the (sanitized) JSON response into a shared document. Anyone can paste; it doesn't depend on a specific person.
- AI reverse-engineers types: Use a unified prompt template to generate TypeScript type definitions, along with a list of uncertain fields.
- Human confirms the gray areas: Backend only looks at the uncertain points flagged by the AI, one confirmation takes 30 seconds. Note that the human's role shifts from "writing types" to "reviewing types," reducing workload by an order of magnitude.
- Commit and compare: The type files go into the frontend repo; when the API changes later, rerun the process, and the diff is your API change list—which also solves the chronic problem of "the API silently changed and nobody was notified."
A Reusable Prompt Template
Here's a simplified version of our team's template, ready to use:
你是一名资深后端工程师,请根据下面的接口返回 JSON 样例,反推 TypeScript 类型定义。
要求:
1. 为顶层对象命名为 {InterfaceName},嵌套对象单独定义 interface,命名使用 PascalCase;
2. 字段类型从样例推导,无法从单条样例确定的(如空数组、null),不要猜测,
放入「不确定字段清单」,并给出 2 种最可能的类型假设;
3. 疑似日期、枚举、ID 的字段,用注释说明判断依据;
4. 敏感字段(手机号、邮箱、内部ID 等)加 @sensitive 注释;
5. 输出顺序:①类型定义代码 ②不确定字段清单 ③建议向后端确认的问题列表。
接口名:{InterfaceName}
JSON 样例:
{paste_json_here}Items 2 and 5 are the essence: forcing the AI to expose its uncertainty and turning "guesses" into "questions"—only then can managers do the review.
Before and After AI
Before: Frontend hand-wrote types from screenshots, averaging 15–30 minutes per API; complex nested APIs often missed fields, causing rework during integration; silent API changes went unnoticed until production incidents; sensitive fields were checked manually and never systematically inventoried.
After: Paste the sample, get types plus an uncertainty list in 10 seconds; backend confirms gray areas in under a minute on average; API changes are caught automatically by rerunning the diff; sensitive field lists are generated automatically, giving security audits something to work with.
Rough calculation: a single API goes from "half an hour + integration rework" to "two minutes + one confirmation." More importantly, this process doesn't depend on anyone's experience—the prompt template sits in the team repo, and whoever runs it gets consistent results. For managers, this is called a replicable process; for people, this is called being able to take a vacation without worry.
A Few Management-Level Reminders
- Samples must be sanitized: Never feed real user data directly to external models. Mask fields first—write this into the process; don't rely on individual discretion.
- AI output must pass a human eye: Especially the uncertainty list. This one minute of review is the safety valve for the entire process.
- Costs are controllable: Mainstream models are more than sufficient for this kind of task. Check the official pricing page for specifics—the cost per API is practically negligible.
One final honest note: this kind of "plug AI into your daily workflow" capability requires a stable, usable model API channel. We're using https://api.thistoken.ai/register—register and go. Give it a try and get this process running in your own team.
---
Every example in this post runs with a single API key — get yours at https://api.thistoken.ai/register and start in minutes.
Bạn muốn thử Token.AI?
Tạo API Key cấp dự án, bật kênh trong bảng điều khiển và định cấu hình định tuyến, ngân sách và nhật ký kiểm tra.
注册 ThisToken.AI 并获取 API Key