Vercel AI SDK Integration
Integrate Superagent with Vercel AI SDK by configuring custom baseURL for providers
Superagent provides seamless integration with the Vercel AI SDK. Simply configure your provider with a custom baseURL to add AI firewall protection to your existing AI applications.
OpenAI Provider
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const openai = createOpenAI({
apiKey: 'your-openai-api-key',
baseURL: 'YOUR_SUPERAGENT_PROXY_URL', // Replace with your Superagent proxy
});
// Use with any AI SDK function
const { text } = await generateText({
model: openai('gpt-4'),
prompt: 'Hello world',
});
Anthropic Provider
import { createAnthropic } from '@ai-sdk/anthropic';
import { generateText } from 'ai';
const anthropic = createAnthropic({
apiKey: 'your-anthropic-api-key',
baseURL: 'YOUR_SUPERAGENT_PROXY_URL', // Replace with your Superagent proxy
});
// Use with any AI SDK function
const { text } = await generateText({
model: anthropic('claude-3-opus-20240229'),
prompt: 'Hello world',
});
xAI Provider
import { createXai } from '@ai-sdk/xai';
import { generateText } from 'ai';
const xai = createXai({
apiKey: 'your-xai-api-key',
baseURL: 'YOUR_SUPERAGENT_PROXY_URL', // Replace with your Superagent proxy
});
// Use with any AI SDK function
const { text } = await generateText({
model: xai('grok-3'),
prompt: 'Hello world',
});
Google Provider
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { generateText } from 'ai';
const google = createGoogleGenerativeAI({
apiKey: 'your-google-api-key',
baseURL: 'YOUR_SUPERAGENT_PROXY_URL', // Replace with your Superagent proxy
});
// Use with any AI SDK function
const { text } = await generateText({
model: google('gemini-1.5-pro'),
prompt: 'Hello world',
});
Usage with AI SDK Functions
All AI SDK functions work seamlessly with Superagent-protected providers:
import { generateText, streamText, generateObject } from 'ai';
// Generate text
const { text } = await generateText({
model: openai('gpt-4'),
prompt: 'Write a story about AI',
});
// Stream text
const { textStream } = await streamText({
model: anthropic('claude-3-opus-20240229'),
prompt: 'Explain quantum computing',
});
// Generate structured data
const { object } = await generateObject({
model: openai('gpt-4'),
schema: z.object({ name: z.string(), age: z.number() }),
prompt: 'Generate a person object',
});
Migration Notes
- No Function Changes: All AI SDK functions work unchanged
- Provider Configuration: Only the provider setup requires baseURL modification
- Same API Surface: All models and parameters remain identical
- Added Protection: Requests are now protected by Superagent's AI firewall
- Complete Compatibility: Full compatibility with all AI SDK features
Simply configure your providers with your Superagent proxy URL and you're protected!