Mastra is a TypeScript framework for AI agents and workflows. Besides its built-in providers, an agent’s model can be any OpenAI-compatible endpoint, given as an object with id and url. BroadNet Inference serves standard chat completions at https://inference.broadnet.ai/v1, so it works this way, with one catch in the model ID. BroadRouter is BroadNet’s own site; this follows Mastra’s models docs and @mastra/core 1.83.0.
Install
npm install @mastra/core zod
export BROADNET_API_KEY='your-broadnet-key'
Connect an agent
import { Agent } from "@mastra/core/agent";
const broadnet = (model: string) => ({
id: `broadnet/${model}`, // Mastra strips the first segment
url: "https://inference.broadnet.ai/v1",
apiKey: process.env.BROADNET_API_KEY,
});
export const assistant = new Agent({
id: "assistant",
name: "Assistant",
instructions: "You are a concise assistant.",
model: broadnet("broadnet/glm-5.3"), // sends broadnet/glm-5.3
});
const res = await assistant.generate("Give me three names for a Go linting tool.");
console.log(res.text);
Why the doubled prefix
Mastra’s docs say an id written as provider/model sends a bare model name to the remote, and gateway/provider/model keeps the provider in the name. BroadNet’s IDs contain a slash, so they need the longer form. In our test:
Mastra id |
Model ID BroadNet received |
|---|---|
broadnet/glm-5.3 |
glm-5.3 (wrong) |
broadnet/broadnet/glm-5.3 |
broadnet/glm-5.3 (right) |
The helper above adds the extra segment for you.
Tools
import { createTool } from "@mastra/core/tools";
import { z } from "zod";
const weather = createTool({
id: "get_weather",
description: "Get the weather for a city",
inputSchema: z.object({ city: z.string() }),
execute: async (input) => ({ city: input.city, tempC: 21 }),
});
const agent = new Agent({
id: "weather",
name: "Weather",
instructions: "Use the weather tool to answer.",
tools: { weather },
model: broadnet("broadnet/glm-5.3"),
});
Use broadnet/glm-5.3 or broadnet/qwen3.8-27b for agents with tools. BroadNet’s docs list tools and structured output for these two models only.
Streaming
const stream = await assistant.stream("Explain vector search in two sentences.");
for await (const chunk of stream.textStream) process.stdout.write(chunk);
Settings that matter
urlis the base URL, ending in/v1. Mastra adds/chat/completions.- Don’t add
api: "responses". Mastra’s docs say that switches to/v1/responses. BroadNet doesn’t list the Responses API. - Output limit. DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B reason before answering, and the reasoning counts toward the output limit. If you cap output tokens, leave 2,000 or more.
Which model to pick
| Agent | Model |
|---|---|
| Tools, structured output, workflows | broadnet/glm-5.3 |
| Tools plus image input or Arabic text | broadnet/qwen3.8-27b |
| Text-only steps on a flat-price plan | broadnet/deepseek-v4.1-flash |
Prices for every model. For the Vercel AI SDK without Mastra, see the AI SDK guide.
How we tested this
On 2026-11-15 we installed @mastra/core 1.83.0 with Node 24 and ran generate, stream and a tool agent against a local mock server that speaks BroadNet’s chat-completions shape and returns tool calls. We read the logged requests. Every call went to /v1/chat/completions with a Bearer key from apiKey. That is how we found the prefix rule in the table above. We had no BroadNet key, so we did not test real model output.
Troubleshooting
- 404 or model not found. The model ID probably lost its prefix. Write the
idasbroadnet/broadnet/glm-5.3. Then check thaturlends in/v1. Paid models need a top-up; the $5 credit covers onlybroadnet/gemma-4-26b-a4band the two Transcribe models. - 401.
BROADNET_API_KEYisn’t set in the process, or the key is wrong or out of allowance. - Empty replies. Reasoning used the output budget. Why answers come back empty.
- 429 in workflows with parallel steps. A pay-as-you-go key allows 30 requests a minute and 4 in flight; a plan session runs one at a time. See errors and retries.
