Skip to main content

Phala logoPhala

Access 19 Phala models through Mastra's model router. Authentication is handled automatically using the PHALA_AI_API_KEY environment variable.

Learn more in the Phala documentation.

.env
PHALA_AI_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: "phala/deepseek/deepseek-v3.2"
});

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

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

Models
Direct link to Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
phala/deepseek/deepseek-v3.2164K$1$1
phala/deepseek/deepseek-v4-flash-07311.0M$0.44$1
phala/deepseek/deepseek-v4.1-flash-10171.0M$0.75$2
phala/google/gemma-4-31b-it262K$0.15$0.46
phala/meta-llama/llama-3.3-70b-instruct131K$2$2
phala/moonshotai/kimi-k2.6262K$1$5
phala/moonshotai/kimi-k31.0M$3$15
phala/openai/gpt-oss-120b131K$0.15$0.60
phala/qwen/qwen-2.5-7b-instruct33K$0.10$0.20
phala/qwen/qwen3-vl-30b-a3b-instruct128K$0.20$0.70
phala/qwen/qwen3.5-27b262K$0.30$2
phala/qwen/qwen3.5-397b-a17b262K$0.55$4
phala/qwen/qwen3.6-27b262K$0.32$3
phala/qwen/qwen3.6-35b-a3b262K$0.20$1
phala/qwen/qwen3.8-27b1.0M$0.20$3
phala/z-ai/glm-5.1203K$1$4
phala/z-ai/glm-5.21.0M$1$3
phala/z-ai/glm-5.31.0M$1$4
phala/z-ai/glm-5.3-flash1.0M$0.15$0.50
19 available models

Model availability, capabilities, context windows, and pricing are sourced from models.dev and may change.

Advanced configuration
Direct link to Advanced configuration

Custom headers
Direct link to Custom headers

src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";

const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
url: "https://inference.phala.com/v1",
id: "phala/deepseek/deepseek-v3.2",
apiKey: process.env.PHALA_AI_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

Dynamic model selection
Direct link to Dynamic model selection

src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";

const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "phala/z-ai/glm-5.3-flash"
: "phala/deepseek/deepseek-v3.2";
}
});