Skip to content

Commit fa9339d

Browse files
committed
use any ai-sdk llm provider
1 parent da073e0 commit fa9339d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sources/platform/integrations/ai/mastra.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This guide demonstrates how to integrate Apify Actors with Mastra by building an
3131
### Prerequisites
3232

3333
- _Apify API token_: To use Apify Actors, you need an Apify API token. Learn how to obtain it in the [Apify documentation](https://docs.apify.com/platform/integrations/api).
34-
- _OpenAI API key_: To power the agents, you need an OpenAI API key. Get one from the [OpenAI platform](https://platform.openai.com/account/api-keys).
34+
- _LLM provider API key_: To power the agents, you need an LLM provider API key. For example, get one from the [OpenAI](https://platform.openai.com/account/api-keys) or [Anthropic](https://console.anthropic.com/settings/keys).
3535
- _Node.js_: Ensure you have Node.js installed.
3636
- _Packages_: Install the following packages:
3737

@@ -47,13 +47,17 @@ First, import all required packages:
4747
import { Agent } from '@mastra/core/agent';
4848
import { MastraMCPClient } from '@mastra/mcp';
4949
import { openai } from '@ai-sdk/openai';
50+
// For Anthropic use
51+
// import { anthropic } from '@ai-sdk/anthropic';
5052
```
5153

5254
Next, set the environment variables for the Apify API token and OpenAI API key:
5355

5456
```typescript
5557
process.env.APIFY_TOKEN = "your-apify-token";
5658
process.env.OPENAI_API_KEY = "your-openai-api-key";
59+
// For Anthropic use
60+
// process.env.ANTHROPIC_API_KEY = "your-anthropic-api-key";
5761
```
5862

5963
Instantiate the Mastra MCP client:
@@ -96,6 +100,7 @@ Instantiate the agent with the OpenAI model:
96100
const agent = new Agent({
97101
name: 'Social Media Agent',
98102
instructions: 'You’re a social media data extractor. Find TikTok URLs and analyze profiles with precision.',
103+
// You can swap to any other AI-SDK LLM provider
99104
model: openai('gpt-4o-mini')
100105
});
101106
```
@@ -163,9 +168,13 @@ If you want to test the whole example, create a new file, `mastra-agent.ts`, and
163168
import { Agent } from '@mastra/core/agent';
164169
import { MastraMCPClient } from '@mastra/mcp';
165170
import { openai } from '@ai-sdk/openai';
171+
// For Anthropic use
172+
// import { anthropic } from '@ai-sdk/anthropic';
166173

167174
process.env.APIFY_TOKEN = "your-apify-token";
168175
process.env.OPENAI_API_KEY = "your-openai-api-key";
176+
// For Anthropic use
177+
// process.env.ANTHROPIC_API_KEY = "your-anthropic-api-key";
169178

170179
const mcpClient = new MastraMCPClient({
171180
name: 'apify-client',
@@ -196,6 +205,7 @@ const tools = await mcpClient.tools();
196205
const agent = new Agent({
197206
name: 'Social Media Agent',
198207
instructions: 'You’re a social media data extractor. Find TikTok URLs and analyze profiles with precision.',
208+
// You can swap to any other AI-SDK LLM provider
199209
model: openai('gpt-4o-mini')
200210
});
201211

0 commit comments

Comments
 (0)