Skip to main content

NEAR AI Cloud logoNEAR AI Cloud

Access 33 NEAR AI Cloud models through Mastra's model router. Authentication is handled automatically using the NEARAI_API_KEY environment variable.

Learn more in the NEAR AI Cloud documentation.

.env
NEARAI_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: "nearai/Qwen/Qwen3-30B-A3B-Instruct-2507"
});

// 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);
}
info

Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the NEAR AI Cloud documentation for details.

Models
Direct link to Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
nearai/anthropic/claude-haiku-4-5200K$1$5
nearai/anthropic/claude-opus-4-6200K$5$25
nearai/anthropic/claude-opus-4-71.0M$5$25
nearai/anthropic/claude-sonnet-4-5200K$3$16
nearai/anthropic/claude-sonnet-4-61.0M$3$15
nearai/black-forest-labs/FLUX.2-klein-4B128K$1$1
nearai/google/gemini-2.5-flash1.0M$0.30$3
nearai/google/gemini-2.5-flash-lite1.0M$0.10$0.40
nearai/google/gemini-2.5-pro1.0M$1$10
nearai/google/gemini-3.1-flash-lite1.0M$0.25$2
nearai/openai/gpt-4.11.0M$2$8
nearai/openai/gpt-4.1-mini1.0M$0.40$2
nearai/openai/gpt-4.1-nano1.0M$0.10$0.40
nearai/openai/gpt-5400K$1$10
nearai/openai/gpt-5-mini400K$0.25$2
nearai/openai/gpt-5-nano400K$0.05$0.40
nearai/openai/gpt-5.1400K$1$10
nearai/openai/gpt-5.2400K$2$16
nearai/openai/gpt-5.41.1M$3$15
nearai/openai/gpt-5.4-mini400K$0.75$5
nearai/openai/gpt-5.4-nano400K$0.20$1
nearai/openai/gpt-5.51.1M$5$30
nearai/openai/gpt-oss-120b131K$0.15$0.55
nearai/openai/o3200K$2$8
nearai/openai/o3-mini200K$1$4
nearai/openai/o4-mini200K$1$4
nearai/openai/whisper-large-v3448$0.01
nearai/Qwen/Qwen3-30B-A3B-Instruct-2507262K$0.15$0.55
nearai/Qwen/Qwen3-Embedding-0.6B41K$0.01
nearai/Qwen/Qwen3-Reranker-0.6B41K$0.01$0.01
nearai/Qwen/Qwen3-VL-30B-A3B-Instruct256K$0.15$0.55
nearai/Qwen/Qwen3.5-122B-A10B131K$0.40$3
nearai/zai-org/GLM-5.1-FP8203K$0.85$3
33 available models

Advanced configuration
Direct link to Advanced configuration

Custom headers
Direct link to Custom headers

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
url: "https://cloud-api.near.ai/v1",
id: "nearai/Qwen/Qwen3-30B-A3B-Instruct-2507",
apiKey: process.env.NEARAI_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

Dynamic model selection
Direct link to Dynamic model selection

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
? "nearai/zai-org/GLM-5.1-FP8"
: "nearai/Qwen/Qwen3-30B-A3B-Instruct-2507";
}
});
On this page