Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Error Handling

The Mastra Client SDK includes built-in retry mechanism and error handling capabilities.

Error HandlingDirect link to Error Handling

All API methods can throw errors that you can catch and handle:

try {
const agent = mastraClient.getAgent("agent-id");
const response = await agent.generate({
messages: [{ role: "user", content: "Hello" }],
});
} catch (error) {
console.error("An error occurred:", error.message);
}

On this page