GLM 5.4 should not receive production traffic through Pydantic AI Code Mode on the strength of its Vercel AI Gateway listing. The listing establishes model availability, not a configured Pydantic AI route or competence at generating Python against your tools. First verify that the route works at all. Then run a fixed qualification suite that scores first-pass script validity, final task correctness, executions and retries, provider-reported token use where available, and human review burden.
That sequence matters because Code Mode changes the artifact being trusted. A conventional tool-calling agent selects individual calls; a Code Mode agent generates a program that uses those tools. A strong chat response or coding-agent benchmark cannot establish that the same model will satisfy your generated type stubs, recover from script errors, or complete a workflow within an execution budget.
What the Vercel listing establishes
Vercel’s announcement identifies GLM 5.4 as Z.ai’s flagship model for coding and agentic work, built on a Loop Transformer architecture. On Vercel AI Gateway, its model name is zai/glm-5.4. The listing describes a 1M-token context window, tool calling, structured outputs, prompt caching, and image input, with Zero Data Retention on that gateway route.
Those are useful capability and procurement facts. They are not Code Mode results. A large context window does not show that the model will follow a particular set of tool-derived Python interfaces. Tool-calling support does not demonstrate correct multi-step generated scripts. Prompt-caching support does not establish that this workload will produce cache hits or reduce its actual bill.
The client list is equally specific. Vercel describes setup through npx vercel ai-gateway setup and selection of zai/glm-5.4 in agents including Claude Code, Codex, and Cursor. It does not name Pydantic AI. That absence is not proof that the combination fails, but it does mean the announcement cannot supply the integration step this article needs.
Zero Data Retention also needs route-level treatment. Vercel’s listing offers GLM 5.4 on AI Gateway with Zero Data Retention, and that guarantee requires the team-wide ZDR setting, which routes requests only to ZDR providers. The claim attaches to Vercel AI Gateway with that setting enabled, and it should not be carried over automatically to Pydantic AI Gateway, a direct provider connection, or some future configuration. If retention terms affect whether your tool data can be used in the trial, verify them for the exact route before selecting fixtures.
Why the available Code Mode numbers cannot qualify GLM
Pydantic’s own comparison shows why the execution path deserves separate testing. In its Code Mode documentation, Pydantic reports three runs of one question using an OpenAI model. The Code Mode agent was correct in all three runs and used a median of 4,680 input tokens. With plain tool calls, the same agent was correct in one run of three and used 111,162 tokens, according to the same comparison.
That is a striking vendor-reported result, but its scope is narrow: one question, three runs, one OpenAI model, and no GLM measurements. It does not tell us whether the difference came from task structure, model behavior, the tool interfaces, or some combination of them. It certainly does not supply an expected token reduction for GLM 5.4.
The result nevertheless supports one practical conclusion: changing between plain tool calls and generated-code execution can change both correctness and token consumption substantially. Qualification therefore needs to test the whole agent path, not just the model’s general coding reputation.
Pydantic’s published comparison reports only an OpenAI model, and neither it nor Vercel’s listing records a GLM run through Code Mode. Neither source includes independent GLM failure reports for this path. That absence should remain uncertainty, not become an implicit clean bill of health.
Gate 0: prove the route before evaluating the model
Pydantic AI’s overview says models can be swapped with a string or used through Pydantic AI Gateway, which provides one key, failover, and cost monitoring. Its named providers include OpenAI, Anthropic, Google, Bedrock, Azure AI Foundry, Groq, Mistral, xAI, and Ollama. Z.ai and GLM are not named, although the overview also says that dozens more providers are supported.
The right interpretation is “attemptable but undocumented,” not “supported” and not “impossible.”
In particular, zai/glm-5.4 is documented as Vercel’s gateway identifier. Neither Vercel’s listing nor Pydantic’s documentation establishes it as a valid Pydantic AI model string. Vercel AI Gateway and Pydantic AI Gateway also should not be treated as interchangeable names for one connection.
A route-verification pass should therefore do four things:
- Choose one explicit candidate route. Attempt either a Pydantic AI model string or a gateway configuration supported by your installed version. Record the exact configuration rather than describing the candidate only as “GLM.”
- Run one harmless tool workflow. Use a disposable fixture with a known result. A configuration error stops the experiment; a chat-only response does not clear this gate.
- Verify which model actually served the run where that information is available. If a gateway uses failover, do not count a fallback model’s success as evidence for GLM 5.4.
- Preserve the route, package versions, prompt version, and any provider error. These details determine whether another engineer can reproduce the result.
A single successful request proves only that the exact request completed. It does not establish script validity or workflow reliability. Conversely, a failed configuration attempt would show that this attempted route needs work, not that GLM 5.4 is inherently poor at Code Mode.
The Code Mode behavior being tested
The documented starting environment has two package floors: logfire[agent-sandboxes]>=5.6.0 and pydantic-ai-harness[codemode]>=0.67.0. Pydantic’s example uses this configuration:
agent = Agent( 'openai:gpt-6.1-sol', tools=[list_customers, get_request_stats, list_open_tickets], capabilities=[ CodeMode( monty_sandbox=logfire.agent_sandboxes, ) ],)This is the documented baseline, not a GLM configuration example. Its model string is openai:gpt-6.1-sol, and replacing that string with Vercel’s identifier would be an experiment, not a documented migration.
The evaluation surface is nevertheless clear. Pydantic says Code Mode writes type stubs from the supplied tools, checks each generated script against those stubs, sends errors back to the model, and records every run in Logfire. Each stage answers a different qualification question:
- Stub checking: Did the model generate Python that conforms to the exposed tool interfaces?
- Error return: When checking fails, can the model produce a valid correction within the execution budget?
- Task execution: Did a valid script actually compute the required result?
- Run recording: Can the result be joined with evaluation labels and reviewed later?
There is also a containment boundary that belongs in the test design. Pydantic’s documentation describes the user’s tools as running in the user’s process, while only the generated script runs in the sandbox. The whole agent and its tool side effects therefore should not be described as sandbox-contained.
For qualification, use synthetic or staging tools with controlled outputs and no production writes. A stub-checked script can still select the wrong tool, use a valid argument with the wrong business meaning, perform an incorrect transformation, or return an unsupported conclusion. Interface validity is necessary, but it is not task correctness.
A task suite that exposes the right failures
The following suite is a proposed harness, not a reported GLM experiment. It assumes deterministic test tools, known expected outputs, and fixed prompts and fixtures. The tool names in Pydantic’s example can inspire equivalent tests in your own system, but the expected results must come from your fixtures rather than from assumptions about those tools’ behavior.
Start with five task families:
- Single-tool retrieval. One read-only tool returns a known fixture, and the final response must match it exactly. This isolates basic script and argument handling.
- Dependent composition. One tool’s output is needed to select or construct a later call. This tests whether the generated program preserves dependencies instead of merely producing plausible-looking Python.
- Aggregation or transformation. The script must process a returned collection and produce a predetermined result. This separates interface validity from programming logic.
- Empty or incomplete input. A fixture returns no matching records or only part of the available information. The expected behavior should be defined in advance, including when the agent must state that the answer is unavailable.
- Error recovery. Whenever a generated script fails stub checking, retain that case and score whether the error-return loop produces a valid, correct run within the fixed budget. If no run produces a stub error, mark recovery as not exercised, rather than passing it automatically.
Repeat every task a number of times chosen before the trial and keep that count constant across compared configurations. Pydantic’s three-run example is documentation of one result, not a statistical standard for production qualification.
If the same candidate route supports ordinary tool calling, run the same tasks through that path as a baseline. The useful comparison is not “GLM versus an unspecified coding agent.” It is GLM with Code Mode versus GLM with plain tool calls, or versus your existing qualified model, under the same fixtures and limits.
A scorecard that does not hide retries or review work
For an execution budget, I would borrow a concrete starting point from the independent MCP-gateway study: up to three executions per task. That study’s agent has search() and execute() meta-tools, and execute() runs scripts in an rlimit-restricted subprocess rather than a container.
This is an analogy, not a Pydantic specification. Its subprocess is not the documented Logfire agent-sandbox path, and its three-execution cap is not evidence of a Logfire default. The value of the study here is that it makes the retry budget explicit. Your suite should do the same, counting all executions and failing runs that exceed the chosen limit.
| Gate or metric | What to record | How it affects the decision |
|---|---|---|
| Route configuration | Exact model string or gateway route, package and prompt versions, serving-model evidence where available, and the smoke-test outcome | If the candidate cannot be configured, stop. Do not substitute chat results or count a fallback model’s success |
| First-pass script validity | Proportion of runs whose first generated script passes the tool-derived stub check | Shows how often the model starts cleanly, rather than hiding initial failures behind repairs |
| Eventual validity and recovery | Whether a valid script appears within the execution budget; among runs with stub errors, whether the returned error leads to a correction | Distinguishes reliable first-pass generation from dependence on debugging loops |
| Task completion | Correct final result for every run, counting invalid and over-budget runs as failures | Establishes whether interface-valid programs actually do the work |
| Executions and retries | Total executions per task and the distribution across repeated runs | Prevents an eventual success from concealing an unacceptable retry cost |
| Tokens and caching | Provider-reported usage across attempts, plus caching information only where the route returns it | Supports a route-specific cost comparison without assuming cache behavior or importing Pydantic’s OpenAI token result |
| Review burden | Reviewer time, scripts needing correction or rejection, and whether the reviewer would permit unattended execution | Shows whether generated-code review fits the team’s actual operating procedure |
Token totals should include every model attempt associated with the task where the provider exposes that information. State what the returned usage covers and mark unavailable fields as missing. Do not convert missing cache data into zero, or turn a context-window specification into a cost estimate.
Logfire provides native SDKs for Python, TypeScript, and Rust, standard OpenTelemetry elsewhere, and a Postgres-compatible SQL plane that Pydantic says can span a trace, an eval result, and a prompt version. That gives the qualification harness a useful audit substrate. It does not automatically supply expected answers, correctness judgments, or reviewer time; those remain evaluation data your team must define.
The broader reliability literature supports this separation. Engineering Reliable Coding Agents organizes its versioned catalog into 206 reliability records, including 193 gated practices and 13 research leads, with attention to the system around the model. It does not validate this particular suite or provide GLM evidence. Its relevant contribution is the promotion discipline: model capability is one input to an engineering gate, not the gate itself.
When the route earns a trial
GLM 5.4 should advance only when the exact Pydantic AI route configures successfully and the candidate completes the representative fixture tasks within the declared execution budget. First-pass validity, recovery, correctness, tokens, and review time should remain visible as separate results. A high aggregate completion rate should not erase a failure whose consequences the workflow cannot tolerate.
I would begin any successful qualification with read-only, disposable workflows and known outputs. If the intended deployment requires an expert to inspect every generated script before execution, a token reduction alone would not justify switching; the review time and correction rate have to fit that operating model. For write-capable or high-consequence tools, passing stub checks is not enough to approve unattended execution, especially when the tools themselves run in the user’s process.
A documented GLM configuration or a successful smoke test would change the gate 0 assessment, but only that assessment. Repeated independent Code Mode results across varied tasks would change the performance assessment. Neither is on record: Vercel’s listing gives a model name for its own gateway, not a Pydantic AI configuration, and Pydantic’s Code Mode documentation reports no GLM runs. Until your own instrumented suite supplies the missing runs, the Vercel listing justifies a controlled qualification experiment, not a routing change.
Frequently Asked Questions
What are the minimum package versions required for the Code Mode environment?
The documented starting environment has two package floors: logfire[agent-sandboxes]>=5.6.0 and pydantic-ai-harness[codemode]>=0.67.0.
What is the model name for GLM 5.4 on Vercel AI Gateway?
On Vercel AI Gateway, its model name is zai/glm-5.4.
What is the recommended execution budget for testing?
For an execution budget, I would borrow a concrete starting point from the independent MCP-gateway study: up to three executions per task.
Join the discussion
Share a useful perspective or ask a question about this article.