Skip to content
TutujinAPI

AI agents and workflow automation

AI agents and workflow automation usually have two layers: a cheap small model turns emails, tickets and forms into JSON with fixed fields so code can pick the workflow, and a main model calls tools (function calling) to look things up and draft replies. Actions with side effects, such as refunds or outgoing email, wait in a human approval queue, and every step is logged. For 50,000 events a month with 10,000 of them handled by the agent, at live prices in each model’s cheapest group, model costs are about ¥331 a month.

Prices updated Nov 13, 2026, 6:13 PM

Monthly cost estimate

Assumptions: 50,000 events a month (emails, tickets, forms) are classified first, at about 800 input and 120 output tokens each; 10,000 of them go to the agent, averaging 4 model calls per task (3 tool calls and a final reply) at about 3,500 input tokens each (1,500 system prompt and tool definitions, 2,000 task and earlier results) and 250 output tokens.

¥331per month

  • Event classification and extraction¥31
  • Agent tool-calling steps¥300
See the usage assumed

The business problem

A lot of back-office work follows a pattern: read an email or ticket, look things up in a few systems, apply the rules, then reply or record the result. With many rules and exceptions, hard-coded scripts cannot keep up, and doing it all by hand is slow and error-prone.

An LLM understands this unstructured input and can call tools to look up orders, check stock or open tickets. It can also pick the wrong tool, invent arguments or act when it should not. Letting a model issue refunds, send email or change data on its own is a risk that is hard to control.

The safer design splits the work: the model understands and drafts, code validates and executes. Read-only lookups can run automatically, anything with side effects goes through human approval, and the input, output and tools of every step are recorded so you can trace what happened.

Recommended models

Recommended models are picked from the live catalog; prices are each model's cheapest group, updated Nov 13, 2026, 6:13 PM. Click a model to see every group's price.

  • Classification and structured output (small model)

    input ¥0.4 / output ¥2.5 per 1M tokensStandard group

    Turns the content of emails, tickets and forms into JSON with fixed fields such as category, order number and urgency, so code can route the workflow. The task is simple and the volume high, so use a low-priced small model. Prefer response_format with json_schema; where a model does not support it, use json_object, and validate the fields in code either way.

  • Tool calling and multi-step work (main model)

    input ¥1.5 / output ¥9 per 1M tokensStandard group

    Decides which function to call with which arguments, reads the result and continues until it reaches a conclusion or a draft. Every step resends the tool definitions and earlier results, so input tokens grow quickly and the number of steps needs a cap. Models differ in how they handle tool calling: test with your own tool definitions before going live, and for long or complex workflows compare against the alternatives.

Reference architecture

  1. 1

    Receive events

    Events come from email, a ticketing system, form submissions or schedules. Build the workflow in n8n or Dify, or consume a message queue in your own service; the model calls are the same either way.

  2. 2

    Classify and extract

    A small model turns the raw content into JSON with fixed fields (category, order number, amount, urgency) and code validates it against a JSON Schema. Retry once on failure, then hand it to a person.

  3. 3

    Call tools

    The main model gets the task and the tool definitions (look up an order, check stock, search the knowledge base, draft a reply) and decides the order of calls. Your code runs each tool and returns the result; cap each task at a maximum number of steps, for example 6.

  4. 4

    Human approval

    For actions with side effects, such as refunds, outgoing email or data changes, the model can only file a request: code puts the action and its arguments in an approval queue and executes it after a person confirms. Read-only lookups can run automatically.

  5. 5

    Audit trail

    Record each step’s input, the model used, the tools called with their arguments and results, the approver and time, and the usage field (tokens) of each response, for reviews and for reconciling with the usage log in the console.

  6. 6

    Quotas and monitoring

    Give the automation its own API key with a quota limit. Watch the failure rate, the share handed to people and tokens per task; when something looks wrong, pause automatic execution and route everything to people.

Cost estimate

Assumptions: 50,000 events a month (emails, tickets, forms) are classified first, at about 800 input and 120 output tokens each; 10,000 of them go to the agent, averaging 4 model calls per task (3 tool calls and a final reply) at about 3,500 input tokens each (1,500 system prompt and tool definitions, 2,000 task and earlier results) and 250 output tokens.

ItemModelUsage assumedCost
Event classification and extractiongpt-5.4-nano50,000 × (800 input + 120 output tokens)¥31
Agent tool-calling stepsgpt-5.4-mini40,000 × (3,500 input + 250 output tokens)¥300
Total (per month)¥331

Calculated from live prices in each model's cheapest group, updated Nov 13, 2026, 6:13 PM.

Model usage only: workflow platform, servers and human approval are not included. Agent cost is driven by the number of steps, because every extra step resends the tool definitions and earlier results; that is why the step count needs a cap. System prompt and tool definitions are identical every time, so if the model supports context caching the cached part is billed at the lower cache-read price. Reasoning models bill their thinking as output; some models let you lower it with reasoning_effort. Twice the events means roughly twice the cost.

Sample code

