Mastra

Mastra agents with an OpenAI-compatible uncensored API

Give a Mastra agent an Abliterator model with the { id, url, apiKey } model config, stream replies with agent.stream, and add tools built with createTool.

Reviewed MastraTypeScript

Quick answer

Set the agent's model to { id: "abliterator/kimi-k3.1-pro-abliterated", url: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY }. Mastra does not read an API key from the environment for url models, so pass apiKey yourself.

Mastra resolves models through its model router. For a single OpenAI-compatible endpoint you skip the router's provider list and give the agent a config object with a url, as Mastra's models guide describes. These snippets were type-checked with tsc --strict and run on Node 22 with @mastra/core 1.86.

Install

npm install @mastra/core zod
export ABL_API_KEY="sk-abl-v1-..."

Create an agent on Abliterator

import { Agent } from "@mastra/core/agent";

const analyst = new Agent({
  id: "soc-analyst",
  name: "SOC analyst",
  instructions: "You are a tier-2 SOC analyst. Answer with concrete next steps.",
  model: {
    id: "abliterator/kimi-k3.1-pro-abliterated",
    url: "https://abliterator.ai/v1",
    apiKey: process.env.ABL_API_KEY,
  },
});

const result = await analyst.generate(
  "An EDR alert shows rundll32 loading a DLL from a user's Downloads folder. What do I check first?",
);
console.log(result.text);
console.log(result.usage);

url is the base URL, not the /chat/completions route. The equivalent long form is { providerId: "abliterator", modelId: "kimi-k3.1-pro-abliterated", url, apiKey }, which avoids any doubt about where the model name starts.

Streaming

agent.stream() returns an object whose textStream yields text deltas:

import { Agent } from "@mastra/core/agent";

const writer = new Agent({
  id: "report-writer",
  name: "Report writer",
  instructions: "You write clear findings for pentest reports.",
  model: { id: "abliterator/deepseek-v4.1-flash-abliterated", url: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY },
});

const stream = await writer.stream("Write the finding for a stored XSS in a support-ticket comment field.");
for await (const delta of stream.textStream) {
  process.stdout.write(delta);
}
console.log("\n", await stream.usage);

Tools with createTool

createTool takes Zod schemas for input and output. The agent calls the tool, gets the result and continues, up to maxSteps:

import { Agent } from "@mastra/core/agent";
import { createTool } from "@mastra/core/tools";
import { z } from "zod";

const checkHash = createTool({
  id: "check-hash",
  description: "Look up a file hash in the internal malware repository.",
  inputSchema: z.object({ sha256: z.string() }),
  outputSchema: z.object({ verdict: z.string(), family: z.string(), firstSeen: z.string() }),
  execute: async ({ sha256 }) => ({
    verdict: sha256.startsWith("e3b0") ? "malicious" : "unknown",
    family: "commodity infostealer",
    firstSeen: "2026-10-30",
  }),
});

const triage = new Agent({
  id: "malware-triage",
  name: "Malware triage",
  instructions: "Check every hash with the check-hash tool before giving a verdict.",
  model: { id: "abliterator/kimi-k3.1-pro-abliterated", url: "https://abliterator.ai/v1", apiKey: process.env.ABL_API_KEY },
  tools: { checkHash },
});

const answer = await triage.generate(
  "Is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 safe to allowlist?",
  { maxSteps: 4 },
);
console.log(answer.text);
console.log(answer.toolCalls.map((c) => c.payload.toolName));

Register agents on a Mastra instance (new Mastra({ agents: { triage } })) to serve them over Mastra's HTTP server or inspect them in Mastra Studio; the model config stays the same.

Troubleshooting

  • 401 from Abliterator. apiKey was not set on the model config. Mastra does not fall back to an environment variable for url models.
  • 404 Not Found. url ends in /chat/completions, or lacks /v1. Use https://abliterator.ai/v1.
  • The model name Abliterator receives looks wrong. Check the id: everything after the first / is sent as the model. Use providerId and modelId to make it explicit.
  • Provider options have no effect. Options under a providerOptions key that does not match the provider half of id (abliterator here) are dropped without a warning.
  • Memory with semantic recall fails. Semantic recall needs an embedding model, and Abliterator has no embeddings endpoint. Configure an embedder from another provider or use memory without semantic recall.

Frequently asked questions

What goes in the id of a Mastra url model?

A provider/model pair. Mastra sends the part after the first slash as the model name, so "abliterator/kimi-k3.1-pro-abliterated" requests kimi-k3.1-pro-abliterated from Abliterator. The provider half is a label you choose; it also becomes the providerOptions key.

Does Mastra use Chat Completions or the Responses API for a url model?

Chat Completions. The api field defaults to "chat"; only set api: "responses" for servers that implement /v1/responses, which Abliterator does not.

How many tool steps will a Mastra agent take?

Up to maxSteps, which is 5 when unset. Pass maxSteps to generate or stream, or set it in the agent's defaultOptions, if your tool chains need more.