> ## Documentation Index
> Fetch the complete documentation index at: https://docs.octen.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Mastra

> Give a Mastra agent Octen search APIs and Extract.

For AI agents: [docs.octen.ai/integrations/mastra.md](https://docs.octen.ai/integrations/mastra.md)

[Mastra](https://mastra.ai) agents accept the Octen tools for the [Vercel AI SDK](https://docs.octen.ai/integrations/vercel-ai-sdk.md), from `@octen.ai/ai-sdk-tools`.

> [card] [Get API Key](https://octen.ai/platform/api-keys)
>
> Create a key from the API Platform.

> [card] [npm](https://www.npmjs.com/package/@octen.ai/ai-sdk-tools)
>
> The `@octen.ai/ai-sdk-tools` package.

## Install

Requires Node.js 22.13+.

```bash theme={null}
npm install @mastra/core @octen.ai/ai-sdk-tools ai zod
```

## Quick Start

Set your Octen and OpenAI API keys:

```bash theme={null}
export OCTEN_API_KEY="your-api-key"
export OPENAI_API_KEY="your-openai-api-key"
```

Run an agent that answers with Octen Web Search and News Search:

```typescript theme={null}
import { Agent, type ToolsInput } from "@mastra/core/agent";
import { octenNewsSearch, octenWebSearch } from "@octen.ai/ai-sdk-tools";

const agent = new Agent({
  id: "research-agent",
  name: "Research Agent",
  instructions: "Answer with current information. Search when you need facts, and cite your sources.",
  model: "openai/gpt-5.4",
  tools: {
    webSearch: octenWebSearch(),
    newsSearch: octenNewsSearch(),
  } as unknown as ToolsInput,
});

const result = await agent.generate("What changed in the latest Node.js LTS release?");
console.log(result.text);
```

The `as unknown as ToolsInput` cast is for TypeScript only: the AI SDK tool type does not match Mastra's `ToolsInput` type.

See [Vercel AI SDK](https://docs.octen.ai/integrations/vercel-ai-sdk.md#tools) for all ten tools and their options.

## Use Auto Search

Skip the tool loop and let Octen run the searches server-side with [Auto Search](https://docs.octen.ai/capabilities/auto-search.md). Point the model at the Octen base URL and enable the built-in `octen_search` tool. Your Octen API key is the only key you need.

Install the AI SDK provider for OpenAI-compatible APIs:

```bash theme={null}
npm install @ai-sdk/openai-compatible
```

Run the agent:

```typescript theme={null}
import { Agent } from "@mastra/core/agent";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const octen = createOpenAICompatible({
  name: "octen",
  baseURL: "https://api.octen.ai/v1",
  apiKey: process.env.OCTEN_API_KEY,
  transformRequestBody: (body) => ({ ...body, tools: [{ type: "octen_search" }] }),
});

const agent = new Agent({
  id: "research-agent",
  name: "Research Agent",
  instructions: "Answer with current information and cite your sources.",
  model: octen("openai/gpt-5.4"),
});

const result = await agent.generate("What happened in AI this week?");
console.log(result.text);
```

***

Last modified on November 24, 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.