xxapi
Access 16 xxapi models through Mastra's model router. Authentication is handled automatically using the XXAPI_API_KEY environment variable.
Learn more in the xxapi documentation.
.env
XXAPI_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: "xxapi/claude-fable-5"
});
// 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 xxapi documentation for details.
ModelsDirect link to Models
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|---|---|
xxapi/claude-fable-5 | 1.0M | $4 | $19 | |||||
xxapi/claude-fable-5-1 | 1.0M | $4 | $19 | |||||
xxapi/claude-haiku-4-5 | 200K | $0.38 | $2 | |||||
xxapi/claude-haiku-4-5-20251001 | 200K | $0.38 | $2 | |||||
xxapi/claude-opus-4-7 | 1.0M | $2 | $10 | |||||
xxapi/claude-opus-4-8 | 1.0M | $2 | $10 | |||||
xxapi/claude-opus-5 | 1.0M | $2 | $10 | |||||
xxapi/claude-opus-5-5 | 1.0M | $2 | $8 | |||||
xxapi/claude-sonnet-5 | 1.0M | $0.77 | $4 | |||||
xxapi/claude-sonnet-5-5 | 1.0M | $0.77 | $4 | |||||
xxapi/gpt-5.6-luna | 1.1M | $0.01 | $0.07 | |||||
xxapi/gpt-5.6-sol | 1.1M | $0.25 | $1 | |||||
xxapi/gpt-5.6-terra | 1.1M | $0.12 | $0.74 | |||||
xxapi/gpt-6-astra | 1.1M | $0.62 | $3 | |||||
xxapi/gpt-6-sol | 1.1M | $0.12 | $0.62 | |||||
xxapi/gpt-6.1-sol | 1.1M | $0.12 | $0.62 |
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://xxapi.ai/v1",
id: "xxapi/claude-fable-5",
apiKey: process.env.XXAPI_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
? "xxapi/gpt-6.1-sol"
: "xxapi/claude-fable-5";
}
});