Integrate Cerebras high-speed AI models (powered by Wafer-Scale Engines) into your application using Vercel's AI SDK. Generate text, stream responses, and leverage ultra-fast inference with models like Llama 3.3 70B.
Integrate Cerebras high-speed AI models into your application using Vercel's AI SDK. Cerebras offers ultra-fast inference powered by Wafer-Scale Engines and CS-3 systems.
This skill helps you install, configure, and use the Cerebras provider with Vercel's AI SDK to generate text, stream responses, and leverage high-performance language models like Llama 3.3 70B.
1. **Install the Cerebras provider package**
```bash
npm i @ai-sdk/cerebras
```
2. **Verify the AI SDK core package is installed**
If not already present, install it:
```bash
npm i ai
```
3. **Set up environment variables**
Ensure you have a Cerebras API key. Add it to your `.env.local` or environment configuration:
```
CEREBRAS_API_KEY=your_api_key_here
```
1. **Import the Cerebras provider and AI SDK functions**
```typescript
import { cerebras } from '@ai-sdk/cerebras';
import { generateText } from 'ai';
```
2. **Generate text using a Cerebras model**
```typescript
const { text } = await generateText({
model: cerebras('llama-3.3-70b'),
prompt: 'Write a JavaScript function that sorts a list:',
});
console.log(text);
```
Cerebras supports multiple high-performance models. Common options include:
For real-time streaming responses:
```typescript
import { cerebras } from '@ai-sdk/cerebras';
import { streamText } from 'ai';
const result = await streamText({
model: cerebras('llama-3.3-70b'),
prompt: 'Explain quantum computing in simple terms:',
});
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
```
When creating the provider instance with custom settings:
```typescript
import { createCerebras } from '@ai-sdk/cerebras';
const cerebras = createCerebras({
apiKey: process.env.CEREBRAS_API_KEY,
baseURL: 'https://api.cerebras.ai/v1', // optional
});
```
```typescript
const { text } = await generateText({
model: cerebras('llama-3.3-70b'),
prompt: 'Create a React component for a todo list with add and delete functionality',
});
```
```typescript
import { generateText } from 'ai';
import { cerebras } from '@ai-sdk/cerebras';
const { text } = await generateText({
model: cerebras('llama-3.3-70b'),
messages: [
{ role: 'system', content: 'You are a helpful coding assistant.' },
{ role: 'user', content: 'How do I optimize a React component?' },
],
});
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/ai-sdk-cerebras-provider/raw