본문으로 건너뛰기

OpenAI logo오픈AI

Mastra의 Model 라우터를 통해 47개의 OpenAI Model에 액세스하세요. 인증은 다음을 사용하여 자동으로 처리됩니다.OPENAI_API_KEY environment variable.

자세한 내용은 다음에서 확인하세요.OpenAI documentation.

.env
OPENAI_API_KEY=your-api-key
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";

const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "openai/chatgpt-image-latest"
});

// Generate a response
const response = await agent.generate("Hello!");

// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
console.log(chunk);
}

Model
Model에 대한 직접 링크

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
openai/chatgpt-image-latest
openai/gpt-4.11.0M$2$8
openai/gpt-4.1-mini1.0M$0.40$2
openai/gpt-4o128K$3$10
openai/gpt-4o-2024-08-06128K$3$10
openai/gpt-4o-2024-11-20128K$3$10
openai/gpt-4o-mini128K$0.15$0.60
openai/gpt-5400K$1$10
openai/gpt-5-mini400K$0.25$2
openai/gpt-5-nano400K$0.05$0.40
openai/gpt-5-pro400K$15$120
openai/gpt-5.1400K$1$10
openai/gpt-5.2400K$2$14
openai/gpt-5.2-chat-latest128K$2$14
openai/gpt-5.2-pro400K$21$168
openai/gpt-5.3-chat-latest128K$2$14
openai/gpt-5.3-codex400K$2$14
openai/gpt-5.3-codex-spark128K$2$14
openai/gpt-5.41.1M$3$15
openai/gpt-5.4-mini400K$0.75$5
openai/gpt-5.4-nano400K$0.20$1
openai/gpt-5.4-pro1.1M$30$180
openai/gpt-5.51.1M$5$30
openai/gpt-5.5-pro1.1M$30$180
openai/gpt-5.61.1M$5$30
openai/gpt-5.6-luna1.1M$0.20$1
openai/gpt-5.6-sol1.1M$5$30
openai/gpt-5.6-terra1.1M$2$12
openai/gpt-image-1-mini
openai/gpt-image-1.5
openai/gpt-image-2$5$30
openai/gpt-realtime-2.1128K$4$24
openai/o3200K$2$8
openai/o3-pro200K$20$80
openai/text-embedding-3-large8K$0.13
openai/text-embedding-3-small8K$0.02
openai/text-embedding-ada-0028K$0.10
37 available models

고급 구성
고급 구성에 대한 직접 링크

맞춤 헤더
맞춤 헤더에 대한 직접 링크

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
id: "openai/chatgpt-image-latest",
apiKey: process.env.OPENAI_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

동적 Model 선택
동적 Model 선택에 대한 직접 링크

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "openai/text-embedding-ada-002"
: "openai/chatgpt-image-latest";
}
});

공급자 옵션
공급자 옵션에 대한 직접 링크

OpenAI는 다음을 통해 다음과 같은 공급자별 옵션을 지원합니다.providerOptions parameter:

const response = await agent.generate("Hello!", {
providerOptions: {
openai: {
// See available options in the table below
}
}
});

사용 가능한 옵션
사용 가능한 옵션에 대한 직접 링크

conversation?:

string | null | undefined

include?:

("web_search_call.results" | "file_search_call.results" | "message.output_text.logprobs" | "reasoning.encrypted_content")[] | null | undefined

instructions?:

string | null | undefined

logprobs?:

number | boolean | undefined

maxToolCalls?:

number | null | undefined

metadata?:

any

parallelToolCalls?:

boolean | null | undefined

previousResponseId?:

string | null | undefined

promptCacheKey?:

string | null | undefined

promptCacheOptions?:

{ mode?: "explicit" | "implicit" | undefined; ttl?: "30m" | undefined; } | undefined

promptCacheRetention?:

"in_memory" | "24h" | null | undefined

reasoningEffort?:

string | null | undefined

reasoningMode?:

"standard" | "pro" | undefined

reasoningContext?:

"auto" | "current_turn" | "all_turns" | undefined

reasoningSummary?:

string | null | undefined

safetyIdentifier?:

string | null | undefined

serviceTier?:

"auto" | "default" | "flex" | "priority" | null | undefined

store?:

boolean | null | undefined
OpenAI가 Model 학습을 위해 사용자의 API 요청을 저장할지 여부를 제어합니다. 조직에서 데이터 보존 안 함을 활성화한 경우 반드시 "false"로 설정해야 합니다. 참조: https://platform.openai.com/docs/guides/your-data#zero-data-retention

passThroughUnsupportedFiles?:

boolean | undefined

strictJsonSchema?:

boolean | null | undefined

textVerbosity?:

"low" | "medium" | "high" | null | undefined

truncation?:

"auto" | "disabled" | null | undefined

user?:

string | null | undefined

systemMessageMode?:

"remove" | "system" | "developer" | undefined

forceReasoning?:

boolean | undefined

allowedTools?:

{ toolNames: string[]; mode?: "auto" | "required" | undefined; } | undefined

직접 Provider 설치
직접 Provider 설치에 대한 직접 링크

이 Provider는 Mastra Model 라우터 문자열을 사용하는 대신 독립 실행형 패키지로 직접 설치할 수도 있습니다. 자세한 내용은 패키지 문서를 참조하세요.

npm install @ai-sdk/openai

자세한 공급자별 설명서는 다음을 참조하세요.AI SDK OpenAI provider docs.