Generate Text with Claude
Many developers need to use different language models but don’t want to learn multiple APIs. Mastra provides a unified interface for working with various LLM providers, handling the complexity of different API implementations. This example shows how to use Anthropic’s Claude model through the same interface used for other providers.
import { Mastra } from "@mastra/core";
const mastra = new Mastra();
const llm = mastra.LLM({
provider: "ANTHROPIC",
name: "claude-3-5-sonnet-20241022",
});
const result = await llm.generate("Who invented the submarine?");
console.log(result.text);
View Example on GitHub