NEAR 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.
ModelsDirect link to Models
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|---|---|
nearai/anthropic/claude-haiku-4-5 | 200K | $1 | $5 | |||||
nearai/anthropic/claude-opus-4-6 | 200K | $5 | $25 | |||||
nearai/anthropic/claude-opus-4-7 | 1.0M | $5 | $25 | |||||
nearai/anthropic/claude-sonnet-4-5 | 200K | $3 | $16 | |||||
nearai/anthropic/claude-sonnet-4-6 | 1.0M | $3 | $15 | |||||
nearai/black-forest-labs/FLUX.2-klein-4B | 128K | $1 | $1 | |||||
nearai/google/gemini-2.5-flash | 1.0M | $0.30 | $3 | |||||
nearai/google/gemini-2.5-flash-lite | 1.0M | $0.10 | $0.40 | |||||
nearai/google/gemini-2.5-pro | 1.0M | $1 | $10 | |||||
nearai/google/gemini-3.1-flash-lite | 1.0M | $0.25 | $2 | |||||
nearai/openai/gpt-4.1 | 1.0M | $2 | $8 | |||||
nearai/openai/gpt-4.1-mini | 1.0M | $0.40 | $2 | |||||
nearai/openai/gpt-4.1-nano | 1.0M | $0.10 | $0.40 | |||||
nearai/openai/gpt-5 | 400K | $1 | $10 | |||||
nearai/openai/gpt-5-mini | 400K | $0.25 | $2 | |||||
nearai/openai/gpt-5-nano | 400K | $0.05 | $0.40 | |||||
nearai/openai/gpt-5.1 | 400K | $1 | $10 | |||||
nearai/openai/gpt-5.2 | 400K | $2 | $16 | |||||
nearai/openai/gpt-5.4 | 1.1M | $3 | $15 | |||||
nearai/openai/gpt-5.4-mini | 400K | $0.75 | $5 | |||||
nearai/openai/gpt-5.4-nano | 400K | $0.20 | $1 | |||||
nearai/openai/gpt-5.5 | 1.1M | $5 | $30 | |||||
nearai/openai/gpt-oss-120b | 131K | $0.15 | $0.55 | |||||
nearai/openai/o3 | 200K | $2 | $8 | |||||
nearai/openai/o3-mini | 200K | $1 | $4 | |||||
nearai/openai/o4-mini | 200K | $1 | $4 | |||||
nearai/openai/whisper-large-v3 | 448 | $0.01 | — | |||||
nearai/Qwen/Qwen3-30B-A3B-Instruct-2507 | 262K | $0.15 | $0.55 | |||||
nearai/Qwen/Qwen3-Embedding-0.6B | 41K | $0.01 | — | |||||
nearai/Qwen/Qwen3-Reranker-0.6B | 41K | $0.01 | $0.01 | |||||
nearai/Qwen/Qwen3-VL-30B-A3B-Instruct | 256K | $0.15 | $0.55 | |||||
nearai/Qwen/Qwen3.5-122B-A10B | 131K | $0.40 | $3 | |||||
nearai/zai-org/GLM-5.1-FP8 | 203K | $0.85 | $3 |
Advanced configurationDirect link to Advanced configuration
Custom headersDirect 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 selectionDirect 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";
}
});