DoublewordDoubleword
Get started

Mastra

Mastra uses the Vercel AI SDK under the hood. Use the @doubleword/vercel-ai provider package to point it at the Doubleword API.

Install

npm install mastra @mastra/core @doubleword/vercel-ai

Configure

import { Agent } from "@mastra/core/agent";
import { createDoubleword } from "@doubleword/vercel-ai";

const doubleword = createDoubleword({
  apiKey: "{{apiKey}}",
});

const agent = new Agent({
  name: "my-agent",
  instructions: "You are a helpful assistant.",
  model: doubleword("{{selectedModel.id}}"),
});

const result = await agent.generate("Say hello.");
console.log(result.text);

The @doubleword/vercel-ai package automatically configures the base URL and supports credential resolution from the DOUBLEWORD_API_KEY environment variable.

Prompt caching

Enable caching on the provider and the agent's instructions are cached as a reusable prefix:

import { Agent } from "@mastra/core/agent";
import { createDoubleword } from "@doubleword/vercel-ai";

const doubleword = createDoubleword({
  apiKey: "{{apiKey}}",
  cache: { ttl: "1h" },
});

const agent = new Agent({
  name: "my-agent",
  instructions: "…large, stable instructions…",
  model: doubleword("{{selectedModel.id}}"),
});

const { text, usage } = await agent.generate("What is 2 + 2?");
console.log(usage.cachedInputTokens);

Override or disable caching for a single call with providerOptions.doubleword.cacheControl (e.g. { ttl: "5m", scope: "lastUser" }, or false to skip it). See the prompt caching guide.

Batch pricing

For background workloads where latency is not critical, use createDoublewordBatch to transparently route requests through Doubleword's Batch API at reduced cost:

npm install mastra @mastra/core @doubleword/vercel-ai autobatcher
import { Agent } from "@mastra/core/agent";
import { createDoublewordBatch } from "@doubleword/vercel-ai";

const doubleword = createDoublewordBatch({
  apiKey: "{{apiKey}}",
});

const agent = new Agent({
  name: "my-agent",
  instructions: "You are a helpful assistant.",
  model: doubleword("{{selectedModel.id}}"),
});

const result = await agent.generate("Summarize this document.");
console.log(result.text);
await doubleword.close();

Concurrent calls are automatically collected into batch submissions, cutting inference costs by up to 90%. The interface is identical to the real-time provider — only streaming is not supported.