Phala
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.
ModelsDirect link to Models
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|---|---|
phala/deepseek/deepseek-v3.2 | 164K | $1 | $1 | |||||
phala/deepseek/deepseek-v4-flash-0731 | 1.0M | $0.44 | $1 | |||||
phala/deepseek/deepseek-v4.1-flash-1017 | 1.0M | $0.75 | $2 | |||||
phala/google/gemma-4-31b-it | 262K | $0.15 | $0.46 | |||||
phala/meta-llama/llama-3.3-70b-instruct | 131K | $2 | $2 | |||||
phala/moonshotai/kimi-k2.6 | 262K | $1 | $5 | |||||
phala/moonshotai/kimi-k3 | 1.0M | $3 | $15 | |||||
phala/openai/gpt-oss-120b | 131K | $0.15 | $0.60 | |||||
phala/qwen/qwen-2.5-7b-instruct | 33K | $0.10 | $0.20 | |||||
phala/qwen/qwen3-vl-30b-a3b-instruct | 128K | $0.20 | $0.70 | |||||
phala/qwen/qwen3.5-27b | 262K | $0.30 | $2 | |||||
phala/qwen/qwen3.5-397b-a17b | 262K | $0.55 | $4 | |||||
phala/qwen/qwen3.6-27b | 262K | $0.32 | $3 | |||||
phala/qwen/qwen3.6-35b-a3b | 262K | $0.20 | $1 | |||||
phala/qwen/qwen3.8-27b | 1.0M | $0.20 | $3 | |||||
phala/z-ai/glm-5.1 | 203K | $1 | $4 | |||||
phala/z-ai/glm-5.2 | 1.0M | $1 | $3 | |||||
phala/z-ai/glm-5.3 | 1.0M | $1 | $4 | |||||
phala/z-ai/glm-5.3-flash | 1.0M | $0.15 | $0.50 |
Model availability, capabilities, context windows, and pricing are sourced from models.dev and may change.
Advanced configurationDirect link to Advanced configuration
Custom headersDirect 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 selectionDirect 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";
}
});