Integrations
Mastra
Wrap Thunderbit as a Mastra tool for agents and workflows
Mastra is a TypeScript framework for AI agents and workflows. Its createTool primitive maps cleanly onto /distill.
Install
npm install @mastra/core zodDefine the tool
import { createTool } from '@mastra/core/tools';
import { z } from 'zod';
const API = 'https://openapi.thunderbit.com/openapi/v1';
const H = { Authorization: `Bearer ${process.env.THUNDERBIT_API_KEY}` };
export const readUrlTool = createTool({
id: 'read-url',
description:
'Fetch a URL and return clean Markdown for the agent to read.',
inputSchema: z.object({
url: z.string().url(),
renderMode: z.enum(['basic', 'advanced']).default('basic'),
}),
outputSchema: z.object({ markdown: z.string() }),
execute: async ({ context }) => {
const res = await fetch(`${API}/distill`, {
method: 'POST',
headers: { ...H, 'Content-Type': 'application/json' },
body: JSON.stringify(context),
});
const json = await res.json();
return { markdown: json.data.markdown };
},
});Wire into an Agent
import { Agent } from '@mastra/core/agent';
import { openai } from '@ai-sdk/openai';
export const researcher = new Agent({
name: 'researcher',
instructions: 'Use read-url to fetch any URL the user asks about.',
model: openai('gpt-4o'),
tools: { readUrlTool },
});Use in a Workflow
For multi-step pipelines, call /batch/distill from a Mastra Step and poll until COMPLETED — see Batch Job Lifecycle.