Skip to main content
Loading navigation
Back to prompt library

Initial AI SDK Setup and Gemini Integration

Linked challenge: Ethical Ad Personalization Agent

Prompt source

implementation18 lines7 sectionsNo variables1 code block
Your first task is to initialize your AI SDK project and integrate Gemini 2.5 Pro for multimodal content generation. Set up a basic streaming chat endpoint. 

```typescript
import { createOpenAI } from '@ai-sdk/openai';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { streamText } from 'ai';

const google = createGoogleGenerativeAI({ apiKey: process.env.GOOGLE_API_KEY });
const model = google('gemini-2.5-pro');

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = await streamText({
    model: model,
    messages,
    // You'll need to add tools for ad generation here later
  });

  return result.to Response();
}
```

Expand this to include a simple tool for 'generateAdContent' that takes user preferences and a conversational context, and returns a multimodal ad draft (text, image URL).