A small model turns the message into JSON with fixed fields; tasks that need work go to an agent loop. Read-only tools run directly, tools with side effects such as refunds only go to an approval queue, every step is logged, and the loop hands over to a person after the step limit.

Sample code (Python, structured routing + tool calling)
import json
import os
from openai import OpenAI

client = OpenAI(base_url="https://www.tutujin.com/v1", api_key=os.environ["TUTUJIN_API_KEY"])
audit_log, approval_queue = [], []

TICKET = {"name": "ticket", "strict": True, "schema": {
    "type": "object",
    "properties": {
        "category": {"type": "string", "enum": ["refund", "shipping", "invoice", "other"]},
        "order_id": {"type": ["string", "null"]},
        "urgent": {"type": "boolean"},
    },
    "required": ["category", "order_id", "urgent"],
    "additionalProperties": False,
}}


def classify(text):
    """Small model: free text in, fixed fields out. Code decides the workflow."""
    resp = client.chat.completions.create(
        model="gpt-5.4-nano",
        messages=[{"role": "system", "content": "Extract the ticket fields."}, {"role": "user", "content": text}],
        # models without json_schema support: {"type": "json_object"}, then check the fields yourself
        response_format={"type": "json_schema", "json_schema": TICKET},
    )
    return json.loads(resp.choices[0].message.content)


TOOLS = [
    {"type": "function", "function": {
        "name": "get_order", "description": "Look up an order. Read-only.",
        "parameters": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]},
    }},
    {"type": "function", "function": {
        "name": "refund", "description": "Refund an order. Runs only after a person approves it.",
        "parameters": {"type": "object", "properties": {
            "order_id": {"type": "string"}, "amount": {"type": "number"}, "reason": {"type": "string"}},
            "required": ["order_id", "amount", "reason"]},
    }},
]


def run_tool(name, args):
    if name == "get_order":
        return {"order_id": args["order_id"], "status": "delivered", "paid": 129.0}  # call your order API here
    if name == "refund":
        approval_queue.append(args)  # side effect: a person approves, then your code executes it
        return {"status": "waiting_for_approval"}
    return {"error": "unknown tool"}


def run_agent(task, max_steps=6):
    messages = [
        {"role": "system", "content": "You handle after-sales requests with the tools. Never promise a refund before it is approved."},
        {"role": "user", "content": task},
    ]
    for step in range(max_steps):
        resp = client.chat.completions.create(model="gpt-5.4-mini", messages=messages, tools=TOOLS)
        msg = resp.choices[0].message
        audit_log.append({"step": step, "model": resp.model, "usage": resp.usage.model_dump() if resp.usage else None})
        if not msg.tool_calls:
            return msg.content
        messages.append({"role": "assistant", "content": msg.content, "tool_calls": [c.model_dump() for c in msg.tool_calls]})
        for call in msg.tool_calls:
            try:
                args = json.loads(call.function.arguments or "{}")
                result = run_tool(call.function.name, args)
            except (json.JSONDecodeError, KeyError) as e:
                args, result = call.function.arguments, {"error": "bad arguments: " + str(e)}
            audit_log.append({"step": step, "tool": call.function.name, "args": args, "result": result})
            messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})
    return "Step limit reached, handing over to a person."


text = "Order 10086 arrived broken. I want my money back."
if classify(text)["category"] == "refund":
    print(run_agent(text))
    print("waiting for approval:", approval_queue)

Try this with one key

Sign up, create an API key in the console, and put your base_url and key into the code above. For company purchasing or invoices, add our WeChat support JsnonoChat.

Tutujin support WeChat QR code
WeChatJsnonoChat

Scan the code or search the WeChat ID to add us

FAQ

How much does an AI agent cost per month?

With 50,000 events classified a month, 10,000 tasks handled by the agent and about 4 model calls per task, the cheapest groups come to about ¥331 a month. Agent cost is mostly about the number of steps and the context sent with each.

Can I use this in Dify or n8n?

Yes. Dify connects through the OpenAI-API-compatible model provider; in n8n, set the Base URL of the OpenAI credential to https://www.tutujin.com/v1. Use model names as listed on the models page; the Dify and n8n guides below have the steps. For tool calling in Dify, the model itself must support it and Function calling must be turned on when you add the model.

How do I stop an agent from doing things it should not?

Give the model only the tools the task needs. Tools with side effects, such as refunds, email or data changes, only create a request that your code executes after a person approves it. Validate tool arguments in code before running them rather than trusting amounts or recipients the model supplied, and cap the steps per task, handing over to a person beyond that.

What if the model does not return valid JSON?

Use response_format with json_schema and put fields, types and allowed values in the schema. Where that is not supported, use json_object and describe the fields in the prompt. Either way, validate against the schema in code and retry once or hand over to a person on failure.

What should the audit log contain?

At least the triggering event, the model used at each step, the tools called with their arguments and results, the approver and approval time, the final outcome and the usage field of each response. Then you can reconstruct what happened and reconcile with the usage log in the console.

What if a workflow uses models from different groups?

One key can have several groups in priority order; each request uses the first group that offers the model and is billed at that group’s price. Or give each workflow its own key with its own quota limit and see the bills per key.