Skip to main content

Keln logoKeln

Access 14 Keln models through Mastra's model router. Authentication is handled automatically using the KELN_API_KEY environment variable.

Learn more in the Keln documentation.

.env
KELN_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: "keln/deepseek-ai/deepseek-v4-pro-0813"
});

// 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 Keln documentation for details.

Models
Direct link to Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
keln/deepseek-ai/deepseek-v4-pro-08131.0M$1$4
keln/deepseek-ai/deepseek-v4.1-flash1.0M$0.30$1
keln/deepseek-ai/deepseek-v4.1-flash-10171.0M$0.30$1
keln/google/gemma-4-31b-it262K$0.15$0.46
keln/minimaxai/minimax-m3.1-flash1.0M$0.15$0.60
keln/moonshotai/kimi-k31.0M$3$15
keln/moonshotai/kimi-k3.1-pro1.0M$2$10
keln/nvidia/nemotron-3-ultra-550b-a55b262K$0.80$3
keln/openai/gpt-oss-120b131K$0.15$0.60
keln/qwen/qwen3.8-2.4t-a95b1.0M$3$6
keln/qwen/qwen3.8-27b1.0M$0.50$3
keln/zai-org/glm-5.21.0M$1$4
keln/zai-org/glm-5.31.0M$1$4
keln/zai-org/glm-5.3-flash1.0M$0.15$0.50
14 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://api.keln.ai/v1",
id: "keln/deepseek-ai/deepseek-v4-pro-0813",
apiKey: process.env.KELN_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
? "keln/zai-org/glm-5.3-flash"
: "keln/deepseek-ai/deepseek-v4-pro-0813";
}
});