BroadRouter

Use Mastra agents with BroadNet Inference

Updated

In a Mastra Agent, set model to an object with url https://inference.broadnet.ai/v1, apiKey from BROADNET_API_KEY and id broadnet/broadnet/glm-5.3. Mastra treats the first part of the id as a provider name and strips it, so the doubled prefix sends broadnet/glm-5.3 to BroadNet. Custom URLs use chat completions by default. Use GLM 5.3 or Qwen3.8 27B for tools.

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

  • url is 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 id as broadnet/broadnet/glm-5.3. Then check that url ends in /v1. Paid models need a top-up; the $5 credit covers only broadnet/gemma-4-26b-a4b and the two Transcribe models.
  • 401. BROADNET_API_KEY isn’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.

Questions

Why does Mastra send glm-5.3 instead of broadnet/glm-5.3?

Mastra reads the model id as provider/model and sends only the part after the first slash. With id broadnet/glm-5.3 it sent glm-5.3 in our test, which BroadNet won't recognise. Write the id as broadnet/broadnet/glm-5.3.

Should the Mastra url be the base URL or the chat completions URL?

The base URL. Mastra's docs say to use the base URL of the OpenAI-compatible endpoint, so use https://inference.broadnet.ai/v1 without /chat/completions.

Does Mastra use the Responses API with a custom URL?

Not by default. Mastra's docs say custom endpoints use chat completions unless you add api set to responses. Don't add it for BroadNet, which serves chat completions.

Do Mastra tools work on BroadNet?

Yes, on a model BroadNet lists with tools, GLM 5.3 or Qwen3.8 27B. In our mock test the agent sent the tool schema, ran the tool and returned the result.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity