🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@mastra/openai

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons
This package has malicious versions linked to the ongoing "Mastra AI framework compromise" supply chain attack.

Affected versions:

1.0.2
View campaign page

@mastra/openai

OpenAI Agents SDK package for Mastra

unpublished
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
2.8K
209.43%
Maintainers
1
Weekly downloads
 
Created
Source

@mastra/openai

@mastra/openai connects Mastra to the OpenAI Agents SDK. Use it when you want to register an OpenAI SDK agent with Mastra and call it through Mastra-compatible generate() and stream() methods.

Installation

npm install @mastra/openai @openai/agents

Overview

The package exports OpenAISDKAgent, a Mastra Agent wrapper around the OpenAI Agents SDK run loop.

OpenAISDKAgent keeps the OpenAI SDK run loop in charge. Mastra receives compatible outputs, usage data, and tracing data for the run.

Create an OpenAI SDK agent

Pass OpenAI Agents SDK configuration through sdkOptions. OpenAISDKAgent creates the SDK agent on first use.

import { OpenAISDKAgent } from '@mastra/openai';

export const openaiAgent = new OpenAISDKAgent({
  id: 'openai-sdk-agent',
  name: 'OpenAI SDK Agent',
  description: 'Use OpenAI Agents SDK through Mastra.',
  sdkOptions: {
    name: 'Repository assistant',
    instructions: 'Answer clearly and cite the relevant files.',
    model: '__GATEWAY_OPENAI_MODEL_BASE__',
  },
});

You can also pass an existing OpenAI SDK agent when your app already creates or owns it.

import { Agent as OpenAIAgent } from '@openai/agents';
import { OpenAISDKAgent } from '@mastra/openai';

const sdkAgent = new OpenAIAgent({
  name: 'Repository assistant',
  instructions: 'Answer clearly and cite the relevant files.',
  model: '__GATEWAY_OPENAI_MODEL_BASE__',
});

export const openaiAgent = new OpenAISDKAgent({
  id: 'openai-sdk-agent',
  description: 'Use OpenAI Agents SDK through Mastra.',
  agent: sdkAgent,
});

You can register the wrapper anywhere Mastra accepts an Agent.

import { Mastra } from '@mastra/core/mastra';

export const mastra = new Mastra({
  agents: {
    openaiAgent,
  },
});

Run the agent

const result = await openaiAgent.generate('Summarize the latest changes in this repository.', {
  runId: 'openai-run',
  maxSteps: 3,
});

console.log(result.text);
const stream = await openaiAgent.stream('Review this package for test gaps.');

for await (const chunk of stream.fullStream) {
  if (chunk.type === 'text-delta') {
    process.stdout.write(chunk.payload.text);
  }
}

Configure OpenAI

OpenAISDKAgent forwards sdkOptions to the OpenAI SDK Agent constructor when agent is not provided. These include name, instructions, model, tools, handoffs, guardrails, and other OpenAI Agents SDK agent settings.

Mastra generate() and stream() execution options drive the run. maxSteps maps to OpenAI maxTurns, and abortSignal maps to OpenAI signal.

FAQs

Package last updated on 17 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts