Use Mastra with Shannon
Give a Mastra agent a model object with Shannon's URL, key and id; streaming and tools then run on Shannon models.
- Tested Nov 7, 2026
- OpenAI Chat Completions
- About 3 min
About Mastra
Mastra is a TypeScript framework for agents, workflows, memory and retrieval, with a local dev studio. Agents take a model through its model router, which accepts any OpenAI-compatible endpoint given a URL and a key. That lets Mastra agents and workflows run on Shannon models.
What you need
- A Shannon API key
- Keys & usage
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Every snippet below follows your choice.
Set it up
-
Install Mastra
Shellnpm install @mastra/core zod -
Create an agent on Shannon
idis<any prefix>/<Shannon id>;urlis the base URL, not the chat endpoint.TypeScriptimport { Agent } from "@mastra/core/agent"; import { createTool } from "@mastra/core/tools"; import { z } from "zod"; const getWeather = createTool({ id: "get-weather", description: "Weather for a city", inputSchema: z.object({ city: z.string() }), execute: async ({ city }) => ({ weather: `Sunny, 18 C in ${city}` }), }); export const agent = new Agent({ id: "assistant", name: "assistant", instructions: "Answer briefly. Use tools for weather.", model: { id: "shannon/Kimi-K3-uncensored-NVFP4", url: "https://api.shannon-ai.com/v1", apiKey: process.env.SHANNON_API_KEY }, tools: { getWeather }, }); -
Stream and generate
TypeScriptconst stream = await agent.stream("Name three colours a cat can be."); for await (const text of stream.textStream) process.stdout.write(text); const r = await agent.generate("What is the weather in Oslo?"); console.log(r.text);
Check that it works
Send: Run the sample with SHANNON_API_KEY set.
You should see: The colours stream in, then an answer that uses the tool's weather.
Models that fit Mastra
Every id below meets what Mastra needs. The first one is the default in the snippets.
| Model id | Context window | Max output | Image input |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | Yes |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | Yes |
shannon-3 | 196,608 | 65,536 | Yes |
shannon-coder-1 | 131,072 | 65,536 | No |
Good to know
urlmust be the base URL ending in/v1; Mastra adds/chat/completions.- Add
api: "responses"to the model object to use Shannon's/v1/responsesinstead.
Tips
- Register agents in a
Mastrainstance to see them in the local studio (mastra dev). - The same model object works in workflows and memory processors that take a model.
- Pass the key in
apiKey, for example fromSHANNON_API_KEY; Mastra's docs name no variable it reads on its own for a custom endpoint.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
404 Not Found | url lacks /v1 or ends in /chat/completions. | Use https://api.shannon-ai.com/v1. |
401 | apiKey is empty. | Pass the key in apiKey. |
401 Unauthorized | The key is missing, mistyped or rotated. | Copy the key again from Keys & usage; it starts with sk-. |
context_length_exceeded / "prompt is too long" | The conversation is longer than the model's window. | Start a new chat, let the tool compact it, or pick a model with a larger window. |
insufficient_quota | Your balance cannot pay for the request. | Top up or change plan; the request is not retried by itself. |
Questions
Does Mastra work with Shannon?
Yes: an agent model { id, url, apiKey } with url: "https://api.shannon-ai.com/v1" reaches Shannon.
Do Mastra tools work?
Yes; createTool tools are sent as native tool calls.